efficient method of two polygon shpfile intersection using python

Viewed 22

I have a fishnet data (~10000000) and a polygon shapfile.I want to calculat polygon intersecting area with a grid cells.The red is fishnet data, and the green is polygon data

enter image description here

Currently, I can obtain the intersecting area:

    sjoin_grid = gpd.sjoin(fishnet, polygon[['geometry']])
    sjoin_grid=sjoin_grid.drop_duplicates(subset=['CODE'], keep='last')

    if(len(sjoin_grid)>0):
        overlay = gpd.overlay(polygon, sjoin_grid, how='intersection')
        overlay = overlay.to_crs({'proj':'laea'})
        overlay['area'] = overlay['geometry'].area/10**6
        overlay_group=overlay.groupby(['CODE'])['area'].sum().reset_index()
        result = sjoin_grid.merge(overlay_group, on='CODE')
        result=result.to_crs({'proj':'laea'})
        result['ratio'] = result['area']/(result ['geometry'].area/10**6)
        result=result.to_crs(epsg=4326) 

Because the fishnet have too many meshes, so I used sjoin to remove the meshes that do not intersect with the polygon. However, the calculation still spend ~30 minutes, espacially the sjoin calculation. Is there a efficient method to speed up the calculation.

0 Answers
Related