discuss icon indicating copy to clipboard operation
discuss copied to clipboard

Get band number of maximum value per pixel for multiband raster in R?

Open spariyar opened this issue 4 years ago • 2 comments

I have a multiband raster stack and I want to find the band number of the maximum value for each pixel. For this, I have used the following code: #Set working directory setwd("E:/Red Panda/TIF") library(raster)

#Get the names of all the files with extension ".tif" of the folder files <- list.files("E:/Red Panda/TIF/", pattern='tif$', full.names=TRUE ) files Raster_stack <- stack(files) Raster_stack names(Raster_stack) plot(Raster_stack)

Identify pixel-wise band with max value

pixelMaxBand.ras <- whiches.max(Raster_stack)

But I found this type of error: Error in .local(x, ...) : you can use only use this function for an object with less than 10 layers

Generally, I have >10 raster layers for different land use and land cover but this “whiches.max” function works for layers less than 10. Can you please suggest me the appropriate code that can work for rasters >10? Thank you.

spariyar avatar Dec 12 '21 08:12 spariyar

Hi @spariyar -- you probably should rise this issue at https://github.com/rspatial/raster/issues.

Nowosad avatar Dec 12 '21 08:12 Nowosad

@Nowosad thank you so much.

spariyar avatar Dec 12 '21 09:12 spariyar