1

I currently have a raster with multi-bands.

> EVI.all
class       : RasterLayer 
band        : 1  (of  12  bands)
dimensions  : 771, 735, 566685  (nrow, ncol, ncell)
resolution  : 0.002245788, 0.002245788  (x, y)
extent      : 76.22654, 77.8772, 9.861256, 11.59276  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : E:\Data\EVI\MOD13Q1_EVI_AllYears.tif 
names       : MOD13Q1_EVI_AllYears

When I try to extract the values from each band, I am only getting the values of the first band. Any suggestions? Alternately I would like to get multiple rasters - one for each band.

See below:

e <-  raster::extract(EVI.all,trial)
> e
  [1] 2924.38889 2924.38889 3157.33333 3952.00000 3336.97222 4052.77778 3169.19444 4226.27778 3621.52778 2732.41667
 [11] 3695.94444 4306.08333 4306.08333 4136.55556 3695.94444 4484.30556 3494.05556 3494.05556 2032.00000 2032.00000
 [21] 3559.08333 2113.13889 1991.50000 4580.52778 4580.52778 2538.41667 4319.08333 3725.72222 3342.61111 3952.00000
 [31] 4473.05556 4473.05556 3503.63889 4106.33333  -56.80556  -56.80556  -56.80556 4120.36111 3342.61111 2922.44444
 [41] 3100.75000 3100.75000 4152.94444 4399.16667 4399.16667 4399.16667 4399.16667 4399.16667 4399.16667 4399.16667
 [51] 4399.16667 2405.08333 2405.08333 2924.38889 4310.52778 4293.22222 4237.13889 4237.13889 4237.13889 3180.02778
 [61] 4037.60000 3823.72222 3191.41667 3191.41667 3330.66667 3961.25000 3952.52778 2732.41667 2732.41667 4894.86111
 [71] 3156.52778 3156.52778 3156.52778 3156.52778 3156.52778 3278.13889 3278.13889 3278.13889 4794.66667 4530.25000
 [81] 4530.25000 4530.25000 4530.25000 2873.11111 3775.69444 2574.47222 2574.47222 3510.13889 2713.02778 4129.50000
 [91] 3130.11111 4987.25000 3098.25000 3663.02778 3521.02778 4285.11111 3225.80556 2311.11111 2311.11111 2337.00000
[101] 2460.13889 4058.44444 4019.41667 3357.08333 3960.83333 4539.58333 3336.00000 3336.00000 3336.00000 2239.50000
[111] 2239.50000  628.22222 3506.36111 3859.11111 3900.97222 3900.97222 3900.97222 3900.97222 3191.41667 4226.44444
[121] 3409.91667 3278.13889 4719.30556 3414.27778 3414.27778 2749.94444 2036.25000 3015.63889 2600.97222 3156.52778
[131] 4070.55556 4207.44444 4207.44444 4207.44444 2640.52778 2640.52778 2309.33333 2390.16667 2390.16667

closed as unclear what you're asking by Spacedman, xunilk, Jochen Schwarze, LaughU, whyzar Jan 22 at 14:10

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    The raster object that you are displaying is not multiband but, rather single band. Can you show us your code for reading the data? You should be using the raster::stack or raster::brick function to read your data. – Jeffrey Evans Jan 18 at 21:20
1

You need to open it using EVI.all = stack(), not raster(). Then, each band is located as a layer in the stack, so EVI.all[[1]] would call the first band (e.g. January) and EVI.all[[12]] would call the last (December).

-1

Use the following code:

library(raster)
# locate your EVI.all file 
path = '...\\EVI.all.tif'
# to get values of 1st band of EVI.all
EVI.all_1 = raster(path, band = 1)
values(EVI.all_1)
# to get values of 2nd band of EVI.all
EVI.all_2  = raster(path, band =2)
values(EVI.all_2) 
# and so on....

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