7

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

example of polygons with elongated shapes

Taras
  • 32,823
  • 4
  • 66
  • 137
Honeybear
  • 2,454
  • 1
  • 15
  • 25
  • 1
    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. – Berend Oct 27 '21 at 08: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... – Spacedman Oct 27 '21 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. – Honeybear Oct 27 '21 at 13:29

2 Answers2

8

Try using buffer

  1. Buffer with a negative distance, for example -50
  2. Buffer with +60
  3. Clip the buffers with your original polygons
BERA
  • 72,339
  • 13
  • 72
  • 161
4

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))

Comments:

  • this will also work like a smoothing operation
  • intersecting the buffers with your original polygons is only needed if you want the original (more detailed) outline
  • 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)

Result: Blue original polygon, green/red resulting polygon. Blue original polygon, green/red resulting polygon after removing elongated parts.

Honeybear
  • 2,454
  • 1
  • 15
  • 25