그래서 저는 Shapely 's LineMerge 나 Union 또는 PostGIS ST_Union을 사용하여 함께 묶어야하는 부서진 루트의 선 스트링을 가지고 있습니다.Shapely에서 PostGIS 지오메트리 형식을 파이썬으로 지오메트리 형식으로 가져 오시겠습니까?
제 아이디어는 바로 모양을 사용하여 Linestrings을 기하학 유형으로 가져 오는 것입니다. Shapely를 사용하여 병합하거나 병합 한 다음 데이터베이스의 결과 테이블로 다시 내 보냅니다.
그러나 PostGIS 데이터베이스의 지오메트리 유형은 단지 횡설수설에 지나지 않습니다. 처럼 ...
01020000020e61000....
어떻게, 매끈한를 사용하여 파이썬 지오메트리 유형으로 데이터베이스에서이 번역 일부 조작을 수행 한 후 다시 데이터베이스로 내보낼 수 있습니까?
현재이 코드는 데이터베이스에서 해당 geom 객체 문자열을 가져오고 기하학 유형이 아니기 때문에 오류가 발생합니다.
def create_shortest_route_geom(shortest_routes):
conn = connect_to_database()
cur = conn.cursor()
shortest_route_geoms = []
for route in shortest_routes:
source = str(int(route[1]))
target = str(int(route[2]))
query = 'SELECT the_geom FROM public.ways WHERE target_osm = ' + target + ' AND source_osm = ' + source + ' OR target_osm = ' + source + ' AND source_osm = ' + target + ';'
cur.execute(query)
total_geom = cur.fetchone()
for index, node in enumerate(route):
try:
source = str(int(node))
target = str(int(route[index + 1]))
query = 'SELECT the_geom FROM public.ways WHERE target_osm = ' + target + ' AND source_osm = ' + source + ' OR target_osm = ' + source + ' AND source_osm = ' + target + ';'
cur.execute(query)
geom = cur.fetchone()
query = "SELECT ST_Union("+str(geom[0])+","+str(total_geom[0])+")"
cur.execute(query)
total_geom = cur.fetchone()
except IndexError:
print "Last element"
shortest_route_geoms.insert(total_geom)
return shortest_route_geoms
EDIT : HEX 값으로 I may have found my answer here, looking more into it and will update my question with an answer if I figure this out.
문자열 대신 SQL 쿼리에 값을 연결하면 자리 표시자를 사용하십시오. 더 읽기 쉬운 코드를 작성하고, 수동으로 "인용 부호를 처리"할 필요가 없으며 일반적으로 주사의 위험을 줄입니다. –