Created
December 1, 2011 21:42
-
-
Save schuyler/1420102 to your computer and use it in GitHub Desktop.
Converting Ushahidi JSON to GeoJSON
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
# convert Ushahidi JSON on stdin to GeoJSON on stdout | |
import json, sys | |
data = json.load(sys.stdin) | |
features = [] | |
for item in data["payload"]["incidents"]: | |
incident = item["incident"] | |
feature = { | |
"type": "Feature", | |
"id": int(incident["incidentid"]), | |
"properties": incident, | |
"geometry": { | |
"type": "Point", | |
"coordinates": [ | |
float(incident["locationlongitude"]), | |
float(incident["locationlatitude"]) | |
] | |
} | |
} | |
features.append(feature) | |
collection = { | |
"type": "FeatureCollection", | |
"features": features | |
} | |
json.dump(collection, sys.stdout, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Convert the output of this script to CSV using:
ogr2ogr -f CSV file.csv file.geojson