组合 OSMnx 多面体

Combining OSMnx Multipolygons

生成使用 OSMnx's gdf_from_places() 作为一个组获取的多边形并集的最佳实践是什么?

gboeing's 02-example-osm-to-shapefile.ipynb 示例中,使用 gdf_from_places() 方法将多个形状文件从 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(否则将是 mx_gt_tx["geometry"]。unary_union 通过 Geopandas,正如@joris 评论所指出的。

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 )

import osmnx as ox
gdf = ox.gdf_from_places(queries=[{'country':'Mexico'}, 'Guatemala', {'state':'Texas'}])
unified = gdf.unary_union