Error in setValues: std :: bad_alloc when executing the aggregate function in a raster file

0

When I run the aggregate function to reduce the resolution of a raster file I'm getting the error below,

Error in setValues(out, .Call("_raster_aggregate_fun", x, dims, as.integer(na.rm), : std::bad_alloc.

The command used was,

DEM2 <- aggregate(DEM, fact=2, fun=mean, expand=FALSE, na.rm=TRUE)

How to solve this?

The version I am using is R-3.4.3 installed on OpenSUSE Leap 42.3 64Bits, on a laptop with an i5 core processor and 8GB of RAM.

    
asked by anonymous 21.01.2018 / 23:34

1 answer

0

Another way without using the aggregate function is:

require(raster)

# criando um raster com dados aleatórios
r <- matrix(runif(100),nrow=10,ncol=10)
r <- raster(r)

# cria um raster com resolucao menor (aggregate)
r1 <- raster(nrow=dim(r)[1]/2, ncol=dim(r)[2]/2, ext=extent(r)) # resolucao diminui pela metade
r1 <- resample(r, r1, method="ngb") # ngb se os dados forem categoricos

r2 <- resample(r, r1, method="bilinear") # se os dados forem tipo gradiente


par(mfrow = c(3, 1))  # 3 linhas com um grafico cada
plot(r, main='raster original')
plot(r1, main='menor resolucao por ngb')
plot(r2, main='menor resolucao por bilinear')

    
05.04.2018 / 16:07