2013-02-05 233 views
7

我正在寻找一种方法来从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 
... 

如果我绘制谷歌地图这些坐标,它看起来像: enter image description here

(我用http://www.darrinward.com/lat-long/绘制数据。)显然,数据包含一些节点是交叉口(他们很可能正面临对两种steets店)

难道我做错了什么,或者这是最好的“交集”数据我可以从OSM获得?我感谢您的帮助和评论。

最佳,

+0

我试图做类似你的东西。目前,我提取“方式”的类型高速公路的高速公路标签的所有节点(以后我会包括其他类型的高速公路---小学,中学等)。 (与键为标识和值的方式为节点列表中选择一个Python字典) 使用您发布时我正在面临着同样的问题,因为你。你能告诉我怎样才能得到所有类型的交叉节点----高速公路---只有高速公路?? 任何帮助将不胜感激:) –

+0

这里是计算器另一个相似的问题:http://stackoverflow.com/questions/12965090/get-list-of-all-intersections-in-a-city/18385182 – tyr

回答

4

首先蒂普:

不仅与谷歌地图相比较,比较的坐标主要与OpenStreetMap的可视化。尤其复杂的街道交叉路口尽管它们代表相同的道路,但可以进行不同的建模。

2):你看,如果你真的使用权类型的方式:是步行小径,与街道混合?有各种不同的类型,具有不同的属性:可用于车辆等。在Google MAPS中,白色道路是可由车辆访问的道路。

3)进一步看,如果你没有得到房子多边形混合。

+0

AlexWien喜, 非常感谢! (1)是的,我会记住这一点。 (2)和(3)你是对的,我有不同类型的混合方式。我提取了街道,现在它已经修复:) 再次感谢:) – Kotaro

+1

@Kotaro:你是怎么最终解决这个问题的?什么是提取街道的方式? – statBeginner

+1

@statBeginner:在上面代码中提取''元素,我最终过滤掉了不必要的高速公路元素(例如'footway')。更具体地说,我使用'高速公路','后备箱','主要','次要','tertialy'和'住宅'。请参阅http://wiki.openstreetmap.org/wiki/Key:highway – Kotaro