【问题标题】:Retrieve data from a Polygon using osmnx使用 osmnx 从多边形中检索数据
【发布时间】:2020-05-06 10:20:59
【问题描述】:

在问这个问题之前,我要展示一下我做了什么:

我正在使用 Pyhton 以及即将展示的软件包。

我想使用 osmnx 访问与葡萄牙大陆(西班牙旁边的部分,因此不包括岛屿)对应的数据:

import geopandas as gpd
import pandas as pd
from shapely.geometry import Point, LineString, Polygon
import networkx as nx
import osmnx as ox
import matplotlib.pyplot as plt
from descartes import PolygonPatch
from IPython.display import IFrame
ox.config(log_console=True, use_cache=True)

选择了地点。我得到了葡萄牙对应的MultiPolygon

place = 'Portugal'
G = ox.gdf_from_place(place)
fig, ax = ox.plot_shape(G, figsize=(17,17))

我只想要葡萄牙大陆,我的意思是这只是西班牙旁边的部分,不包括亚速尔群岛和马德拉岛等岛屿。因此,我探索了 MultipPolygon 的几何形状。然后将所有多边形按面积排序,选出面积最大的那个。

exploded_G = G.explode()
exploded_G['area'] = exploded_G.area
exploded_G.sort_values(by='area', inplace=True)
Portugal= exploded_G.iloc[-1]['geometry']

我的问题是:如何访问我现在拥有的多边形(我称之为葡萄牙的多边形)的所有信息,例如兴趣点、道路、节点等。

提前谢谢你。

【问题讨论】:

    标签: python python-3.x polygon osmnx


    【解决方案1】:

    由于葡萄牙大陆涉及大量数据,因此非常耗时,我只是在其中一个较小的多边形上实施了以下步骤。因此,以下内容也应该适用于“葡萄牙”。

    exploded_gdf_place = gdf_place.explode()
    exploded_gdf_place['area'] = exploded_gdf_place.area
    exploded_gdf_place.sort_values(by='area', inplace=True)
    smaller_area_Portugal= exploded_gdf_place.iloc[4]['geometry']
    

    您可以使用 OSMNx 的graph_from polygon 函数来获取道路网络(例如,驾驶或步行网络)。

    g = ox.graph_from_polygon(polygon = smaller_area_Portugal, network_type = 'drive')
    fig, ax = ox.plot_graph(g, fig_height=5)
    

    然后,您可以获取关于与地理数据框相同的图形的节点和边的数据,如下所示。

    gdf_nodes,gdf_edges = ox.graph_to_gdfs(g, nodes=True, edges=True)
    

    要获取有关多边形内 POI 的数据,您应该使用以下方法。我没有指定任何特定的便利设施类型,但也可以这样做。请参阅文档。

    gdf_pois = ox.pois.osm_poi_download(polygon=smaller_area_Portugal)
    

    在多边形内获得的 POI 的一个示例将按如下方式检索。

    sample_poi = gdf_pois['elements'][0]
    

    【讨论】:

    • 非常感谢,这正是我想要的!
    猜你喜欢
    • 1970-01-01
    • 2011-07-03
    • 2020-04-04
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多