jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
897 stars 120 forks source link

Map_Coords/(Other Map_* operations) loses data and affects original referenced object #136

Open mike-sosa-sofarocean opened 4 years ago

mike-sosa-sofarocean commented 4 years ago

To reproduce the issue take a FeatureCollection that has the example feature [{"geometry": {"coordinates": [-142.505993, 27.779555], "properties": {"dogs": 5, "cats": 6, "frogs": 7}, "type": "Point"}, "properties": {}, "type": "Feature"}]

Then if we run map_coords to divide each coordinate in half

# gj is our FeatureCollection object
gj_prime = geojson.utils.map_coords(lambda x: x / 2, gj)

Then gj_prime will have {"geometry": {"coordinates": [-71.2529965, 13.8897775], "type": "Point"}, "properties": {}, "type": "Feature"}

which correctly applies the coordinate transformation but does not carry over the properties dictionary. Additionally if we look back at the original FeatureCollection gj, it will have also have the transformation applied to its coordinates, and properties dictionary lost.

This does not seem like the intended behavior (or at least should have a 'copy'/'in_place' kwarg) and additionally information during the operation should be preserved.

arsdragonfly commented 3 years ago

Can confirm. map_ functions should preserve properties.

hhoeflin commented 3 years ago

To add to this ... the returned object is not actually a "FeatureCollection" or "Feature" object, but instead the dictionary encoded version. In practice this can be seen e.g. during comparison, where one encodes coordinate-tuples to tuples, and not to lists - as in the example above.

ferreteleco commented 1 year ago

Is there any update on this?