creating a polygon that covers other polygons layer using python

Question:

I have a layer with polygons (buildings) and I would like create a polygon that limits the area where the polygons are using geopandas or other python module

SO I have these buildings:

enter image description here

and I would like to have a new layer with a polygon that covers all buildings:

enter image description here

so this:

enter image description here

where it covers the building polygons area .
It can be that also a polygon that covers all the buildings and not goes exactly on the vertices of the outside buildings.

Asked By: Ricardo Gomes

||

Answers:

Using geopandas you could apply unary_union to create a multipolygon out of your polygons and then use convex_hull:

import geopandas as gpd
gdf1 = gpd.read_file(r"C:UsersXDesktoptestpoly.shp")
gdf2 = gpd.GeoDataFrame(geometry=[gdf1.unary_union.convex_hull], crs="EPSG:4326")
gdf1.plot()
gdf2.plot()

enter image description here

Answered By: NielsFlohr
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.