3

I have a map on QGIS that looks like this:

enter image description here

I would like to clean the weird-looking polygons (inside a red circle for example) and keep the normal-looking ones. My initial approach was to compute the area of all polygons and deleted by size (i.e. deleting large polygons)

#convert to MERCHICH NORD and compute area in km2

gpd= gpd.to_crs({'init': 'epsg:26191'}) 
gpd["area_km2"] = gpd['geometry'].area/ 10**6

But deleting large polygons (by size) is misleading because some large polygons are valid. Then I tried to look for a different approach and compute by shape type by using a function similar to geopandas.GeoSeries.geom_type but this function only outputs: centroid, polygon or linestring.

My question is: how can we delete weird looking polygons like the one circled in red and only keep the normal ones (polygons related to buildings or residential area)?

2
  • 3
    The criteria for filtering polygons is quite vague. Can you describe a bit more in detail what exactly are the charactristics that distinguish a "normal" from a "weird" one (your terminology)? Only if we have this information can we give an answer.
    – Babel
    May 19 at 11:59
  • 1
    @babel My goal is to keep only residential polygons. So polygons that follow the roads and miss residential areas are of no interest to me.
    – bravopapa
    May 19 at 13:20

1 Answer 1

6

If by "weird" you mean "significantly convex" then one approach would be to calculate the ratio of the perimeter or area of the convex hull of each polygon to the perimeter or area of the polygon.

For "normal" ones, the ratio will be 1. For "weird" ones, the ratio of the area will be high, and the perimeter low.

How high or low is going to depend on your "weird"-ness factor. You'll need to experiment with figures, which will be different for perimeter vs area. Probably start with > 2 for area, and < 0.5 for perimeter, and go from there.

Expression for area ratio:

area(convex_hull($geometry))/area($geometry)

Expression for perimeter ratio:

perimeter(convex_hull($geometry))/perimeter($geometry)

3
  • 1
    The area, the convexity and the surface are concepts that iam familiar with. Not so for the convex_hull... I understand that it is a concept that measures the minimum surface that is need to contain a set of points but intuitively how will it help me detect 'weirdness'? Thank you for clarifying or pointing me to a link where i can better understand
    – bravopapa
    May 19 at 13:52
  • 1
    This code might be helpful for people facing similar issues: gdf['convexHull']=gdf.geometry.convex_hull gdf['ratio_area_convexity']= gdf.convexHull.area/gdf.geometry.area
    – bravopapa
    May 20 at 9:46
  • All the weird polygons are cleaned up. Thanks very much for the suggestion. I ended up using ratio>=3
    – bravopapa
    May 20 at 13:45

Your Answer

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

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