r-spatialecology/landscapemetrics

error in large Raster files

Closed this issue · 5 comments

Hello all
I have several raster files with the characteristics below, when I try to calculate any metrics (any level) returns error in memory (below example). Is there any alternative to calculating the metrics in large files like these? Some alternative to this problem would be very important.

Thank you in advance for your thoughts, they are very much appreciated!

Best Regards

Rodrigo Vasconcelos

############################################################
Ex.
aa='C:/Users/Mapbiomas/Desktop/CAATINGA/clip_geral_1985.tif'
kk=raster(aa)
calc.metrics=calculate_metrics(kk,what = "class")
Error: cannot allocate vector of size 6.3 Gb

*Raster proprities
class : RasterLayer
dimensions : 49368, 34377, 1697123736 (nrow, ncol, ncell)
resolution : 0.0002694957, 0.0002694969 (x, y)
extent : -44.43804, -35.17359, -16.08875, -2.784231 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : C:\Users\Mapbiomas\Desktop\CAATINGA\clip_geral_1985.tif
names : clip_geral_1985
values : 0, 255 (min, max)

Sorry I forgot to describe my machine. I have a laptop 16 GB RAM DDR4, I7
thanks
R.

Have you tried to change the maxmemory option? For example to:

setOptions(maxmemory = 1e+09)

Hi Rodrigo,

without your actual raster the error is quite hard to replicate.
From what it looks like you have too little memory on your machine (as your raster is indeed quite big) - plus landscapemetrics creates a second copy of your raster for each land cover class.

Some thoughts:

  • Are the 255 values actual land cover classes? Seems to me quite a lot - landscape metrics are meant for categorical landscapes, the 255 looks more like grey values?

  • Did you monitor your system before/while using the package? Maybe it's already sufficient to close your browser etc.

  • Does it run if you only calculate a single metric? If so, you could maybe make a selection of metrics that answer your question and combine them with dplyr::bind_rows()?

  • If all of the above do not make sense and you have some time, you could try rasterOptions(todisk = TRUE).

Any Progress @rnvuefsppgm ? If not, feel free to open again :)