Validity after aggregation with do_union = FALSE · Issue #681 · r-spatial/sf (original) (raw)

Lately, I've tried to aggregate some spatial data without unioning them. This process often ends with non-valid polygons (see the last example below), however aggregation with union works fine. Original data are also valid. Is is possible to improve it on the sf part or using lwgeom::st_make_valid() is the only feasible solution?

The sample data is attached - map.zip.

library(sf)
library(lwgeom)
#> Linking to liblwgeom 2.3.2 r15302, GEOS 3.6.1, proj.4 4.9.3 map = st_read("/vsizip/map.zip")

check if map is valid

all(st_is_valid(map))
#> [1] TRUE

aggregate and union them

map_aggr_union = aggregate(map, by = list(group = map$NAME), FUN = function(x) x[1], do_union = TRUE)

check if map_aggr_union is valid

all(st_is_valid(map_aggr_union))
#> [1] TRUE

aggregate them

map_aggr = aggregate(map, by = list(group = map$NAME),
FUN = function(x) x[1], do_union = FALSE)

check if map_aggr is valid

all(st_is_valid(map_aggr))
#> [1] FALSE