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

TODO: M gets dropped from pickle serialization of LinearRing types #2005

Open
mwtoews opened this issue Mar 5, 2024 · 1 comment
Open

TODO: M gets dropped from pickle serialization of LinearRing types #2005

mwtoews opened this issue Mar 5, 2024 · 1 comment
Milestone

Comments

@mwtoews
Copy link
Member

mwtoews commented Mar 5, 2024

On shapely main with #1808 to enable M and ZM in WKB outputs, one "TODO" item needs to be resolved for test_pickle_m. To demonstrate the issue:

import pickle
import shapely

assert shapely.geos_version[0:2] >= (3, 12), shapely.geos_version_string

geom = shapely.from_wkt("LINEARRING M (0 0 1, 1 0 2, 1 1 3, 0 1 2, 0 0 1)")
pickled = pickle.dumps(geom)
actual = pickle.loads(pickled)

print(f"{geom!r} != {actual!r}")
# <LINEARRING M (0 0 1, 1 0 2, 1 1 3, 0 1 2, 0 0 1)> != <LINEARRING (0 0, 1 0, 1 1, 0 1, 0 0)>

I recall there is special handling for LinearRing types in shapely's src/* C code, as there is no WKB equivalent for LinearRing. It will need to be updated to handle M and ZM coordinate types.

@jorisvandenbossche
Copy link
Member

The special handling is currently not in the C code but here:

def _unpickle_linearring(wkb):
linestring = shapely.from_wkb(wkb)
srid = shapely.get_srid(linestring)
linearring = shapely.linearrings(shapely.get_coordinates(linestring))
if srid:
linearring = shapely.set_srid(linearring, srid)
return linearring

def __reduce__(self):
"""WKB doesn't differentiate between LineString and LinearRing so we
need to move the coordinate sequence into the correct geometry type"""
return (_unpickle_linearring, (shapely.to_wkb(self, include_srid=True),))

We should probably add a helper function in C that converts a LineString to a LinearRing by just getting the CoordSequence from the line and put that in a LinearRing, so that it preserves the full coord seq and its dimensionality.

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

2 participants