[R-sig-Geo] st_union crashes RStudio - bug?
Bertram Ostendorf
bertr@m@o@tendorf @ending from @del@ide@edu@@u
Fri Sep 14 08:33:25 CEST 2018
I am trying to dissolve internal boundaries using sf. This crashes R in the example geojson map below, a simple map of Australia’s states and territories. I am using a polygon layer that processes fine in other GIS and also works fine using sp (casting to sp and using gUnaryUnion). I am not after a workaround but I'd like to explore what's different in sf and why this particular layer causes problems.
My questions: Is this a bug in sf? Have others experienced similar issues using simple features?
Thanks
Bertram Ostendorf
Chair for Spatial Environmental Sciences
Director: Spatial Information Group
The University of Adelaide, AUSTRALIA 5005
# Here's my example layer and code:
# Note: Neither ArcGIS ‘repair geometry’ nor ‘st_is_valid’ show any issues.
library(sf)
library(ggplot2)
# read Australia.geojson from dropbox, 15.5Mb
test <- st_read("https://www.dropbox.com/s/060c6lfijyx1e5v/Australia.geojson?dl=1")
st_is_valid(test)
# The next lines work fine, I added them to illustrate what works
ggplot(test) + geom_sf(aes(fill=STATE))
ACT <- test[test$STATE == 'ACT', ]
NSW <- test[test$STATE == 'NSW', ]
ACTandNSW <- test[test$STATE %in% c('NSW','ACT'), ]
noACT <- test[test$STATE != 'ACT', ]
noNSW <- test[test$STATE != 'NSW', ]
noACTandNSW <- test[!test$STATE %in% c('NSW','ACT'), ]
# st_union works ok for most subsets. But note that some internal boundaries are not removed.
ok <- st_union(ACT)
# donut polygons work fine
ok <- st_union(NSW)
# donut polygons (NSW) filled (ACT) work fine
ok <- st_union(ACTandNSW)
# all states except NSW work fine
ok <- st_union(noNSW)
# ok if both ACT and NSW are removed
ok <- st_union(noACTandNSW)
ggplot(ok) + geom_sf()
# Thing go pear-shaped if the hole is filled (ACT in NSW), but only if neighbours of the filled donut polygon are present.
# The two lines below stall R and eventually crash RStudio
crash <- st_union(test)
# Australia without its governing territory kills R
crash <- st_union(noACT)
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.0.0 sf_0.6-3
loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 rstudioapi_0.7 bindr_0.1.1 magrittr_1.5 units_0.6-0 tidyselect_0.2.4 munsell_0.5.0
[8] colorspace_1.3-2 R6_2.2.2 rlang_0.2.2 plyr_1.8.4 dplyr_0.7.6 tools_3.5.1 grid_3.5.1
[15] gtable_0.2.0 e1071_1.7-0 DBI_1.0.0 withr_2.1.2 class_7.3-14 digest_0.6.16 yaml_2.2.0
[22] lazyeval_0.2.1 assertthat_0.2.0 tibble_1.4.2 crayon_1.3.4 bindrcpp_0.2.2 spData_0.2.9.3 purrr_0.2.5
[29] glue_1.3.0 compiler_3.5.1 pillar_1.3.0 scales_1.0.0 classInt_0.2-3 pkgconfig_2.0.2
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list