Skip to content

Commit

Permalink
src - Initial support for GeoJSON (Ref: #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
phibos committed Apr 22, 2021
1 parent fa76991 commit 764607d
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions overpy/format/geojson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import json

import overpy


def dump(result, fp, nodes=False, ways=False, json_args={}):
"""
:param result:
:type result: overpy.Result
:param fp:
:return:
"""
features = []
if nodes:
for node in result.nodes:
properties = {}
features.append({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
float(node.lon),
float(node.lat)
]
},
"properties": properties
})

if ways:
for way in result.ways:
properties = {}
coordinates = []
for node in way.nodes:
coordinates.append([
float(node.lon),
float(node.lat)
])
features.append({
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": coordinates
},
"properties": properties
})

geojson = {
"type": "FeatureCollection",
"features": features
}

json.dump(geojson, fp, **json_args)

0 comments on commit 764607d

Please sign in to comment.