【问题标题】:Combining OSMnx Multipolygons结合 OSMnx 多面体
【发布时间】:2019-02-19 11:44:27
【问题描述】:

使用OSMnx's gdf_from_places() 生成作为一个组获取的多面体联合的最佳做法是什么?

gboeing02-example-osm-to-shapefile.ipynb 示例中,使用 gdf_from_places() 方法将多个 shapefile 从 OSM 下载到地理数据框。几何图形存储为 Geopanda 数据框中的多面体,每一行代表一个地点。

# you can pass multiple queries with mixed types (dicts and strings)
mx_gt_tx = ox.gdf_from_places(queries=[{'country':'Mexico'}, 'Guatemala', {'state':'Texas'}])
mx_gt_tx = ox.project_gdf(mx_gt_tx)
fig, ax = ox.plot_shape(mx_gt_tx)

关于这个问题,我尝试过使用 Geopanda 的 GeoSeries.unary_union,但想知道其他人是如何在 Python 中以编程方式完成此任务的。

2018 年当前流程

此方法使用Shapely function of unary_union(如@joris 评论所指出的那样,否则它将是 mx_gt_tx["geometry"].unary_union 通过 Geopandas。

queries = [{'country':'Mexico'}, 'Guatemala', {'state':'Texas'}]

# buffer_dist is in meters
mx_gt_tx = ox.gdf_from_places(queries, gdf_name='region_mx_gt_tx')
mx_gt_tx

# project the geometry to the appropriate UTM zone then plot it
mx_gt_tx = ox.project_gdf(mx_gt_tx)
fig, ax = ox.plot_shape(mx_gt_tx)

# unary union through Geopandas
region_mx_gt_tx = gpd.GeoSeries(unary_union(mx_gt_tx["geometry"]))
region_mx_gt_tx.plot(color = 'blue')
plt.show()
print(region_mx_gt_tx )

【问题讨论】:

  • 看起来生成的 osmnx gdf ​​不将形状存储为多多边形,而是多边形。
  • 您的问题到底是什么?你从unary_union 得到的结果不是你想要的吗?
  • @joris 结果就是我正在寻找的结果,尽管我不知道这是否是获得该结果的“最佳实践”方式。我问这个问题是为了寻找关于创建联合的方法的其他观点。
  • 我认为这肯定被视为最佳实践(我不知道有什么更好的方法)。请注意,您没有使用 GeoSeries.unary_union 方法,而是使用 shapely 函数(否则它将是 mx_gt_tx["geometry"].unary_union 而不是 unary_union(mx_gt_tx["geometry"])),但两者都很好(并且一个在引擎盖下使用另一个)跨度>
  • @joris 感谢您的澄清和指出!绝对是尝试各种方法以获得有效解决方案后留下的工件。

标签: python gis geopandas osmnx


【解决方案1】:
import osmnx as ox
gdf = ox.gdf_from_places(queries=[{'country':'Mexico'}, 'Guatemala', {'state':'Texas'}])
unified = gdf.unary_union

【讨论】:

    猜你喜欢
    • 2020-10-05
    • 2015-07-30
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多