簡體   English   中英

從 OSMNX Geoseries 獲取坐標列表(緯度、經度)

[英]Getting list of coordinates (lat,long) from OSMNX Geoseries

我想計算目的地列表和起點之間的最短路徑。 但首先我需要找到離我的目的地最近的節點。 我從 OSMNX function 獲取一組興趣點 (geometries_from_place) 的目的地列表。

import osmnx as ox
import geopandas as gpd
import networkx as nx
print(ox.__version__)
ox.config(use_cache=True, log_console=True)
Kinshasa = [ "Kisenso, Mont Amba, 31, Democratic Republic of the Congo",
"N'djili, Tshangu, Democratic Republic of the Congo",
"Kinshasa, Democratic Republic of the Congo"]
G_Kinshasa = ox.graph.graph_from_place(Kinshasa, simplify=True, network_type='drive')
tags2 = {'amenity' : ['hospital','university','social_facility'],
        'landuse' : ['retail', 'commercial'],
         'shop' : ['water','bakery']}
POIS = ox.geometries_from_place(Kinshasa, tags2, which_result=1)
Nearest_Nodes = ox.get_nearest_nodes(G_Kinshasa, POIS['geometry'][x],POIS[geometry][y])

如何從 POIS['geometry'] object 中獲取經緯度圖的列表,這是一個 GeoSeries 以將其傳遞給上面最后一行代碼中的 get_nearest_nodes? 這是 POIS['geometry'] 的 output 的示例:

Out[10]: 
0                             POINT (15.34802 -4.39344)
1                             POINT (15.34074 -4.41001)
2                             POINT (15.34012 -4.40466)
3                             POINT (15.34169 -4.40443)
4                             POINT (15.35278 -4.40812)

這是一個最小的可重現解決方案(OSM 無法以當前形式對您的地點查詢進行地理編碼,因此我選擇了一個僅用於演示目的的解決方案)。 請注意,我指定了balltree方法來查找最近的節點,因為您正在使用未投影圖和未投影點。

import osmnx as ox
ox.config(use_cache=True, log_console=True)

place = 'Berkeley, CA, USA'
G = ox.graph_from_place(place, network_type='drive')

tags = {'amenity' : ['hospital','university','social_facility'],
        'landuse' : ['retail', 'commercial'],
        'shop' : ['water','bakery']}
gdf = ox.geometries_from_place(place, tags)

centroids = gdf.centroid
X = centroids.x
Y = centroids.y

nn = ox.get_nearest_nodes(G, X, Y, method='balltree')

您可以使用簡單的 lambda function 創建列表操作元組。 我沒有針對其他可能的解決方案測試性能,而是針對 5000 行 x 9 列進行測試。 geodataframe 在中型台式 PC 上大約需要 120 毫秒。

pointlist = list(POIS.geometry.apply(lambda x: ( x.x, x.y )))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM