Hallo. Importierte OpenStreetMap-Daten in mongodb (unter Verwendung von goosm) als Anwendung unterwegs Angesichts der "Breitengrad-Sequenzsequenzdaten" (blau unten), die sich entlang bewegten, dachte ich über das Problem der Identifizierung der Straße (grün) nach. Im Geojson-Format exportiert.
Die OpenStreetMap-Wegedaten (Autobahn) müssen jedoch eine einfache Kante (Linie) mit einem Scheitelpunkt an beiden Enden sein.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import simplejson
import textwrap
from pymongo import MongoClient
client = MongoClient('localhost')
def queryNear(coord, radius):
return ({"geometry": {"$near": {"$maxDistance": radius, "$geometry": {"type": "Point", "coordinates": coord}}}}, {"_id": 1, "geometry.coordinates": 1, "nodes": 1})
def printgeojson(type, coordinates):
fmtstr = """\
{
"type": "Feature",
"geometry": {"type": %s, "coordinates": %s},
"properties": {}
}"""
fmtstr = textwrap.dedent(fmtstr)
print(fmtstr % (type, coordinates), end='')
return 0
def printNodes(tracks):
nodes = []
colnodes = client['osm_nodes']['data']
prepend = ''
for coord in tracks:
results = colnodes.find(*queryNear(coord, radius))
for r in results:
if r['_id'] not in nodes:
nodes.append(r['_id'])
print(prepend, end='')
printgeojson("Point", r['geometry']['coordinates'])
prepend = ',\n'
return nodes
def printEdges(tracks, nodes):
edges = []
coledges = client['osm_edges']['data']
prepend = ''
for coord in tracks:
results = coledges.find(*queryNear(coord, radius))
for r in results:
if r['_id'] not in edges and set(r['nodes']).issubset(nodes):
edges.append(r['_id'])
print(prepend, end='')
printgeojson("LineString", r['geometry']['coordinates'])
prepend = ',\n'
return edges
def main():
radius = 30.0
tracks = [[lon0, lat0], [lon1, lat1], ...] # <==Geben Sie Breiten- und Längengradpunktsequenzdaten an
nodes = printNodes(tracks, radius)
edges = printEdges(tracks, radius, nodes)
exit(0)
if __name__ == '__main__':
main()
Recommended Posts