Skip to content

Instantly share code, notes, and snippets.

@schuyler
Created December 1, 2011 21:42
Show Gist options
  • Save schuyler/1420102 to your computer and use it in GitHub Desktop.
Save schuyler/1420102 to your computer and use it in GitHub Desktop.
Converting Ushahidi JSON to GeoJSON
# 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)
@schuyler
Copy link
Author

schuyler commented Dec 1, 2011

Convert the output of this script to CSV using:

ogr2ogr -f CSV file.csv file.geojson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment