Search code examples
pythonpolygongeopandasarea

creating a polygon that covers other polygons layer using python


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.


Solution

  • 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:\Users\X\Desktop\testpoly.shp")
    gdf2 = gpd.GeoDataFrame(geometry=[gdf1.unary_union.convex_hull], crs="EPSG:4326")
    gdf1.plot()
    gdf2.plot()
    

    enter image description here