I'm merging/dissolving a mixed bag of property boundary geometries and have hit a snag with an object containing a MULTISURFACE geometry. I've been casting the geometries to MULTIPOLYGON prior to the dissolve without issue, including properties with former MULTISURFACE geometries. Thus I believe the issue is related to this specific boundary, not to MULTISURFACE geometries in general.
Any guidance for dissolving in this situation?
Will st_combine followed by st_sf accomplish essentially the same goal if the objective is simply to clip a MULTIPOINT geometry to the boundary?
library(dplyr)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.0, proj.4 4.9.3
packageVersion("sf")
#> [1] '0.5.4'
tetlin <- readRDS("./tetlin.rds")
# 7th component is MULTISURFACE
# It plots with the whole object...
plot(tetlin)
# But not alone (no plotting method for MULTISURFACE?)
plot(tetlin[7,])
# Casting to MULTIPOLYGON overcomes the plotting issue
tetlin <- tetlin %>% st_cast(to = "MULTIPOLYGON")
plot(tetlin)
# Attempts to merge into single MULTIPOLYGON fail
tetlin %>% group_by(ORGNAME) %>% summarize()
#> Error in CPL_geos_union(st_geometry(x), by_feature): Evaluation error: TopologyException: Input geom 0 is invalid: Hole lies outside shell at or near point -141.55936108399999 62.771209905000035 at -141.55936108399999 62.771209905000035.
# Ignoring the previous MULTISURFACE works
tetlin[1:6, ] %>% group_by(ORGNAME) %>% summarize()
# Is this a suitable alternative?
tet <- st_combine(tetlin)
tet <- st_sf(data.frame(ORGNAME = "TETLIN NATIONAL WILDLIFE REFUGE",
geom = tet,
stringsAsFactors = FALSE))
either
tetlin %>% st_make_valid() # requires liblwgeom
or
tetlin %>% st_buffer(0)
seem to do the trick.
Thanks very much @edzer. I'm embarrassed I didn't think to try the st_buffer(0) option before bothering you. It seems to be the r-spatial equivalent of magic fairy dust...
Most helpful comment
either
or
seem to do the trick.