r-spatialecology / landscapemetrics

Landscape Metrics for Categorical Map Patterns 🗺️ in R
https://r-spatialecology.github.io/landscapemetrics
GNU General Public License v3.0
231 stars 43 forks source link

Error with check_landscape() #253

Closed zlkvet closed 2 years ago

zlkvet commented 2 years ago

I am reading in my raster file with the raster() function and it plots fine. When I go to use the check_landscape() I get the error below. Can someone help me figure out what this means or how to correct it? I have tried a few different raster .tif files and get the same error. Thanks.

Error in array(dim = as.integer(c(rev(output.dim), length(band)))) : too many elements specified

mhesselbarth commented 2 years ago

Any chance to share the raster with us? Very hard to debug without the data...

zlkvet commented 2 years ago

I think it is too big to upload here.. is there another way to share it? Thanks.

mhesselbarth commented 2 years ago

Either use any cloud sharing service and post the link here (Dropbox, Google Drive, etc.) or send per mail to mhk.hesselbarth\<at>gmail.com.

zlkvet commented 2 years ago

https://drive.google.com/drive/folders/1eT35QBvagTVAfgpIubrb-SsRGx6BbfqL?usp=sharing

mhesselbarth commented 2 years ago

The original raster is too big and the values cannot be stored in the RAM (at least on my computer). Thus, landscapemetrics wont be able to calculate any metrics anyhow.

If you subset just one state, check_lsm() works for me...

library(landscapemetrics)
library(raster)
library(rnaturalearth)
library(sf)
library(dplyr)

ras <- raster::raster("~/Downloads/NLCD.tif")

iowa <- rnaturalearth::ne_states(country = "United States of America", return = "sf") %>% 
    dplyr::filter(name == "Iowa") %>% 
    sf::st_transform(crs = raster::crs(ras))

ras_crop <- raster::crop(x = ras, y = iowa)
check_landscape(ras_crop)
#> Warning: Caution: More than 30 land cover-classes - Please check if discrete
#> land-cover classes are present.
#>   layer       crs units   class n_classes OK
#> 1     1 projected     m integer        62  ?⃝

Created on 2022-03-09 by the reprex package (v2.0.1)

mhesselbarth commented 2 years ago

I will close this for now, since I don't think we can change the code at the moment. Raster must be held in the memory for all calculations. Please re-open if you have further questions.