WKBReadingError with PostGIS + Shapely with PostGIS Geography 列未知 WKB 类型 233

问题描述

我有一个带有 2 个字段的称为符号的表。注意一个geometry一个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)

当我运行以下代码时出现错误

    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,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,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.

以下是标志的两个属性中的值。请注意,它们不同的。

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'

我不知道为什么我收到错误。为什么两个字节值不同?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)