I am trying to resample settlements raster layer to have the same no. of rows and columns as NDVI layer using this code in R.





Settlement_rprj <-projectRaster(Settlement, crs = '+proj=longlat')

Settlement_rsmpl=resample(Settlement_rprj, NDVI, "billinear")

But it keeps on giving me Error in .local(x, y, ...) : invalid method

> Settlement_rprj
class      : RasterLayer 
dimensions : 904, 1237, 1118248  (nrow, ncol, ncell)
resolution : 1000, 1000  (x, y)
extent     : 8088000, 9325000, 2682000, 3586000  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : memory
names      : settlement_reclass2_EU_reclasses 
values     : 1, 11  (min, max)

> Settlement_rsmpl=resample(Settlement_rprj, NDVI, "billinear")
Error in .local(x, y, ...) : invalid method
class      : RasterLayer 
dimensions : 838, 1049, 879062  (nrow, ncol, ncell)
resolution : 0.008980789, 0.008974054  (x, y)
extent     : 87.98699, 97.40784, 21.94033, 29.46059  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +no_defs 
source     : ndvi_studyarea.tif 
names      : ndvi_studyarea 
values     : -0.156, 0.9284  (min, max)

To run biomod2 I need to stack all the layers and for that all of them must have the same projection and same no. of Rows and Columns. but even after reprojecting them they don't have the same columns and rows. I am trying to resample them but it keep on giving me error in both R and ArcMap.

  • This is an R problem, not an RStudio problem - I've edited it.
    – Spacedman
    Jul 30 '21 at 16:55

It seems like projectRaster did not work as you intended. The extent in your example is still not in the same units. I tried to reproduce your problem with my own data and the code you provided also gave error messages (but differnt ones) for me. So, you might want to try out project and resample from {terra}, which worked for me.
"{terra} is very similar to the {raster} package; but can do more, is easier to use, and it is faster."

Settlement_rprj <-terra::project(Settlement, '+proj=longlat')
Settlement_rsmpl <- resample(Settlement_rprj, NDVI, method="bilinear")

There is no "billinear" method. It should be "bilinear".

Also, this is probably not a good approach

Settlement_rprj <-projectRaster(Settlement, crs = '+proj=longlat')
Settlement_rsmpl=resample(Settlement_rprj, NDVI, "billinear")

Instead, you could do

Settlement_rsmpl <- projectRaster(Settlement, NDVI)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.