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

Topology modifies source data #137

Closed
mattijn opened this issue Sep 9, 2021 · 0 comments · Fixed by #139
Closed

Topology modifies source data #137

mattijn opened this issue Sep 9, 2021 · 0 comments · Fixed by #139

Comments

@mattijn
Copy link
Owner

mattijn commented Sep 9, 2021

Somehow there still modification of source data. Observe the following:

import topojson as tp
from geojson import Feature, Polygon, FeatureCollection

# prepare data
feat_1 = Feature(
    geometry=Polygon([[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]),
    properties={"name":"abc"}
)
feat_2 = Feature(
    geometry=Polygon([[[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]]),
    properties={"name":"def"}
)
fc = FeatureCollection([feat_1, feat_2])

# before Topology()
print('before')
print(fc['features'][0]['geometry'])

# apply Topology()
gdf = tp.Topology(fc)

# after Topology()
print('after')
print(fc['features'][0]['geometry'])
before
{"coordinates": [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]], "type": "Polygon"}
after
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-8fbba6233a22> in <module>
     22 # after Topology()
     23 print('after')
---> 24 print(fc['features'][0]['geometry'])

KeyError: 'geometry'
@mattijn mattijn changed the title output functions modify source data Topology modifies source data Sep 9, 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

Successfully merging a pull request may close this issue.

1 participant