# Removing elongated, "thin" parts of shapes using R

I have a dataset with a lot of polygons, of which some are long and thin in shape (see image). I'd like to remove their "extremities".

Is there a tool/method to remove thin parts of a polygon in R?*

In the example, the elongated shapes vary in shape and thickness

• I thought about using a shape-ratio (e.g. perimeter/area, as described here), but that only allows me to remove complete polygons, whereas in some cases I'd like to preserve the "roundish" part of a polygon.
• I'd like to be able to experiment with thresholds to find a suitable setting for the "roundness".
• Removing thin rectangles from a shapely polygon seems like a similar problem, but I'd rather not use shapely

• One approach would be to apply a buffer with a negative size (i.e. shrink polygons), then apply a buffer with the same but positive size. You'll also lose details of the 'wide' parts of the polygons however. Oct 27, 2021 at 8:44
• When you talk about "complete" and "parts" of a polygon, are you talking about individual polygons of a multipolygon feature? Because you can totally split multipolygons into polygons, filter on area/perimeter and rebuild multipolygons in R with the sf package... Oct 27, 2021 at 13:25
• Sorry if I wasn't clear there. With "parts" I was not referring to "polygons of a multipolygon" but "a portion of a continous polygon", e.g. the two elongated "arms/antlers" of the red polygon in the middle/bottom. Oct 27, 2021 at 13:29

Try using buffer

1. Buffer with a negative distance, for example -50
2. Buffer with +60
3. Clip the buffers with your original polygons

Buffering with negative distance and then the positive distance (plus some extra to account for loss of detail) as suggested in this answer can be realized with this code (in R):

``````BUFFER_WIDTH = 10

# negative buffer removes parts of the polygons
poly = raster::buffer(poly, width= - BUFFER_WIDTH )

# positive buffer recreates shape from the remainders
poly = raster::buffer(poly, width=   BUFFER_WIDTH + (BUFFER_WIDTH * 0.1))
``````

• you may want to filter small areas (red), that might be created by artifact leftovers after negative buffering. In R: `poly_new <- drop_crumbs(poly, threshold = AREA_THRESH)`