| title: "EXPLORACION" |
LIBRERIA
library(terra)
## terra version 1.0.10
library(raster)
## Loading required package: sp
library(sp)
ENTORNO DE TRABAJO
ruta <- getwd()
carpeta <- 'Datos'
file <- paste0(ruta,'/',carpeta,'/','LC08_L1TP_009057_20140820_20200911_02_T1_B', 1:7, ".tif")
landsat <- rast(file)
names(landsat) <- c('ultra-blue','blue','green','red','NIR','SWIR1','SWIR2')
Recorte
xmx <- 374838
xmn <- 358682
ymx <- 467578
ymn <- 454847
ext(landsat)
## SpatExtent : 273585, 501315, 362985, 595515 (xmin, xmax, ymin, ymax)
e <- ext(xmn, xmx, ymn, ymx)
# crop landsat by the extent
landsatcrop <- crop(landsat, e)
UNA SOLA BANDA
par(mfrow = c(2,2))
plot(landsatcrop$blue, main = "Blue", col = rgb((0:100)/100, red = 0, green = 0))
plot(landsatcrop$green, main = "Green", col = rgb((0:100 / 100), red = 0, blue = 0))
plot(landsatcrop$red, main = "Red", col = rgb((0:100 / 100),green = 0, blue = 0))
plot(landsatcrop$NIR, main = "NIR", col = rgb((0:100 / 100), red = 1, green=0,blue=0))
Tres Bandas RGB color natural
landsatRGB <- c(landsat$red, landsat$green, landsat$blue)
# plot 3-band image
plotRGB(landsatRGB, axes = TRUE, stretch = "lin", main = "Landsat Composicion de color natural")
Falso Color
landsatNirRG <- c(landsat$NIR , landsat$red, landsat$green)
# plot 3-band image
plotRGB(landsatNirRG, axes = TRUE, stretch = "lin", main = "Landsat Composicion de Falso Color")
par(mfrow = c(1,2))
landsatcropRGB <- c(landsatcrop$red, landsatcrop$green, landsatcrop$blue)
landsatcropNirRG <- c(landsatcrop$NIR , landsatcrop$red, landsatcrop$green)
plotRGB(landsatcropRGB, axes = TRUE, stretch = "lin", main = "Landsat Color natural")
plotRGB(landsatcropNirRG, axes = TRUE, stretch = "lin", main = "Landsat Falso Color")
Guardar
writeRaster(landsatcropRGB, filename="cropRGB.tif", overwrite=TRUE)
## Warning: Deleting C:/Users/LENOVO/Desktop/11/RS/MyData/cropRGB.tif failed:
## Permission denied (GDAL error 1)
writeRaster(landsatcropNirRG, filename="cropNirRG.tif", overwrite=TRUE)
## Warning: Deleting C:/Users/LENOVO/Desktop/11/RS/MyData/cropNirRG.tif failed:
## Permission denied (GDAL error 1)
Comparar Bandas
pairs(landsatcrop[[1:2]], main = "Ultra-blue versus Blue")
pairs(landsatcrop[[4:5]], main = "Red versus NIR")
Extraer Valores de Pixeles
Lon <- c(xmx, xmx, xmn, xmn)
Lat <- c(ymx, ymn, ymn, ymx)
LonLat <- cbind(Lon, Lat)
df <- extract(landsat, LonLat)
head(df)
PUNTOS DE PERFIL ESPECTRAL
######puntos#######
rio <- extract(landsat, cbind(363723, 465125))
urbano <- extract(landsat, cbind(371717,465452))
cultivo <- extract(landsat, cbind(365893, 466383))
descubierto <-extract(landsat, cbind(364866, 466383))
montana <-extract(landsat, cbind(372434, 463455))
######matriz#######
pt <- rbind(rio,urbano,cultivo,descubierto,montana)
pt$head <- c('rio','urbano','cultivo','descubierto','montana')
rownames(pt) <- pt[,8]
pt <- pt[,-8]
pt
PERFIL ESPECTRAL
Colores <- c('Blue', 'gray', 'green', 'yellow','brown')
pt <- as.matrix(pt)
plot(0, ylim=c(0,26000), xlim = c(1,7), type='n', xlab="Bandas", ylab = "Reflectancia")
for (i in 1:nrow(pt)){
lines(pt[i,], type = "l", lwd = 3, lty = 1, col = Colores[i])
}
# Title
title(main="Perfil Espectral", font.main = 2)
# Legend
legend("topleft", rownames(pt),
cex=0.8, col=Colores, lty = 1, lwd =3, bty = "n")