我正在寻找一种方法来从OpenStreetMap(OSM)数据中准确检索准确的街道交叉路口。我意识到类似的问题被问及并得到解答,但我可以从建议的方法中检索到的数据不是很准确。如何从OpenStreetMap数据中找到街道交叉路口的列表?
首先,我知道以下问题:
上述问题的答案建议:
“查询所有方法在给定的边界框中查找由两种或多种方式共享的节点作为exp排在另一个答案。“
我遵循了这一建议,并写道,提取从我从OpenStreetMap下载一个XML文件(OSM文件)节点元素python脚本。以下是代码:
try:
from xml.etree import cElementTree as ET
except ImportError, e:
from xml.etree import ElementTree as ET
def extract_intersections(osm, verbose=True):
# This function takes an osm file as an input. It then goes through each xml
# element and searches for nodes that are shared by two or more ways.
# Parameter:
# - osm: An xml file that contains OpenStreetMap's map information
# - verbose: If true, print some outputs to terminal.
#
# Ex) extract_intersections('WashingtonDC.osm')
#
tree = ET.parse(osm)
root = tree.getroot()
counter = {}
for child in root:
if child.tag == 'way':
for item in child:
if item.tag == 'nd':
nd_ref = item.attrib['ref']
if not nd_ref in counter:
counter[nd_ref] = 0
counter[nd_ref] += 1
# Find nodes that are shared with more than one way, which
# might correspond to intersections
intersections = filter(lambda x: counter[x] > 1, counter)
# Extract intersection coordinates
# You can plot the result using this url.
# http://www.darrinward.com/lat-long/
intersection_coordinates = []
for child in root:
if child.tag == 'node' and child.attrib['id'] in intersections:
coordinate = child.attrib['lat'] + ',' + child.attrib['lon']
if verbose:
print coordinate
intersection_coordinates.append(coordinate)
return intersection_coordinates
如果我运行此代码,我从OSM导出的数据(如,我用从出口地区出口数据:最小纬度:38.89239,最大纬度:38.89981,闵咯嗯:-77.03212,和最大经度:-77.02119),它打印出看起来像坐标:
38.8966440,-77.0259810
38.8973430,-77.0280900
38.9010391,-77.0270309
38.8961050,-77.0319620
...
如果我绘制谷歌地图这些坐标,它看起来像:
(我用http://www.darrinward.com/lat-long/绘制数据。)显然,数据包含一些节点是不交叉口(他们很可能正面临对两种steets店)
难道我做错了什么,或者这是最好的“交集”数据我可以从OSM获得?我感谢您的帮助和评论。
最佳,
我试图做类似你的东西。目前,我提取“方式”的类型高速公路的高速公路标签的所有节点(以后我会包括其他类型的高速公路---小学,中学等)。 (与键为标识和值的方式为节点列表中选择一个Python字典) 使用您发布时我正在面临着同样的问题,因为你。你能告诉我怎样才能得到所有类型的交叉节点----高速公路---只有高速公路?? 任何帮助将不胜感激:) –
这里是计算器另一个相似的问题:http://stackoverflow.com/questions/12965090/get-list-of-all-intersections-in-a-city/18385182 – tyr