r-spatial / stars

Spatiotemporal Arrays, Raster and Vector Data Cubes
https://r-spatial.github.io/stars/
Apache License 2.0
563 stars 94 forks source link

Issues with particular file: North American Land Cover (NALC) Dataset #675

Closed 1johnreaves closed 7 months ago

1johnreaves commented 8 months ago

The dataset in question is a raster dataset of land cover in the United States. It's linked from the MRLC, but for consistency, the specific download that I've used is from here (http://www.cec.org/north-american-environmental-atlas/land-cover-30m-2020/), and is the TIF button at the bottom of the page. Be warned, the download is 3.7gb.

I unzipped the contents of the folder and tried to open them with the stars package:

landCover <- read_stars('Land Data/usa_land_cover/NA_NALCMS_landcover_2020_30m.tif')

at which point it "loads" (via a proxy) in memory. The landCover object instantiates just fine. But when I try to use the proxy that stars automatically creates to plot anything (say, plot(landCover)), or specify not to use a proxy, or anything else, I get the following error:

downsample set to 218
Error in read_stars(file_name, RasterIO = rasterio, NA_value = attr(x,  : 
  object 'which.column' not found

I'm not sure what to make of this error. Running traceback() following the error yields the following:

8: read_stars(file_name, RasterIO = rasterio, NA_value = attr(x, 
   "NA_value") %||% NA_real_, normalize_path = FALSE, proxy = FALSE, 
   ...)
7: fetch(.x, ..., downsample = downsample)
6: process_call_list(fetch(.x, ..., downsample = downsample), cl, 
       envir = envir, downsample = downsample)
5: st_as_stars.stars_proxy(x, downsample = downsample, ...)
4: st_as_stars(x, downsample = downsample, ...)
3: plot(st_as_stars(x, downsample = downsample, ...), ..., downsample = 0)
2: plot.stars_proxy(landCover)
1: plot(landCover)

To see if the file was the problem, I opened it in ArcGIS Pro, which successfully displayed the raster. (It said that it'd need to process something on first import, but I didn't take note of what that was.) I tried exporting the open raster to a new .tif file, multiple times, with no luck. The terra package is able to open the raster all right, and displays it as well with plot().

I have also re-downloaded the same dataset, from the same link, on the off chance that the file was corrupted on initial download. It was not. (New file also opens just fine in Arc, and with terra.) The same issue persists when accessing this file through Google Earth Engine and the rgee package, and yields an identical error.

My session info is below for completeness:

R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

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/New_York
tzcode source: internal

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

other attached packages:
[1] stars_0.6-4 sf_1.0-15   abind_1.4-5 dplyr_1.1.4

loaded via a namespace (and not attached):
 [1] Matrix_1.6-5       jsonlite_1.8.8     compiler_4.3.3     crayon_1.5.2       maps_3.4.2         tidyselect_1.2.1  
 [7] Rcpp_1.0.12        parallel_4.3.3     png_0.1-8          reticulate_1.35.0  lattice_0.22-5     R6_2.5.1          
[13] generics_0.1.3     classInt_0.4-10    tibble_3.2.1       units_0.8-5        DBI_1.2.2          pillar_1.9.0      
[19] rlang_1.1.3        utf8_1.2.4         sp_2.1-3           terra_1.7-71       cli_3.6.2          magrittr_2.0.3    
[25] ps_1.7.6           class_7.3-22       grid_4.3.3         processx_3.8.3     rstudioapi_0.15.0  lifecycle_1.0.4   
[31] rgee_1.1.7         vctrs_0.6.5        KernSmooth_2.23-22 proxy_0.4-27       glue_1.7.0         raster_3.6-26     
[37] codetools_0.2-19   fansi_1.0.6        e1071_1.7-14       tools_4.3.3        pkgconfig_2.0.3 
1johnreaves commented 8 months ago

I should note that while I can try to make things work in terra, I'm not very proficient when working with rasters, and I'm more familiar with sf; I appreciate the integration that stars has with that package. If I'm able to extract data from this dataset somehow, that's good enough for me, but this seemed like a bug-worthy report given the context. Hopefully I'm not just missing something!

edzer commented 8 months ago

On plot(landCover) I get this

x

what does sf_extSoftVersion() give?

1johnreaves commented 7 months ago

sf_extSoftVersion() yields:

      GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H           PROJ 
  "3.11.2"        "3.7.2"        "9.3.0"         "true"         "true"        "9.3.0" 
edzer commented 7 months ago

Could you try again after installing stars dev, using

devtools::install_github("r-spatial/stars")

??

1johnreaves commented 7 months ago

Now it works! Thank you!