Reputation: 708
In gboeing's 02-example-osm-to-shapefile.ipynb example, multiple shapefiles are downloaded from OSM to a geodataframe using the gdf_from_places() method. The geometry is stored as Multipolygons in a Geopanda's dataframe with each row representing a place.
# 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)
In regards to the question, I've experimented with using Geopanda's GeoSeries.unary_union but wanted to know how others were accomplishing this programmatically in Python.
This method uses the Shapely function of unary_union (it would otherwise be mx_gt_tx["geometry"].unary_union through Geopandas as pointed out by @joris comment.
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 )
Upvotes: 1
Views: 1080
Reputation: 6422
import osmnx as ox
gdf = ox.gdf_from_places(queries=[{'country':'Mexico'}, 'Guatemala', {'state':'Texas'}])
unified = gdf.unary_union
Upvotes: 2