Skip to content

Instantly share code, notes, and snippets.

@aatishnn
Created July 8, 2020 21:16
Show Gist options
  • Save aatishnn/2272232cde1d8a013b6be8d477d3932f to your computer and use it in GitHub Desktop.
Save aatishnn/2272232cde1d8a013b6be8d477d3932f to your computer and use it in GitHub Desktop.
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