1

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

library(sf)

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

class(shp)
[1] "sfc_MULTIPOLYGON" "sfc"

plot(shp)

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
st_crs(shp)$units 
[1] "m"

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

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

shape after

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

Method #2 doesn't do anything, apparently.

What are substitute or complementary ways of accomplishing the task?

7
  • What type of spatial object is your data on pastebin? Also, take a look at this QA: gis.stackexchange.com/questions/264562/…
    – Aaron
    Commented Jun 7, 2021 at 2:59
  • It's an sf object.
    – syre
    Commented Jun 7, 2021 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
    Commented Jun 7, 2021 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
    Commented Jun 7, 2021 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
    Commented Jun 8, 2021 at 2:54

0

Your Answer

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

Browse other questions tagged or ask your own question.