Created
August 18, 2014 19:10
-
-
Save danvk/57c3164d3c65a4f7a4f6 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
'''Removes all non-polygon features from a GeoJSON file. | |
For now, these must be FeatureCollections of Features. | |
''' | |
import sys | |
import json | |
assert len(sys.argv) == 2 | |
d = json.load(file(sys.argv[1])) | |
assert d['type'] == 'FeatureCollection' | |
indices_to_delete = [] | |
for idx, feat in enumerate(d['features']): | |
assert feat['type'] == 'Feature' | |
if feat['geometry']['type'] not in ['Polygon', 'MultiPolygon']: | |
indices_to_delete.append(idx) | |
for idx in reversed(indices_to_delete): | |
del d['features'][idx] | |
print json.dumps(d, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment