unsupervised classification of a raster in R: the layer-stack or part one.

In my last post I was explaining the usage of QGis to do a layerstack of a Landsat-scene. Due to the fact that further research and trying out resulted in frustration I decided to stick with a software I know well: R.
So download the needed layers here and open up your flavoured version of R (in my case RStudio).

What do we need is a package called raster


Now define the working directory where your ETM-bands are stored which is “ETM” in my case:


Let’s do the last step and create the stack using one line and store this raster object using a second line:

A=stack(c("p134r027_7dt20020722.SR.b01.tif","p134r027_7dt20020722.SR.b02.tif","p134r027_7dt20020722.SR.b03.tif","p134r027_7dt20020722.SR.b04.tif","p134r027_7dt20020722.SR.b05.tif", "p134r027_7dt20020722.SR.b07.tif"))
writeRaster(A, filename="merge.tif")
plotRGB(A, 3, 2, 1, stretch="hist")

That’s it. Easy, wasn’t it?

result of stack and plot of it
result of stack and plot of it (click to enlarge)

0 0 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newest Most Voted
Inline Feedbacks
View all comments
Erin Hodgess
Erin Hodgess
8 years ago

This is so great! How do you get the ETM bands and the tif files, please?


[…] the missing values problem of the non-covered areas of a landsat picture. First: get the data In the part one we have already described where to get the data. As the used dataset contains surface reflectance […]

Erin Hodgess
Erin Hodgess
8 years ago

Hello again! Did you use Windows or Linux/Ubuntu for this please?