Created
April 5, 2017 09:56
-
-
Save Scarysize/0e3c5124a6b543ce6b2bcdaf3c0dea19 to your computer and use it in GitHub Desktop.
Handle (Geo-)JSON with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
with open('path/to/json/file') as data_file: | |
# a python dictionary, similar to a JS object | |
data = json.load(data_file) | |
# iterate over features, 'features' is a python list | |
for feature in data['features']: | |
# access everything via brackets, no dot notation | |
properties = feature['properties'] | |
#... | |
# construct a new geoJson | |
geoJson = { | |
'type': 'FeatureCollection', | |
'features': [] | |
} | |
# write geojson to file | |
with open('target/file', 'w') as outfile: | |
json.dump(geoJson, outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment