1

我有一个名为符号的表,有 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, 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.

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

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'

我无法弄清楚为什么我会收到错误消息。为什么两个字节值不同?

4

0 回答 0