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

install.packages("raster")
library("raster")

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

setwd("~/wd_r/ETM")

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 (click to enlarge)

5
Leave a Reply

avatar
3 Comment threads
2 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
unsupervised classification of a Landsat image in R: the whole story or part two « Cartography « geo-affinericckliErin Hodgess Recent comment authors

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

  Subscribe  
newest oldest most voted
Notify of
Erin Hodgess
Guest
Erin Hodgess

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

trackback

[…] 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
Guest
Erin Hodgess

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