Ошибка в RGEOSBinTopoFun c при кадрировании SpatialPolygon в R - PullRequest
0 голосов
/ 04 февраля 2020

У меня странная проблема, я не могу обрезать SpatialPolygonsDataFrame , когда я использую определенные экстенты в своем ноутбуке Ubuntu 18.04 с моей версией R 3.6.2, это воспроизводимый пример, где он работает с один экстент, а не другой:

Сначала я загружу пакеты

library(raster)
library(rworldxtra)

Я буду использовать набор данных для стран:

data("countriesHigh")

Теперь я создам 2 различные экстенты:

e1 <- new("Extent", xmin = -87.5, xmax = -27.5, ymin = -60, ymax = 15)
e2 <- new("Extent", xmin = -60, xmax = -27, ymin = -40, ymax = 15)

Теперь, когда я пытаюсь обрезать countryHigh с e1 , я получаю ошибку

SA1 <- crop(countriesHigh, e1)

и следующее сообщение

Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false,  : 
  TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point -68.642342900000003 -54.853653260000002 at -68.642342900000003 -54.853653260000002
In addition: Warning messages:
1: In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") :
  Ring Self-intersection at or near point -68.642342900000003 -54.853653260000002
2: In rgeos::gIntersection(x[i, ], y, byid = TRUE, drop_lower_td = TRUE) :
  Invalid objects found; consider using set_RGEOS_CheckValidity(2L)

если я делаю это с экстентом e2 , это работает

SA2 <- crop(countriesHigh, e2)

Это информация о моем сеансе от devtools

 setting  value                       
 version  R version 3.6.2 (2019-12-12)
 os       Ubuntu 18.04.3 LTS          
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/Santiago            
 date     2020-02-04                  

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                         
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.2)                 
 backports     1.1.5      2019-10-02 [1] CRAN (R 3.6.2)                 
 callr         3.4.1      2020-01-24 [1] CRAN (R 3.6.2)                 
 cli           2.0.1      2020-01-08 [1] CRAN (R 3.6.2)                 
 codetools     0.2-16     2018-12-24 [4] CRAN (R 3.5.2)                 
 crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.2)                 
 desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.2)                 
 devtools      2.2.1      2019-09-24 [1] CRAN (R 3.6.2)                 
 digest        0.6.23     2019-11-23 [1] CRAN (R 3.6.2)                 
 ellipsis      0.3.0      2019-09-20 [1] CRAN (R 3.6.2)                 
 fansi         0.4.1      2020-01-08 [1] CRAN (R 3.6.2)                 
 fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.2)                 
 glue          1.3.1.9000 2020-01-09 [1] Github (tidyverse/glue@b9ffe6c)
 lattice       0.20-38    2018-11-04 [4] CRAN (R 3.5.1)                 
 magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.2)                 
 memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.2)                 
 packrat       0.5.0      2018-11-14 [1] CRAN (R 3.6.2)                 
 pkgbuild      1.0.6      2019-10-09 [1] CRAN (R 3.6.2)                 
 pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.2)                 
 prettyunits   1.1.1      2020-01-24 [1] CRAN (R 3.6.2)                 
 processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.2)                 
 ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.2)                 
 R6            2.4.1      2019-11-12 [1] CRAN (R 3.6.2)                 
 raster      * 3.0-12     2020-01-30 [1] CRAN (R 3.6.2)                 
 Rcpp          1.0.3      2019-11-08 [1] CRAN (R 3.6.2)                 
 remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.2)                 
 rgdal         1.4-8      2019-11-27 [1] CRAN (R 3.6.2)                 
 rgeos         0.5-2      2019-10-03 [1] CRAN (R 3.6.2)                 
 rlang         0.4.4      2020-01-28 [1] CRAN (R 3.6.2)                 
 rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.2)                 
 rstudioapi    0.10       2019-03-19 [1] CRAN (R 3.6.2)                 
 rworldxtra  * 1.01       2012-10-03 [1] CRAN (R 3.6.2)                 
 sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.2)                 
 sp          * 1.3-2      2019-11-07 [1] CRAN (R 3.6.2)                 
 testthat      2.3.1      2019-12-01 [1] CRAN (R 3.6.2)                 
 usethis       1.5.1      2019-07-04 [1] CRAN (R 3.6.2)                 
 withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.2)                 

[1] /home/derek/R/x86_64-pc-linux-gnu-library/3.6
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library

Попытка на другом компьютере

Я попытался на rstudio.cloud

, и это сработало, это информация о сеансе, я не знаю, что не так с моей версией

─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.0 (2019-04-26)
 os       Ubuntu 16.04.6 LTS          
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  C.UTF-8                     
 ctype    C.UTF-8                     
 tz       Etc/UTC                     
 date     2020-02-04                  

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] RSPM (R 3.6.0)
 backports     1.1.5   2019-10-02 [1] RSPM (R 3.6.0)
 callr         3.4.1   2020-01-24 [1] RSPM (R 3.6.0)
 cli           2.0.1   2020-01-08 [1] RSPM (R 3.6.0)
 codetools     0.2-16  2018-12-24 [2] CRAN (R 3.6.0)
 crayon        1.3.4   2017-09-16 [1] RSPM (R 3.6.0)
 desc          1.2.0   2018-05-01 [1] RSPM (R 3.6.0)
 devtools      2.2.1   2019-09-24 [1] RSPM (R 3.6.0)
 digest        0.6.23  2019-11-23 [1] RSPM (R 3.6.0)
 ellipsis      0.3.0   2019-09-20 [1] RSPM (R 3.6.0)
 fansi         0.4.1   2020-01-08 [1] RSPM (R 3.6.0)
 fs            1.3.1   2019-05-06 [1] RSPM (R 3.6.0)
 glue          1.3.1   2019-03-12 [1] RSPM (R 3.6.0)
 lattice       0.20-38 2018-11-04 [2] CRAN (R 3.6.0)
 magrittr      1.5     2014-11-22 [1] RSPM (R 3.6.0)
 memoise       1.1.0   2017-04-21 [1] RSPM (R 3.6.0)
 pkgbuild      1.0.6   2019-10-09 [1] RSPM (R 3.6.0)
 pkgload       1.0.2   2018-10-29 [1] RSPM (R 3.6.0)
 prettyunits   1.1.1   2020-01-24 [1] RSPM (R 3.6.0)
 processx      3.4.1   2019-07-18 [1] RSPM (R 3.6.0)
 ps            1.3.0   2018-12-21 [1] RSPM (R 3.6.0)
 R6            2.4.1   2019-11-12 [1] RSPM (R 3.6.0)
 raster      * 3.0-12  2020-01-30 [1] RSPM (R 3.6.0)
 Rcpp          1.0.3   2019-11-08 [1] RSPM (R 3.6.0)
 remotes       2.1.0   2019-06-24 [1] RSPM (R 3.6.0)
 rgeos         0.5-2   2019-10-03 [1] RSPM (R 3.6.0)
 rlang         0.4.4   2020-01-28 [1] RSPM (R 3.6.0)
 rprojroot     1.3-2   2018-01-03 [1] RSPM (R 3.6.0)
 rstudioapi    0.10    2019-03-19 [1] RSPM (R 3.6.0)
 rworldxtra  * 1.01    2012-10-03 [1] RSPM (R 3.6.0)
 sessioninfo   1.1.1   2018-11-05 [1] RSPM (R 3.6.0)
 sp          * 1.3-2   2019-11-07 [1] RSPM (R 3.6.0)
 testthat      2.3.1   2019-12-01 [1] RSPM (R 3.6.0)
 usethis       1.5.1   2019-07-04 [1] RSPM (R 3.6.0)
 withr         2.1.2   2018-03-15 [1] RSPM (R 3.6.0)

[1] /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6
[2] /opt/R/3.6.0/lib/R/library
...