deck.gl
deck.gl copied to clipboard
[Doc] pydeck.Layer modifies data. Documentation should make this clear!
Link
https://deckgl.readthedocs.io/en/latest/layer.html
Description
When using 'GeoJsonLayer'
and passing a python-geojson object to the data
attribute the geojson object gets modified. This sideeffect is not documented.
I spent a while trying to figure out why the geojson geometry suddenly appeared in the properties of a feature as well as in the feature itself. This was due to me using the geojson object after passing it to a Layer. So the layer seems to modify the object.
import geojson
from pydeck import Layer
gj_obj = geojson.FeatureCollection([geojson.Feature(geometry=geojson.Point((0, 0)))])
before = geojson.dumps(gj_obj)
print(before)
layer = Layer('GeoJsonLayer', gj_obj)
after = geojson.dumps(gj_obj)
print(after)
print(before == after)
{"features": [{
"geometry": {"coordinates": [0, 0], "type": "Point"},
"properties": {"geometry": {"coordinates": [0, 0], "type": "Point"}},
"type": "Feature"
}], "type": "FeatureCollection"}
I don't really know why adding the geometry to the properties is neccessary as it is present in the feature anyway, but if it is required it should at least be documented that this is happening.