1

enter image description hereI have a shapefile with 850,000 records. What I am trying to do is merge all adjacent polygons and keep the lowest value for the group.

so for example my polygon is land_plots and has a crop_yield field which is numeric. Some of my land plots touch and some do not.

So i am

import geopandas as gpd
shp = '/content/drive/land_plots.shp'
df = gpd.read_file(shp)
# merge adjacent polygons
mergedPolys = gpd.GeoDataFrame(geometry=list(df.unary_union))

so here i end up with around 50,000 records and i need to assign the lowest crop yield from each plot.

in the image they are squares but in reality they are irregular shapes.

1 Answer 1

0

Adding this to the code above is what i believe will work, albeit very slow and probably not the most efficient.

mergedPolys['PolygonGroupID'] = mergedpolys.index
points = df.copy()
points['geometry'] =points['geometry'].centroid
pointInPoly = gpd.sjoin(mergedPolys, points, op='contains')
poly_agg = pointInPoly.dissolve(by='polygonGroupID', aggfunc = 'min')

Maybe someone has a better way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.