I see libraries such as shape
from shapely.geometry
that support conversion to WKB and WKT binaries. What I am unable to find is guidance on converting to EWKB specifically.
I suspect this is because libraries that support WKB conversion also support EWKB? How do I know if I am creating an EWKB vs WKB? Are all WKB also EWKB (but not the other way around)?
If EWKB is an extension of WKB, how would I check that, say, Shapely, supports EWKB format?
I am trying to understand if EWKB is standard or something that was just built for PostGIS (where I have seen it used) and how I can make sure that data I am producing for a function that expects EWKB can be correctly formatted.
Because of @shongololo's comment, I wanted to add a snippet of what I am going presently to generate the WKB of the shape from GeoJSON.
from shapely.geometry import shape
import binascii
# convert geom to wkb format
geom_str = json.dumps(route['geometry'])
geom_geo = geojson.loads(geom_str)
geom_shp = shape(geom_geo)
geom_wkb = geom_shp.to_wkb()
geom_cln = binascii.hexlify(geom_wkb).decode('ascii')
Best Answer
Shapely is based on GEOS, which natively reads/writes EWKB. The Z-dimension support of EWKB (different from ISO) is well supported by GEOS/Shapely, but getting/setting SRIDs is a hidden feature. Here's a quick demo:
Note that if SRID is not used and the geometries are simple 2D, then ISO WKB and EWKB are the same.