#install.packages("raster")
#install.packages("sp")
#install.packages("rgdal")
library(raster)
## Loading required package: sp
library(sp)
library(rgdal)
## Please note that rgdal will be retired by the end of 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
##
## rgdal: version: 1.5-25, (SVN revision 1143)
## 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/mcra9/OneDrive/Documentos/R/win-library/4.1/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/mcra9/OneDrive/Documentos/R/win-library/4.1/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 sp or rgdal.
## Overwritten PROJ_LIB was C:/Users/mcra9/OneDrive/Documentos/R/win-library/4.1/rgdal/proj
#Llamar imagenes
b2 <- raster("C:/Users/Andres/LC08_L2SP_009058_20210807_20210818_02_T1_SR_B2.tif")
b3 <- raster("C:/Users/Andres/LC08_L2SP_009058_20210807_20210818_02_T1_SR_B3.tif")
b4 <- raster("C:/Users/Andres/LC08_L2SP_009058_20210807_20210818_02_T1_SR_B4.tif")
b5 <- raster("C:/Users/Andres/LC08_L2SP_009058_20210807_20210818_02_T1_SR_B5.tif")
#Rasterstack
s <- stack(b5,b4,b3,b2)
s
## class : RasterStack
## dimensions : 7741, 7601, 58839341, 4 (nrow, ncol, ncell, nlayers)
## resolution : 30, 30 (x, y)
## extent : 239385, 467415, 203385, 435615 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## names : LC08_L2SP_009058_20210807_20210818_02_T1_SR_B5, LC08_L2SP_009058_20210807_20210818_02_T1_SR_B4, LC08_L2SP_009058_20210807_20210818_02_T1_SR_B3, LC08_L2SP_009058_20210807_20210818_02_T1_SR_B2
## min values : 0, 0, 0, 0
## max values : 65535, 65535, 65535, 65535
#Plotear imagenes
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))
#Color verdadero
landsatRGB <- stack(b4,b3,b2)
plotRGB(landsatRGB, axes = TRUE, stretch = "lin", main = "Landsat True Color Composite ")