Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spariyar opened this issue Dec 12, 2021 · 2 comments
Open

Comments

@spariyar
Copy link

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.

@Nowosad
Copy link
Contributor

Nowosad commented Dec 12, 2021

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

@spariyar
Copy link
Author

@Nowosad thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants