pfrater / arcpullr

21 stars 9 forks source link

error when trying to access rasters with get_map_layer() #17

Open jaymwin opened 9 months ago

jaymwin commented 9 months ago

Thanks for all your work on this package, it has been super helpful for pulling vector layers into R and I recently decided to give it a try for some raster layers that I'm interested in using for an analysis. However, I seem to be running into an issue with the 'get_map_layer' function.

I'm trying to pull burn severity rasters from MTBS for the Sierra Nevada region. Here's the code:

library(tidyverse)
library(sf)
library(arcpullr)

# create sf object; sierra nevada ecoregion
sierra_nevada_sf <-
  get_spatial_layer(
    url = 'https://edits.nationalmap.gov/arcgis/rest/services/landforms/landforms_epa_eco_regions/MapServer/0',
    where = "US_L3NAME = 'Sierra Nevada'"
  ) |>
  # just use a simple bounding box for now
  st_bbox() |> 
  st_as_sfc() |> 
  st_as_sf()

# query mtbs rasters
ca_fire <- get_map_layer('https://apps.fs.usda.gov/arcx/rest/services/RDW_Wildfire/MTBS_CONUS/MapServer', sierra_nevada_sf)

Which gives me the following error:

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file.
In addition: Warning message:
`C:/Users/jmwin/AppData/Local/Temp/RtmpcZctRJ/file871c40e54c95' not recognized as a supported file format. (GDAL error 4) 

Initially, I was hoping to download each year of burn severity data separately. It seems this might be possible according to a previous issue, but I get the same error above:

# doesn't work either; 1984 data
ca_fire <- 
  get_map_layer(
  'https://apps.fs.usda.gov/arcx/rest/services/RDW_Wildfire/MTBS_CONUS/MapServer/', 
  sierra_nevada_sf, 
  layers = 'show:38'
  )

This led me back to the vignette, but I also get the error when trying to reproduce the Wiscland2 code:

# wi_landcover is part of the package; this doesn't work
wi_landcover2 <- get_map_layer(landcover_url, wis_poly)

Here's my session info if it is helpful:

> sessionInfo()
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] arcpullr_0.2.8  sf_1.0-14       lubridate_1.9.3 forcats_1.0.0   stringr_1.5.0   dplyr_1.1.3     purrr_1.0.2     readr_2.1.4    
 [9] tidyr_1.3.0     tibble_3.2.1    ggplot2_3.4.4   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] gtable_0.3.4       raster_3.6-23      htmlwidgets_1.6.2  lattice_0.21-8     RMariaDB_1.2.2     tzdb_0.4.0        
 [7] vctrs_0.6.3        tools_4.3.1        generics_0.1.3     curl_5.0.2         proxy_0.4-27       fansi_1.0.4       
[13] pkgconfig_2.0.3    KernSmooth_2.23-21 assertthat_0.2.1   lifecycle_1.0.3    compiler_4.3.1     tictoc_1.2        
[19] munsell_0.5.0      terra_1.7-46       keyring_1.3.1      codetools_0.2-19   htmltools_0.5.6    class_7.3-22      
[25] pillar_1.9.0       crayon_1.5.2       classInt_0.4-10    DT_0.29            tidyselect_1.2.0   digest_0.6.33     
[31] stringi_1.7.12     rprojroot_2.0.3    fastmap_1.1.1      grid_4.3.1         here_1.0.1         colorspace_2.1-0  
[37] cli_3.6.1          magrittr_2.0.3     utf8_1.2.3         e1071_1.7-13       withr_2.5.2        scales_1.2.1      
[43] sp_2.0-0           bit64_4.0.5        timechange_0.2.0   httr_1.4.7         bit_4.0.5          hms_1.1.3         
[49] rlang_1.1.1        Rcpp_1.0.11        glue_1.6.2         DBI_1.1.3          rstudioapi_0.15.0  vroom_1.6.3       
[55] jsonlite_1.8.7     R6_2.5.1           units_0.8-4 

Thanks!