#install.packages("raster")


library(raster)
## Loading required package: sp
#Ultra-Blue
b1 <- raster('C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B1.tif')
#Blue
b2 <- raster('C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B2.tif')
#Green
b3 <- raster('C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B3.tif')
#Red
b4 <- raster('C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B4.tif')
#Near Infrared (NIR)
b5 <- raster('C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B5.tif')
#Swir1
b6 <- raster('C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B6.tif')
#Swir2
b7 <- raster('C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B7.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:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B2.tif 
## names      : LC08_044034_20170614_B2 
## values     : 0.0748399, 0.7177562  (min, max)
#install.packages("rgdal")

library(rgdal)
## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/jose_/OneDrive/Documentos/R/win-library/4.0/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/jose_/OneDrive/Documentos/R/win-library/4.0/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/jose_/OneDrive/Documentos/R/win-library/4.0/rgdal/proj
# coordinate reference system (CRS)
crs(b2)
## CRS arguments:
##  +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
ncell(b2)
## [1] 1863765
dim(b2)
## [1] 1245 1497    1
res(b2)
## [1] 30 30
nlayers(b2)
## [1] 1
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
par(mfrow = c(2,2))
plot(b1, main = "Ultra-Blue", col = gray(0:100/ 100))
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))
plot(b6, main = "SWIR1", col = gray(0:100/ 100))
plot(b7, main = "SWIR2", col = gray(0:100/ 100))

landsatRGB <- stack(b4, b3, b2)
plotRGB(landsatRGB, axes = TRUE, stretch = "lin", main = "landsat true color composite")

#install.packages("contrib.ur")
par(mfrow = c(1,2))
plotRGB(landsatRGB, axes=TRUE, stretch="lin", main="Landsat True Color Composite")
landsatFCC <- stack(b5, b4, b3)
plotRGB(landsatFCC, axes=TRUE, stretch="lin", main="Landsat False Color Composite")

filenames <- paste0('C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B', 1:11,".tif")
filenames
##  [1] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B1.tif" 
##  [2] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B2.tif" 
##  [3] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B3.tif" 
##  [4] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B4.tif" 
##  [5] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B5.tif" 
##  [6] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B6.tif" 
##  [7] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B7.tif" 
##  [8] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B8.tif" 
##  [9] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B9.tif" 
## [10] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B10.tif"
## [11] "C:/Users/jose_/Desktop/2021-1/ELECTIVA_2/TRABAJO#3/rs/LC08_044034_20170614_B11.tif"
landsat <- stack(filenames)
landsat
## class      : RasterStack 
## dimensions : 1245, 1497, 1863765, 11  (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_B1, LC08_044034_20170614_B2, LC08_044034_20170614_B3, LC08_044034_20170614_B4, LC08_044034_20170614_B5, LC08_044034_20170614_B6, LC08_044034_20170614_B7, LC08_044034_20170614_B8, LC08_044034_20170614_B9, LC08_044034_20170614_B10, LC08_044034_20170614_B11 
## min values :            9.641791e-02,            7.483990e-02,            4.259216e-02,            2.084067e-02,            8.457669e-04,           -7.872183e-03,           -5.052945e-03,            3.931751e-02,           -4.337332e-04,             2.897978e+02,             2.885000e+02 
## max values :              0.73462820,              0.71775615,              0.69246972,              0.78617686,              1.01243150,              1.04320455,              1.11793602,              0.82673049,              0.03547901,             322.43139648,             317.99530029
 landsat <- subset(landsat, 1:7)
names(landsat)
## [1] "LC08_044034_20170614_B1" "LC08_044034_20170614_B2"
## [3] "LC08_044034_20170614_B3" "LC08_044034_20170614_B4"
## [5] "LC08_044034_20170614_B5" "LC08_044034_20170614_B6"
## [7] "LC08_044034_20170614_B7"
names(landsat) <- c('ultra-blue', 'blue', 'green', 'red', 'NIR', 'SWIR1', 'SWIR2')
names(landsat)
## [1] "ultra.blue" "blue"       "green"      "red"        "NIR"       
## [6] "SWIR1"      "SWIR2"
#Using extent
extent(landsat)
## class      : Extent 
## xmin       : 594090 
## xmax       : 639000 
## ymin       : 4190190 
## ymax       : 4227540
e <- extent(624887, 635752, 4200047, 4210939)
# crop landsat by the extent
landsatcrop <- crop(landsat, e)
x <- writeRaster(landsatcrop, filename="cropped-landsat.tif", overwrite=TRUE)
pairs(landsatcrop[[1:2]], main = "ultra-blue versus blue")

pairs(landsatcrop[[4:5]], main = "Red versus NIR")

pairs(landsatcrop[[6:7]], main = "SWIR1 versus SWIR2")

pairs(landsatcrop[[2:3]], main = "blue versus green")

par(mfrow = c(1,2))
plotRGB(landsatRGB, axes=TRUE, stretch="lin", main="Landsat True Color Composite")
landsatFCC432 <- stack(b4, b3, b2)
plotRGB(landsatFCC432, axes=TRUE, stretch="lin", main="Landsat False Color Composite")

par(mfrow = c(1,2))
plotRGB(landsatRGB, axes=TRUE, stretch="lin", main="Landsat True Color Composite")
landsatFCC764 <- stack(b7, b6, b4)
plotRGB(landsatFCC764, axes=TRUE, stretch="lin", main="Landsat False Color Composite")

par(mfrow = c(1,2))
plotRGB(landsatRGB, axes=TRUE, stretch="lin", main="Landsat True Color Composite")
landsatFCC543 <- stack(b5, b4, b3)
plotRGB(landsatFCC543, axes=TRUE, stretch="lin", main="Landsat False Color Composite")

par(mfrow = c(1,2))
plotRGB(landsatRGB, axes=TRUE, stretch="lin", main="Landsat True Color Composite")
landsatFCC652 <- stack(b6, b5, b2)
plotRGB(landsatFCC652, axes=TRUE, stretch="lin", main="Landsat False Color Composite")

par(mfrow = c(1,2))
plotRGB(landsatRGB, axes=TRUE, stretch="lin", main="Landsat True Color Composite")
landsatFCC765 <- stack(b7, b6, b5)
plotRGB(landsatFCC765, axes=TRUE, stretch="lin", main="Landsat False Color Composite")

par(mfrow = c(1,2))
plotRGB(landsatRGB, axes=TRUE, stretch="lin", main="Landsat True Color Composite")
landsatFCC564 <- stack(b5, b6, b4)
plotRGB(landsatFCC564, axes=TRUE, stretch="lin", main="Landsat False Color Composite")

par(mfrow = c(1,2))
plotRGB(landsatRGB, axes=TRUE, stretch="lin", main="Landsat True Color Composite")
landsatFCC753 <- stack(b7, b5, b3)
plotRGB(landsatFCC753, axes=TRUE, stretch="lin", main="Landsat False Color Composite")

En conclucion

se nota la diferencia de cada imagen pues me gio por el titulo de cada una y se nota la diferencia y observo sus colores densos y suabes

Falso color (urbano) 764

Color infrarrojo(vegetacion) 543

Agricultura 652

Penetracion atmosferica 765

Tierra/Agua 564

Natural con remocion atmosferica 753