Geographic Information Systems Asked by Nick Ginanto on January 26, 2021
I want to encode coordinates of LineString in WKB with the SRID included
wkbwriter = shapely.geos.WKBWriter(shapely.geos.lgeos, big_endian=False, include_srid=True)
geo = wkbwriter.write_hex(LineString(geometry_obj['coordinates']))
but it is the same exact as
shapely.geometry.shape(geometry_obj).wkb_hex
and does not include the SRID in the encoding, causing issues when trying to store it in postgis with column Geometry(‘LineString’, 3857)
what am I doing wrong?
I had the same issue. This is not a big problem. Instead of having the SRID code inside you can use this syntax when exporting in postgis:
"ST_GeomFromText('{}',{})".format(geometry,srid)
Hope that helps
Answered by Guillaume on January 26, 2021
The easiest way is to use wkb.dumps
, e.g.:
from shapely import wkb, wkb
# example geometry
g = wkt.loads('LINESTRING(2 3, 4 5)')
# without SRID
wkb.dumps(g, hex=True)
# 0102000000020000000000000000000040000000000000084000000000000010400000000000001440
# with SRID=3857
wkb.dumps(g, hex=True, srid=3857)
# 0102000020110F0000020000000000000000000040000000000000084000000000000010400000000000001440
Answered by Mike T on January 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP