2013-02-05 237 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