Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WKBWriter produces invalid WKB data #151

Closed
snorfalorpagus opened this issue Aug 20, 2014 · 2 comments
Closed

WKBWriter produces invalid WKB data #151

snorfalorpagus opened this issue Aug 20, 2014 · 2 comments

Comments

@snorfalorpagus
Copy link
Member

The wkb and wkb_hex methods are giving me the wrong output (see code sample below). I'm not sure if this is an issue with shapely, or the underlying GEOS library (which I compiled myself).

>>> from shapely.geometry import Point
>>> from shapely.wkb import loads
>>> p = Point(2.0, 4.0)
>>> p.wkt
'POINT (2 4)'
>>> p.wkb_hex
'010100000000000000000000000000000000000000'
>>> p2 = loads(p.wkb_hex, hex=True)
>>> p.x, p.y
(2.0, 4.0)
>>> p2.x, p2.y
(2.722673383505394e-306, 2.722673383505394e-306)

I'm running Python 2.7.6 (32 bit) on Windows 7 with GEOS 3.4.2 (compiled with MinGW32).

@mwtoews
Copy link
Member

mwtoews commented Aug 20, 2014

Yup, that's doing something weird. Did your build of GEOS pass the tests? (make check). Do you have multiple copies of GEOS libraries?

I left some of the older readers and writers in place, which raise a DeprecationWarning. Try p.to_wkb().encode('hex') (the others writer is p.to_wkt())

Furthermore, the old readers are:

from shapely.geometry import base
base.geom_from_wkt('POINT(2 4)').to_wkt()
base.geom_from_wkb('010100000000000000000000400000000000001040'.decode('hex')).to_wkt()

@snorfalorpagus
Copy link
Member Author

This does indeed seem to be a problem with my GEOS build. The tests fail, and it looks like the errors are related to similarly empty geometries. I'll follow this up on the GEOS mailing list, but I guess this issue can be closed.

The shapely test cases do seem to catch this as well:

======================================================================
FAIL: test_polygon (shapely.tests.test_polygon.PolygonTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "d:\Shapely\shapely\tests\test_polygon.py", line 64, in test_polygon
    self.assertEqual(ring.coords[0], (0., 0.))
AssertionError: Tuples differ: (7.994349224597053e-307, 7.994... != (0.0, 0.0)

First differing element 0:
7.9943492246e-307
0.0

- (7.994349224597053e-307, 7.994349224597053e-307)
+ (0.0, 0.0)

Serves me right for not running the tests when installing things...

jorisvandenbossche pushed a commit to jorisvandenbossche/shapely that referenced this issue Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants