Error in setValues : Std::bad_alloc when running the Aggregate function in a raster file

Asked

Viewed 391 times

1

While performing the Aggregate function to reduce the resolution of a raster file I am 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’m using is the R-3.4.3 installed on Opensuse Leap 42.3 64bits, on a laptop with i5 core processor and 8GB RAM.

  • 1

    Are you using Windows? Rstudio? How large is the object (object.size(dados))?This error seems to be associated with the memory allocation of very large files. Edit your question with parts of the data dput(head(dados)) so that we can test if your code is correct.

  • this coming from a comic the variable DEM, used attach()?

1 answer

1

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')

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.