Geopandas Overlapping Check – How to Perform Overlapping Check Using Geopandas

geopandaspython

How we can check if feature has intersections or not with other features in one shapefile data?

I want to make sure if in that file there is no overlaps between polygon, I have read this approach "An Approach for Checking Overlaps and Gaps in Polygons using Geopandas" and I know that work, but is there any better solutions? With these way the process take time because the loop.

data_overlaps=gpd.GeoDataFrame(crs=data_temp.crs)
for index, row in data_temp.iterrows():
    data_temp1=data_temp.loc[data_temp.ID!=row.ID,]
    overlaps=data_temp1[data_temp1.geometry.overlaps(row.geometry)]['ID'].tolist()
    if len(overlaps)>0:
        for j in overlaps:
            temp_area=gpd.overlay(data_temp.loc[data_temp.ID==row.ID,],data_temp.loc[data_temp.ID==row.ID,],how='intersection')
            temp_area=temp_area.loc[temp_area.geometry.area>=9e-9]
            if temp_area.shape[0]>0:
                data_overlaps=gpd.GeoDataFrame(pd.concat([temp_area,data_overlaps],ignore_index=True),crs=data_temp.crs)

Best Answer

I have found a solution, although the speed of processing depends on the size of the file, I'm using maup python library with some modification on maup.close_gaps(geometries) and maup.resolve_overlaps(geometries) where geometry are GeoSeries data type from goepandas.