如何从OpenStreetMap数据中找到街道交叉点列表?

时间:2013-02-05 20:39:34

标签: openstreetmap

我正在寻找一种从OpenStreetMap(OSM)数据中准确检索街道交叉点 的方法。我知道提出并回答了类似的问题,但我可以从建议的方法中检索的数据不是很准确。

首先,我知道以下问题:

上述问题的答案表明:

  

“查询给定边界框中的所有方式,并查找由两个或多个方式共享的节点,如另一个答案中所述。”

我遵循了这个建议并写了一个python脚本,它从我从OpenStreetMap下载的xml文件(osm文件)中提取节点元素。以下是代码:

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导出的数据运行此代码(例如,我使用从导出区域导出的数据:Min Lat:38.89239,Max Lat:38.89981,Min Lon:-77.03212,和Max Lon:-77.02119。),它打印出看起来像的坐标:

38.8966440,-77.0259810
38.8973430,-77.0280900
38.9010391,-77.0270309
38.8961050,-77.0319620
...

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

(我使用http://www.darrinward.com/lat-long/绘制数据。)显然,数据包含一些交叉点的节点(它们可能是面向两个街道的商店。)

我做错了什么或者这是我从OSM获得的最佳“交叉”数据?感谢您的帮助和评论。

最佳,

1 个答案:

答案 0 :(得分:5)

First Tipp:

不仅要与Google地图进行比较,还要将您的坐标主要与OpenStreetMap可视化进行比较。特别复杂的街道交叉口,虽然它们代表相同的道路,但可以进行不同的建模。

2):看看你是否真的使用了正确的方式:那条步道与街道混合在一起吗?有各种不同的类型,具有不同的属性:车辆可访问等。在Google MAps中,白色道路是车辆可以访问的道路

3)进一步看,如果你没有把房子多边形混入。

相关问题