I have a table called signs with 2 fields. Notice one is geometry
and one is geography
class Sign(AbstractMapObj, Base):
__tablename__ = "signs"
location = Column(Geometry('POINTZ', dimension=3), nullable=False)
geometry_lla = Column(Geography('POINTZ', dimension=3, srid=4326), nullable=True)
When I run the following code I get an error
sign_id = 1
sign = session.query(Sign).filter(Sign.id == sign_id).first()
sign.location = from_shape(Point(32, 12, 0), srid=4326)
sign.geometry_lla = from_shape(Point(32, 12, 0), srid=4326)
session.flush()
session.commit()
sign = session.query(Sign).filter(Sign.id == sign_id).first()
# THIS LINE WORKS
shape = to_shape(sign.location)
# THESE TWO LINES WORKS
a = from_shape(Point(32, 12, 0), srid=4326)
b = wkb.loads(bytes(a.data))
# THIS FAILS
shape = wkb.loads(bytes(sign.geometry_lla.data))
2021-03-01 17:33:39 shapely.geos ERROR - ParseException: Unknown WKB type 233
Traceback (most recent call last):
File "/mnt/ssd/mepy_algo/.venv/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2882, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-d2f7a1c9e125>", line 1, in <module>
wkb.loads(bytes(sign.geometry_lla.data))
File "/mnt/ssd/mepy_algo/.venv/lib/python2.7/site-packages/shapely/wkb.py", line 16, in loads
return reader.read(data)
File "/mnt/ssd/mepy_algo/.venv/lib/python2.7/site-packages/shapely/geos.py", line 395, in read
"Could not create geometry because of errors "
WKBReadingError: Could not create geometry because of errors while reading input.
Below are the values in the two properties of the sign. Notice that they are different.
bytes(sign.geometry_lla.data)
Out[6]: '\x01\xe9\x03\x00\x00\x00\x00\x00\x00\x00\x00@@\x00\x00\x00\x00\x00\x00(@\x00\x00\x00\x00\x00\x00\x00\x00'
bytes(a.data)
Out[8]: '\x01\x01\x00\x00\x80\x00\x00\x00\x00\x00\x00@@\x00\x00\x00\x00\x00\x00(@\x00\x00\x00\x00\x00\x00\x00\x00'
I cant figure out why I am getting the error. Why are the two byte values different?
from WKBReadingError with PostGIS + Shapely with PostGIS Geography column (Unknown WKB type 233)
No comments:
Post a Comment