Created
July 8, 2020 21:16
-
-
Save aatishnn/2272232cde1d8a013b6be8d477d3932f 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
import csv | |
import sys | |
import json | |
from collections import defaultdict | |
IN_FILENAME = sys.argv[1] | |
in_csv_file = csv.DictReader(open(IN_FILENAME, 'r')) | |
featuresByGroup = defaultdict(list) | |
geojson = { | |
"type": "FeatureCollection", | |
"features": [] | |
} | |
for row in in_csv_file: | |
geojson['features'].append( | |
{ | |
"type": "Feature", | |
"properties": { | |
"name": row['name'], | |
"deviceId": row['deviceId'], | |
"group": row['group'] | |
}, | |
"geometry": { | |
"type": "Point", | |
"coordinates": [ | |
float(row["longitude"]), | |
float(row["latitude"]) | |
] | |
} | |
} | |
) | |
with open("devices.json", 'w') as f: | |
f.write(json.dumps(geojson)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment