FedData icon indicating copy to clipboard operation
FedData copied to clipboard

get_nlcd() issue

Open n-a-gilbert opened this issue 1 year ago • 8 comments

I'm trying to use the get_nlcd() function to download NLCD data for the lower 48. I'm using a SpatRaster as my template. I keep getting this error message:

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.factor': [rast] cannot open this file as a SpatRaster: C:\Users\12487\AppData\Local\Temp\RtmpOkzDko\file22306a166a7.tif In addition: Warning message: C:\Users\12487\AppData\Local\Temp\RtmpOkzDko\file22306a166a7.tif' not recognized as a supported file format. (GDAL error 4)

I tried downloading the development version of FedData but still received this error. Any ideas for what is going on here? My session info is below. Thanks!

R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
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] terra_1.7-78        dplyr_1.1.4         sf_1.0-16           rnaturalearth_1.0.1 ebirdst_3.2022.3    here_1.0.1         
[7] FedData_4.0.1      

loaded via a namespace (and not attached):
 [1] htmlwidgets_1.6.4             devtools_2.4.5                remotes_2.5.0                 processx_3.8.4               
 [5] lattice_0.22-6                callr_3.7.6                   tzdb_0.4.0                    vctrs_0.6.5                  
 [9] tools_4.4.0                   ps_1.7.6                      generics_0.1.3                curl_5.2.1                   
[13] tibble_3.2.1                  proxy_0.4-27                  fansi_1.0.6                   pkgconfig_2.0.3              
[17] KernSmooth_2.23-22            desc_1.4.3                    lifecycle_1.0.4               compiler_4.4.0               
[21] stringr_1.5.1                 codetools_0.2-20              httpuv_1.6.15                 htmltools_0.5.8.1            
[25] usethis_2.2.3                 class_7.3-22                  later_1.3.2                   pillar_1.9.0                 
[29] urlchecker_1.0.1              ellipsis_0.3.2                classInt_0.4-10               cachem_1.1.0                 
[33] sessioninfo_1.2.2             mime_0.12                     tidyselect_1.2.1              digest_0.6.35                
[37] stringi_1.8.4                 purrr_1.0.2                   rprojroot_2.0.4               fastmap_1.2.0                
[41] grid_4.4.0                    cli_3.6.2                     magrittr_2.0.3                pkgbuild_1.4.4               
[45] utf8_1.2.4                    e1071_1.7-14                  readr_2.1.5                   promises_1.3.0               
[49] sp_2.1-4                      httr_1.4.7                    rnaturalearthhires_1.0.0.9000 hms_1.1.3                    
[53] memoise_2.0.1                 shiny_1.8.1.1                 miniUI_0.1.1.1                profvis_0.3.8                
[57] rlang_1.1.3                   Rcpp_1.0.12                   xtable_1.8-4                  glue_1.7.0                   
[61] DBI_1.2.3                     xml2_1.3.6                    pkgload_1.3.4                 rstudioapi_0.16.0            
[65] jsonlite_1.8.8                R6_2.5.1                      fs_1.6.4                      units_0.8-5

n-a-gilbert avatar Jun 20 '24 15:06 n-a-gilbert

Hi Neil. I don'y know quite what is going on here, but since you want all of CONUS you'd probably be better off downloading the raw NLCD data yourself. Here is a one-click download for the 2021 dataset (the most recent version):

https://s3-us-west-2.amazonaws.com/mrlc/nlcd_2021_land_cover_l48_20230630.zip

Hope this helps!

On Jun 20, 2024, at 9:10 AM, Neil Gilbert @.***> wrote:

I'm trying to use the get_nlcd() function to download NLCD data for the lower 48. I'm using a SpatRaster as my template. I keep getting this error message:

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.factor': [rast] cannot open this file as a SpatRaster: C:\Users\12487\AppData\Local\Temp\RtmpOkzDko\file22306a166a7.tif In addition: Warning message: C:\Users\12487\AppData\Local\Temp\RtmpOkzDko\file22306a166a7.tif' not recognized as a supported file format. (GDAL error 4)

I tried downloading the development version of FedData but still received this error. Any ideas for what is going on here? My session info is below. Thanks!

R version 4.4.0 (2024-04-24 ucrt) Platform: x86_64-w64-mingw32/x64 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] terra_1.7-78 dplyr_1.1.4 sf_1.0-16 rnaturalearth_1.0.1 ebirdst_3.2022.3 here_1.0.1
[7] FedData_4.0.1

loaded via a namespace (and not attached): [1] htmlwidgets_1.6.4 devtools_2.4.5 remotes_2.5.0 processx_3.8.4
[5] lattice_0.22-6 callr_3.7.6 tzdb_0.4.0 vctrs_0.6.5
[9] tools_4.4.0 ps_1.7.6 generics_0.1.3 curl_5.2.1
[13] tibble_3.2.1 proxy_0.4-27 fansi_1.0.6 pkgconfig_2.0.3
[17] KernSmooth_2.23-22 desc_1.4.3 lifecycle_1.0.4 compiler_4.4.0
[21] stringr_1.5.1 codetools_0.2-20 httpuv_1.6.15 htmltools_0.5.8.1
[25] usethis_2.2.3 class_7.3-22 later_1.3.2 pillar_1.9.0
[29] urlchecker_1.0.1 ellipsis_0.3.2 classInt_0.4-10 cachem_1.1.0
[33] sessioninfo_1.2.2 mime_0.12 tidyselect_1.2.1 digest_0.6.35
[37] stringi_1.8.4 purrr_1.0.2 rprojroot_2.0.4 fastmap_1.2.0
[41] grid_4.4.0 cli_3.6.2 magrittr_2.0.3 pkgbuild_1.4.4
[45] utf8_1.2.4 e1071_1.7-14 readr_2.1.5 promises_1.3.0
[49] sp_2.1-4 httr_1.4.7 rnaturalearthhires_1.0.0.9000 hms_1.1.3
[53] memoise_2.0.1 shiny_1.8.1.1 miniUI_0.1.1.1 profvis_0.3.8
[57] rlang_1.1.3 Rcpp_1.0.12 xtable_1.8-4 glue_1.7.0
[61] DBI_1.2.3 xml2_1.3.6 pkgload_1.3.4 rstudioapi_0.16.0
[65] jsonlite_1.8.8 R6_2.5.1 fs_1.6.4 units_0.8-5 — Reply to this email directly, view it on GitHub https://github.com/ropensci/FedData/issues/114, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7SSM4OQDEBWUOWC636CD3ZILWHTAVCNFSM6AAAAABJUFLUPOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3DINRZGAZDKNY. You are receiving this because you are subscribed to this thread.

bocinsky avatar Jul 01 '24 18:07 bocinsky

I also ran into the same problem. It used to work around May 2024. The sources for 2021 dataset may have changed because running the package example did not work either. Can you please check @bocinsky? Thank you!

get_nlcd(
  template = FedData::meve,
  label = "meve",
  year = 2021
)

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.factor': [rast] cannot open this file as a SpatRaster: C:\Users\user007\AppData\Local\Temp\RtmpO66bkW\filed2b45633e1c.tif In addition: Warning message: `C:\Users\user007\AppData\Local\Temp\RtmpO66bkW\filed2b45633e1c.tif' not recognized as a supported file format. (GDAL error 4)

tungttnguyen avatar Sep 16 '24 08:09 tungttnguyen

I am also having this issue. As @tungttnguyen suggested, this is specific to the 2021 data set. Calls to 2019 version still work.

edixon1 avatar Sep 20 '24 18:09 edixon1

I am having the same issue trying to get NLCD data for Alaska (2016).

get_refuge <- function(orgname){
  orgname <- toupper(orgname)
  message(paste("Downloading boundary layer for", orgname))
  url <- httr::parse_url("https://services.arcgis.com/QVENGdaPbd4LUkLV/arcgis/rest/services")
  url$path <- paste(url$path, "National_Wildlife_Refuge_System_Boundaries/FeatureServer/0/query", sep = "/")
  url$query <- list(where = paste("ORGNAME =", paste0("'",orgname,"'")),
                    outFields = "*",
                    returnGeometry = "true",
                    f = "pgeojson"
  )
  request <- httr::build_url(url)
  prop <- sf::st_read(request)
  message("Done.")
  return(prop)
}

tetlin <- get_refuge("Tetlin National Wildlife Refuge")

NLCD <- FedData::get_nlcd(template = tetlin,
                 landmass = "AK",
                 year = 2016,
                 label = "tetlin_nlcd")

mccrea-cobb avatar Sep 24 '24 00:09 mccrea-cobb

@mccrea-cobb I think there may be issues with a dependency. What has worked for me is to install v4.0.0.

devtools::install_version(
  "FedData", 
  version = "4.0.0", 
  repos = "http://cran.us.r-project.org"
)
library(FedData)

khurley-usgs avatar Oct 08 '24 13:10 khurley-usgs

@khurley-usgs I've been using FedData 4.0.0. I'm getting the same error message as @tungttnguyen. I'm able to get data for the lower 48.

mccrea-cobb avatar Oct 08 '24 15:10 mccrea-cobb

@khurley-usgs I've been using FedData 4.0.0. I'm getting the same error message as @tungttnguyen. I'm able to get data for the lower 48.

So you were able to get the 2021 data for the lower 48 using FedData 4.0.0? Thanks!

tungttnguyen avatar Oct 30 '24 14:10 tungttnguyen

@tungttnguyen I have been using v4.0.0 with success to download 2019 (still errors for 2021) NLCD for the Maryland area. However, MRLC just released their new LULC product that includes annual NLCD from 1985-2023 and I suspect there will be new changes to the API which would affect the FedData package.

Edit: At the moment FedData has been removed from CRAN because a dependency was removed. See issue #120

khurley-usgs avatar Oct 30 '24 15:10 khurley-usgs

Hi all. No clue what's going on with the 2021 legacy data. However, I've implemented the new annual NLCD product! See ?get_nlcd_annual(). Closing this now!

bocinsky avatar Nov 05 '24 16:11 bocinsky

Hi all. No clue what's going on with the 2021 legacy data. However, I've implemented the new annual NLCD product! See ?get_nlcd_annual(). Closing this now!

Thanks @bocinsky ! Can you update this page with the new function? https://docs.ropensci.org/FedData/articles/FedData.html#usgs-national-land-cover-dataset

tungttnguyen avatar Nov 14 '24 15:11 tungttnguyen