Question

I want to create a subset of an image with four bands. Therefore I am using the crop function in R.

A<-raster("L8_stacked.tif")
subset<-extent(c(639451, 660104, 5469254, 5489566))
B<-crop(A,subset)

As a result I get a raster with only one band in the .tif file. Do I have to define other options to get a subset image with 4 bands?

Was it helpful?

Solution

As the others already pointed out in the comments, the raster() function returns a (single) RasterLayer object. If you want a multilayer raster object you need to use the stack() or brick() function load the image into R. I.e.:

A <- stack("L8_stacked.tif")

If you then apply your extent with the crop() function, the result should be a raster stack containing all the bands from the original image.

To learn more on the raster package, read this document.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top