library(raster)
## Loading required package: sp
#Blue
b2 <- raster('C:/PRACTOCA #3/rs/LC08_044034_20170614_B2.tif')
#Green
b3 <- raster('C:/PRACTOCA #3/rs/LC08_044034_20170614_B3.tif')
#Red
b4 <- raster('C:/PRACTOCA #3/rs/LC08_044034_20170614_B4.tif')
#Near Infrared (NIR)
b5 <- raster('C:/PRACTOCA #3/rs/LC08_044034_20170614_B5.tif')
b2
## class : RasterLayer
## dimensions : 1245, 1497, 1863765 (nrow, ncol, ncell)
## resolution : 30, 30 (x, y)
## extent : 594090, 639000, 4190190, 4227540 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
## source : C:/PRACTOCA #3/rs/LC08_044034_20170614_B2.tif
## names : LC08_044034_20170614_B2
## values : 0.0748399, 0.7177562 (min, max)
## class : RasterLayer
## dimensions : 1245, 1497, 1863765 (nrow, ncol, ncell)
## resolution : 30, 30 (x, y)
## extent : 594090, 639000, 4190190, 4227540 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
## source : C:/PRACTOCA #3/rs/LC08_044034_20170614_B2.tif
## names : LC08_044034_20170614_B2
## values : 0.0748399, 0.7177562 (min, max)
# coordinate reference system (crs)
crs(b2)
## CRS arguments:
## +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
## CRS arguments:
## +proj=utm +zone=10 +datum=WGS84 +units=m
## +no_defs
# Number of cells, row, columns
ncell(b2)
## [1] 1863765
## [1] 1863765
dim(b2)
## [1] 1245 1497 1
## [1] 1245 1497 1
# spatial resolution
res(b2)
## [1] 30 30
## [1] 30 30
# Number of bands
nlayers(b2)
## [1] 1
## [1] 1
# Do the bands have the same extent, number of rows and columns, projection, resolution, and origin
compareRaster(b2,b3)
## [1] TRUE
## [1] TRUE
s <- stack(b5, b4, b3)
# Check the properties of the RasterStack
s
## class : RasterStack
## dimensions : 1245, 1497, 1863765, 3 (nrow, ncol, ncell, nlayers)
## resolution : 30, 30 (x, y)
## extent : 594090, 639000, 4190190, 4227540 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
## names : LC08_044034_20170614_B5, LC08_044034_20170614_B4, LC08_044034_20170614_B3
## min values : 0.0008457669, 0.0208406653, 0.0425921641
## max values : 1.0124315, 0.7861769, 0.6924697
## class : RasterStack
## dimensions : 1245, 1497, 1863765, 3 (nrow, ncol, ncell, nlayers)
## resolution : 30, 30 (x, y)
## extent : 594090, 639000, 4190190, 4227540 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
## names : LC08_044034_20170614_B5, LC08_044034_20170614_B4, LC08_044034_20170614_B3
## min values : 0.0008457669, 0.0208406653, 0.0425921641
## max values : 1.0124315, 0.7861769, 0.6924697
par(mfrow = c(2,2))
plot(b2, main = "Blue", col = gray(0:100/100))
plot(b3, main = "Green", col = gray(0:100/100))
plot(b4, main = "Red", col = gray(0:100/100))
plot(b5, main = "NIR", col = gray(0:100/100))

landsatRGB <- stack(b4, b3, b2)
plotRGB(landsatRGB,axes = TRUE, stretch = "lin", main = "Landsat True Color Composite")
