#ALUMNOS: #jhon jairo cuenca campos #angie dannielle cediel zabala

#install.packages("raster")
#install.packages("rgdal")
#install.packages("sp")

library(raster)
## Loading required package: sp
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/Jairo Cuenca/Documents/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/Jairo Cuenca/Documents/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/Jairo Cuenca/Documents/R/win-library/4.0/rgdal/proj
library(sp)
#blue
b2 <- raster("C:/Users/Jairo Cuenca/Desktop/10 - DECIMO SEMESTRE/GEOMATICA/DATOS 1/rs/LC08_044034_20170614_B2.tif")
#green
b3 <- raster("C:/Users/Jairo Cuenca/Desktop/10 - DECIMO SEMESTRE/GEOMATICA/DATOS 1/rs/LC08_044034_20170614_B3.tif")
#red
b4 <- raster("C:/Users/Jairo Cuenca/Desktop/10 - DECIMO SEMESTRE/GEOMATICA/DATOS 1/rs/LC08_044034_20170614_B4.tif")
# near infrared (NIR)
b5 <- raster("C:/Users/Jairo Cuenca/Desktop/10 - DECIMO SEMESTRE/GEOMATICA/DATOS 1/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:/Users/Jairo Cuenca/Desktop/10 - DECIMO SEMESTRE/GEOMATICA/DATOS 1/rs/LC08_044034_20170614_B2.tif 
## names      : LC08_044034_20170614_B2 
## values     : 0.0748399, 0.7177562  (min, max)
b3
## 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/Jairo Cuenca/Desktop/10 - DECIMO SEMESTRE/GEOMATICA/DATOS 1/rs/LC08_044034_20170614_B3.tif 
## names      : LC08_044034_20170614_B3 
## values     : 0.04259216, 0.6924697  (min, max)
b4
## 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/Jairo Cuenca/Desktop/10 - DECIMO SEMESTRE/GEOMATICA/DATOS 1/rs/LC08_044034_20170614_B4.tif 
## names      : LC08_044034_20170614_B4 
## values     : 0.02084067, 0.7861769  (min, max)
b5
## 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/Jairo Cuenca/Desktop/10 - DECIMO SEMESTRE/GEOMATICA/DATOS 1/rs/LC08_044034_20170614_B5.tif 
## names      : LC08_044034_20170614_B5 
## values     : 0.0008457669, 1.012432  (min, max)
#coordinate reference system (CRS)
crs(b2)
## CRS arguments:
##  +proj=utm +zone=10 +datum=WGS84 +units=m +no_defs
#number of cells, rows, colums
ncell(b2)
## [1] 1863765
dim(b2)
## [1] 1245 1497    1
#spatial resolucion
res(b2)
## [1] 30 30
#number of nads
nlayers(b2)
## [1] 1
compareRaster(b2,b3)
## [1] TRUE
s <- stack(b5, b4,b3)
#check the properties of the resterstack
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 (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")