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


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?


2 Answers 2


The easiest way is to use wkb.dumps, e.g.:

from shapely import wkb, wkt

# 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

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:


Hope that helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.