forked from Rub21/vizualization-imagen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverts-nodes.py
executable file
·36 lines (29 loc) · 989 Bytes
/
converts-nodes.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
from xml.etree.ElementTree import ElementTree
from datetime import datetime
import time
from sys import argv
import json
tree = ElementTree()
if (len(argv) < 3):
print "specify an input & output filename, and year. input is osm, output is geojson"
exit()
tree.parse(argv[1])
geojson = { "type": "FeatureCollection", "features": [] }
nodeidx = {}
print 'mapping nodes'
for n in tree.iterfind('node'):
if (n.attrib.has_key('user')):
pt = {
"type": "Feature",
"geometry": {
"type": 'Point',
"coordinates": [float(n.attrib['lon']), float(n.attrib['lat'])]
},
"properties": {
"user": n.attrib['user'],
"version": n.attrib['version'],
"timestamp": time.mktime(datetime.strptime(n.attrib['timestamp'], '%Y-%m-%dT%H:%M:%SZ').utctimetuple())
}
}
geojson['features'].append(pt)
json.dump(geojson, open(argv[2], 'w'))