I am trying to convert a file to Geojson in python and I have below code. I have tried adding row indexes to the code, but the error is still the same.
import csv
import json
from collections import OrderedDict
li = []
with open('sample.csv', 'r') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for lat,long in reader:
d = OrderedDict()
d['type'] = 'Feature'
d['geometry'] = {
'type': 'Point',
'coordinates': [float(lat), float(long)]
}
li.append(d)
d = OrderedDict()
d['type'] = 'FeatureCollection'
d['features'] = li
I am getting below error,
"too many values to unpack (expected 2)"
sample data
event_id time_0 time_1 signal description signal_name_value_desc product long lat
a 6/30/2018 18:39 6/30/2018 18:39 1 description1 signal_name1 product-1 -84.52694 46.931625
a 6/30/2018 18:39 6/30/2018 18:39 1 description1 signal_name1 Product - 1 -84.52684 46.931725
a 10/15/2018 21:10 10/15/2018 21:11 1 description1 signal_name1 Product - 2 -94.25526333 42.71689167
a 10/15/2018 21:10 10/15/2018 21:11 1 description1 signal_name1 Product - 2 -94.25524667 42.71689333
a 10/15/2018 21:10 10/15/2018 21:11 1 description1 signal_name1 Product - 2 -94.25519167 42.716895
b 10/15/2018 21:10 10/15/2018 21:11 1 description1 signal_name1 Product - 2 -94.25505167 42.71690833
b 10/15/2018 21:12 10/15/2018 21:13 1 description1 signal_name1 Product - 2 -94.25531167 42.71687167
b 10/15/2018 21:12 10/15/2018 21:13 1 description1 signal_name1
This is the output I am expecting
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ -84.52694,46.931625 ]
},
"properties": {
"event_id":"a",
"time_0":"6/30/2018 18:39",
"time_1":"6/30/2018 18:39",
"signal":"1",
"description":"description1",
"signal_name_value_desc":"signal_name1",
"product":"product-1",
}
}
How can I convert csv to GeoJson. Thanks in advance