geojson icon indicating copy to clipboard operation
geojson copied to clipboard

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

Open mike-sosa-sofarocean opened this issue 6 years ago • 3 comments

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.

mike-sosa-sofarocean avatar Oct 02 '19 22:10 mike-sosa-sofarocean

Can confirm. map_ functions should preserve properties.

arsdragonfly avatar Dec 25 '20 08:12 arsdragonfly

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.

hhoeflin avatar May 31 '21 12:05 hhoeflin