After dissolving inner boundaries, this sf shape [Pastebin] retains residual specks or crumbs:


#download file "shp.txt" from Pastebin
shp <- dget("shp.txt")

[1] "sfc_MULTIPOLYGON" "sfc"


shape before

I have tried 2 different methods of removing them but both fall short:

#CRS is in meters so that threshold parameters are expressed in square meters in both methods
[1] "m"

#Method #1
shp <- ms_filter_islands(shp, min_area=1000000)

Method #1 fails to remove at least one tiny speck in the centre of the shape:

shape after

#Method #2
shp <- drop_crumbs(shp, threshold=1000000)

Method #2 doesn't do anything, apparently.

What are substitute or complementary ways of accomplishing the task?

  • What type of spatial object is your data on pastebin? Also, take a look at this QA: gis.stackexchange.com/questions/264562/…
    – Aaron
    Jun 7 at 2:59
  • It's an sf object.
    – syre
    Jun 7 at 3:25
  • @Aaron The linked answer is for polygons but some specks might be lines or points, for all I know. The answer seems to apply to a different object type. The answer also refers to rmapshaper, which my question includes.
    – syre
    Jun 7 at 3:33
  • 1
    One hack is to use a buffer/negative-buffer to clean up small polygons and holes. Keep in mind though that this approach can smooth polygons, especially if you use too big of a buffer size.
    – Aaron
    Jun 7 at 3:43
  • I flagged my question to be transferred to StackOverflow, considering the relatively low attention it is getting here (GIS-SE) and my experience of getting fast answers to computational geospatial questions on SO. My flag was declined with the argument that the question is on topic for GIS-SE. However, I am still waiting as a result. Should I consequently cross-post in SO, in accordance with this answer on Meta-SE? I submit that this moderation policy discourages from posting this type of question here instead of on SO in the first place.
    – syre
    Jun 8 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.