Last active
December 11, 2015 17:33
-
-
Save plablo09/b3ed77516481826e03ed to your computer and use it in GitHub Desktop.
quick csv 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
import csv | |
import json | |
csv_data = csv.reader(open('MonthMap.csv', 'rb'), delimiter='\t') | |
features = [] | |
for i, row in enumerate(csv_data): | |
try: | |
f = { | |
"type" : "Feature", | |
"id" : row[0], | |
"properties" : { "date" : row[3], "value" : row[4]}, | |
"geometry" : { | |
"type" : "Point", | |
"coordinates" : [float(row[2]),float(row[1])] | |
} | |
} | |
features.append(f) | |
except: | |
pass | |
feature_collection = { | |
"type" : "FeatureCollection", | |
"features": features | |
} | |
with open('output.geojson', 'w') as outfile: | |
json.dump(feature_collection, outfile,indent=4, sort_keys=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment