Giter Club home page Giter Club logo

Comments (1)

larsbutler avatar larsbutler commented on June 8, 2024 1

@frisia-mtz Thanks for the bug report. I appreciate you taking the time to point this out and provide an example.

I think this is more of a general problem of the way the geometry type (bytes 1-5: 010000A0) is represented in EWKB context. In EWKB, the 01 indicates a Point-type, and the A0 is the bitwise OR [1] of an SRID flag (0x20) and a WKB Z offset (0x80) [2] --> 0x20 | 0x80 = 0xa. geomet is checking for the presence of the SRID flag [3] but it's not expecting the dimensional offset.

It looks the reverse of the conversion (dumps/to WKB) is also not correctly setting the dimensionality flag [4].

It looks like the correct fix would be to:

  • look for the dimensionality flag when parsing EWKB
  • inject the dimensionality flag when generating EWKB

@tomplex @achapkowski Would you both agree with this assessment? Is there anything I'm missing, perhaps an alternate EWKB spec independent of PostGIS that would contradict this and cause additional breakage in other use cases, if we were to fix this per the PostGIS spec?

References:
[1] - https://github.com/postgis/postgis/blob/b1b8c11bfe54d7756ed53719e74783dd2733d3df/doc/ZMSgeoms.txt#L56-L66
[2] - https://github.com/postgis/postgis/blob/b1b8c11bfe54d7756ed53719e74783dd2733d3df/liblwgeom/liblwgeom.h.in#L124-L127
[2] -

has_srid = high_byte == b'\x20'

[3] -

geomet/geomet/wkb.py

Lines 336 to 373 in 8d2b8f2

def _header_bytefmt_byteorder(geom_type, num_dims, big_endian, meta=None):
"""
Utility function to get the WKB header (endian byte + type header), byte
format string, and byte order string.
"""
dim = _INT_TO_DIM_LABEL.get(num_dims)
if dim is None:
pass # TODO: raise
type_byte_str = _WKB[dim][geom_type]
srid = meta.get('srid')
if srid is not None:
# Add the srid flag
type_byte_str = SRID_FLAG + type_byte_str[1:]
if big_endian:
header = BIG_ENDIAN
byte_fmt = b'>'
byte_order = '>'
else:
header = LITTLE_ENDIAN
byte_fmt = b'<'
byte_order = '<'
# reverse the byte ordering for little endian
type_byte_str = type_byte_str[::-1]
header += type_byte_str
if srid is not None:
srid = int(srid)
if big_endian:
srid_header = struct.pack('>i', srid)
else:
srid_header = struct.pack('<i', srid)
header += srid_header
byte_fmt += b'd' * num_dims
return header, byte_fmt, byte_order

from geomet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.