Use OGR Geometry Hex data In Python

344 Views Asked by At

I have a csv file with ogr_geometry column. The data is encoded in hex values. I'm try to extract the Geometry object from the encoded values. But failed to do so. Below is a sample dataset.

ogr_fid     ogr_geometry    
    1   0xE61000000114300F99F221E36240CDF22B8CE3F440C0...   
    2   0xE6100000010407000000F866406220E36240EBA6391E...   
    3   0xE6100000010405000000F8A8BF5E21E362409341A495...   

I tried to create the Geometry from WKB as in this link: http://pcjericks.github.io/py-gdalogr-cookbook/geometry.html Also tried this: https://gis.stackexchange.com/questions/89323/postgis-parse-geometry-wkb-with-ogr

from __future__ import print_function
from shapely import wkb

gdf = gp.read_file('osm_overspeed_data.csv')
hex_string = gdf['ogr_geometry'][0][2:] 
# hex_string E61000000114300F99F221E36240CDF22B8CE3F440C0259EA2D92BE362401D6B9093D3F440C0
shp = wkb.loads(hex_string, hex=True)
print(shp)

this gives the following error.

/usr/local/lib/python3.7/dist-packages/shapely/geos.py in read_hex(self, data)
    443         if not geom:
    444             raise WKBReadingError(
--> 445                 "Could not create geometry because of errors "
    446                 "while reading input.")
    447         # avoid circular import dependency

WKBReadingError: Could not create geometry because of errors while reading input.
0

There are 0 best solutions below