Skip to content

Commit 764607d

Browse files
committed
src - Initial support for GeoJSON (Ref: #13)
1 parent fa76991 commit 764607d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

overpy/format/geojson.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import json
2+
3+
import overpy
4+
5+
6+
def dump(result, fp, nodes=False, ways=False, json_args={}):
7+
"""
8+
9+
:param result:
10+
:type result: overpy.Result
11+
:param fp:
12+
:return:
13+
"""
14+
features = []
15+
if nodes:
16+
for node in result.nodes:
17+
properties = {}
18+
features.append({
19+
"type": "Feature",
20+
"geometry": {
21+
"type": "Point",
22+
"coordinates": [
23+
float(node.lon),
24+
float(node.lat)
25+
]
26+
},
27+
"properties": properties
28+
})
29+
30+
if ways:
31+
for way in result.ways:
32+
properties = {}
33+
coordinates = []
34+
for node in way.nodes:
35+
coordinates.append([
36+
float(node.lon),
37+
float(node.lat)
38+
])
39+
features.append({
40+
"type": "Feature",
41+
"geometry": {
42+
"type": "LineString",
43+
"coordinates": coordinates
44+
},
45+
"properties": properties
46+
})
47+
48+
geojson = {
49+
"type": "FeatureCollection",
50+
"features": features
51+
}
52+
53+
json.dump(geojson, fp, **json_args)

0 commit comments

Comments
 (0)