-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeojson.py
38 lines (30 loc) · 892 Bytes
/
geojson.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json, geojson, sys
print "Converting Json to Geojson.. "
in_file = sys.argv[1]
gjson = {
"type": "FeatureCollection",
"features": []
}
with open(in_file) as json_file:
data = json.load(json_file)
for p in data['MSDBS_Report (21)']:
f = gjson["features"]
if (p.has_key("Latitude") and p.has_key("Longitude")):
lat = p['Latitude'].encode('ascii', 'ignore')
lat = float(lat)
lon = p['Longitude'].encode('ascii', 'ignore')
lon = float(lon)
properties = []
#print lat
#print lon
#print properties
point = geojson.Point((lat, lon))
feature = {"type": "Feature","geometry": {"type": "Point","coordinates": [lat, lon]},"properties": p}
#print feature
f.append(feature)
output = open('geo.json', 'w')
#json.dump(geojson, output)
geojson_string = geojson.dumps(gjson)
output.write(geojson_string)
output.close()
print geojson_string