Skip to content

elevatr::get_elev_raster(..., clip = 'bbox') is broken #104

Description

@courtiol

The function get_elev_raster() is currently broken when using the argument clip = 'bbox'.
I think this comes from a change in how sf and/or terra behave.

elevatr::get_elev_raster(
  locations = data.frame(
    x = c(-180, 180),
    y = c(-90, 90)),
  z = 1,
  prj = "+proj=longlat +datum=WGS84 +no_defs",
  clip = "bbox")
#> Mosaicing & Projecting
#> Clipping DEM to bbox
#> Error : IllegalArgumentException: Invalid number of points in LinearRing found 2 - must be 0 or >= 3
#> Error: [as,sf] coercion failed. You can try coercing via a Spatial* (sp) class

It seems easy to fix.

The bug is triggered here:

dem <- terra::mask(terra::crop(rast,bbx_sf), bbx_sf)

And this workaround seems to work:
dem <- terra::mask(terra::crop(rast, bbx_sf), terra::ext(bbx_sf))

However since terra::crop(rast, bbx_sf) just works and terra::mask(rast, bbx_sf) does not, perhaps it is something that would be better solved in terra directly... -> @rhijmans, please us know if you if you want a reprex.

My session:

sessionInfo()
#> R version 4.5.2 (2025-10-31)
#> Platform: x86_64-redhat-linux-gnu
#> Running under: Fedora Linux 43 (KDE Plasma Desktop Edition)
#> 
#> Matrix products: default
#> BLAS/LAPACK: FlexiBLAS OPENBLAS-OPENMP;  LAPACK version 3.12.1
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Europe/Berlin
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] terra_1.8-86       crayon_1.5.3       vctrs_0.6.5        httr_1.4.7        
#>  [5] cli_3.6.5          knitr_1.50         progressr_0.18.0   rlang_1.1.7       
#>  [9] xfun_0.55          DBI_1.2.3          KernSmooth_2.23-26 purrr_1.2.0       
#> [13] sf_1.0-23          glue_1.8.0         prettyunits_1.2.0  htmltools_0.5.9   
#> [17] e1071_1.7-16       hms_1.1.4          rmarkdown_2.30     grid_4.5.2        
#> [21] elevatr_0.99.1     evaluate_1.0.5     classInt_0.4-11    fastmap_1.2.0     
#> [25] progress_1.2.3     yaml_2.3.12        lifecycle_1.0.5    compiler_4.5.2    
#> [29] codetools_0.2-20   fs_1.6.6           pkgconfig_2.0.3    slippymath_0.3.1  
#> [33] Rcpp_1.1.0         rstudioapi_0.17.1  digest_0.6.39      R6_2.6.1          
#> [37] class_7.3-23       reprex_2.1.1       curl_7.0.0         magrittr_2.0.4    
#> [41] tools_4.5.2        withr_3.0.2        proxy_0.4-28       units_1.0-0

Update: same behavior with terra 1.8-94.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions