在gboeing的02-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中以编程方式完成此工作的。
此方法使用Shapely function of unary_union(否则将是@joris注释指出的通过Geopandas的mx_gt_tx [“ geometry”]。unary_union。
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 )
答案 0 :(得分:1)
import osmnx as ox
gdf = ox.gdf_from_places(queries=[{'country':'Mexico'}, 'Guatemala', {'state':'Texas'}])
unified = gdf.unary_union