###Instalar Paquetes
#install.packages("raster")
#install.packages("sp")
#install.packages("rgdal")
#Paquetes instalados
library(sp)
library(raster)
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-27, (SVN revision 1148)
## 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/ASUS/Documents/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/ASUS/Documents/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/ASUS/Documents/R/win-library/4.1/rgdal/proj
#Instalar los objetos a mis variables
b1 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b01.tif"); b1
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b01.tif
## names : facade_b01
## values : 0, 66 (min, max)
b2 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b02.tif"); b2
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b02.tif
## names : facade_b02
## values : 0, 66 (min, max)
b3 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b03.tif"); b3
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b03.tif
## names : facade_b03
## values : 0, 66 (min, max)
b4 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b04.tif"); b4
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b04.tif
## names : facade_b04
## values : 0, 66 (min, max)
b5 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b05.tif"); b5
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b05.tif
## names : facade_b05
## values : 0, 76 (min, max)
b6 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b06.tif"); b6
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b06.tif
## names : facade_b06
## values : 0, 78 (min, max)
b7 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b07.tif"); b7
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b07.tif
## names : facade_b07
## values : 0, 76 (min, max)
b8 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b08.tif"); b8
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b08.tif
## names : facade_b08
## values : 2, 50 (min, max)
b9 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b09.tif"); b9
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b09.tif
## names : facade_b09
## values : 3, 71 (min, max)
b10 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b10.tif"); b10
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b10.tif
## names : facade_b10
## values : 3, 79 (min, max)
b11 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b11.tif"); b11
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b11.tif
## names : facade_b11
## values : 3, 80 (min, max)
b12 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b12.tif"); b12
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b12.tif
## names : facade_b12
## values : 0, 43 (min, max)
b13 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b13.tif"); b13
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b13.tif
## names : facade_b13
## values : 0, 66 (min, max)
b14 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b14.tif"); b14
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b14.tif
## names : facade_b14
## values : 0, 66 (min, max)
b15 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b15.tif"); b15
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b15.tif
## names : facade_b15
## values : 1, 79 (min, max)
b16 <-raster("C:/Users/ASUS/Downloads/PRACTICA 4/FACADE/facade_b16.tif"); b16
## class : RasterLayer
## dimensions : 800, 1000, 8e+05 (nrow, ncol, ncell)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## source : facade_b16.tif
## names : facade_b16
## values : 1, 63 (min, max)
#Ploteo de bandas
plot(b1)
plot(b2)
plot(b4)
plot(b5)
plot(b6)
plot(b7)
plot(b8)
plot(b9)
plot(b10)
plot(b11)
plot(b12)
plot(b13)
plot(b14)
plot(b15)
plot(b16)
#Ploteo composicion a color verdadero
facade <-stack(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16)
facadeRGB <-stack(b16, b15, b14, b13, b12, b11, b10, b9, b8, b7, b6, b5, b4, b3, b2, b1)
plotRGB(facadeRGB, r = 3, g = 2, b = 1, axes = TRUE, stretch = "hist", main = "Facade True Color Composite")
#stack facade
recorte <-crop(facade, facadeRGB)
recorte
## class : RasterStack
## dimensions : 800, 1000, 8e+05, 16 (nrow, ncol, ncell, nlayers)
## resolution : 0.1, 0.1 (x, y)
## extent : 40000, 40100, 2e+05, 200080 (xmin, xmax, ymin, ymax)
## crs : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
## names : facade_b01, facade_b02, facade_b03, facade_b04, facade_b05, facade_b06, facade_b07, facade_b08, facade_b09, facade_b10, facade_b11, facade_b12, facade_b13, facade_b14, facade_b15, ...
## min values : 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 3, 0, 0, 0, 1, ...
## max values : 66, 66, 66, 66, 76, 78, 76, 50, 71, 79, 80, 43, 66, 66, 79, ...
#Renombrar las bandas
names(recorte) <- c("B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10", "B11", "B12", "B13", "B14", "B15", "B16")
#Integrar el Excel
library(readxl) # leer Excel
library(sf) #Manejar datos
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1
datos <- read_xlsx("C:/Users/ASUS/Downloads/PRACTICA 4/training.xlsx")
datos <- datos %>%
st_as_sf(coords = c("x", "y"))
datos
## Simple feature collection with 100 features and 1 field
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 40001 ymin: 200001 xmax: 40099 ymax: 200073
## CRS: NA
## # A tibble: 100 x 2
## class geometry
## <chr> <POINT>
## 1 gap (40030 200005)
## 2 gap (40079 200023)
## 3 gap (40079 200071)
## 4 gap (40012 200047)
## 5 gap (40012 200023)
## 6 gap (40025 200047)
## 7 gap (40025 200023)
## 8 gap (40049 200023)
## 9 gap (40049 200011)
## 10 gap (40060 200005)
## # ... with 90 more rows
plot(datos$geometry)
df <- extract(recorte, datos); df
## B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 B14 B15 B16
## [1,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 2
## [2,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 1
## [3,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 1
## [4,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 1
## [5,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 1
## [6,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 2
## [7,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 2
## [8,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 2
## [9,] 0 0 0 0 0 0 0 3 4 5 5 0 0 0 1 2
## [10,] 0 0 0 0 0 1 0 6 9 10 10 0 0 0 2 2
## [11,] 0 0 0 0 0 1 0 6 9 10 10 0 0 0 2 2
## [12,] 0 0 0 0 0 1 0 6 9 10 10 0 0 0 2 1
## [13,] 0 0 0 0 0 1 0 6 9 10 10 0 0 0 2 1
## [14,] 0 0 0 0 0 1 0 6 9 10 10 0 0 0 2 1
## [15,] 0 0 0 0 0 1 0 6 9 10 10 0 0 0 2 2
## [16,] 0 0 0 0 0 1 0 6 9 10 10 0 0 0 2 2
## [17,] 0 0 0 0 0 1 0 6 9 10 10 0 0 0 2 2
## [18,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 2
## [19,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 1
## [20,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 2
## [21,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 2
## [22,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 2
## [23,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 2
## [24,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 2
## [25,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 2
## [26,] 65 65 65 65 75 77 75 20 70 78 32 42 65 65 78 62
## [27,] 62 62 62 62 72 74 72 48 68 75 77 39 62 62 75 59
## [28,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [29,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [30,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [31,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [32,] 21 21 21 21 31 33 31 22 31 34 35 0 21 21 34 18
## [33,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [34,] 22 22 22 22 32 34 32 22 32 35 35 0 22 22 35 19
## [35,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [36,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [37,] 22 22 22 22 32 34 32 22 32 35 35 0 22 22 35 19
## [38,] 22 22 22 22 32 34 32 22 32 35 35 0 22 22 35 19
## [39,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [40,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [41,] 23 23 23 23 33 35 33 22 32 36 35 0 23 23 36 20
## [42,] 24 24 24 24 34 36 34 23 33 37 37 1 24 24 37 21
## [43,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [44,] 25 25 25 25 35 37 35 24 34 38 38 2 25 25 38 22
## [45,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [46,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [47,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [48,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [49,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [50,] 62 62 62 62 72 74 72 48 68 75 77 39 62 62 75 59
## [51,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [52,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [53,] 62 62 62 62 72 74 72 48 68 75 77 39 62 62 75 59
## [54,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [55,] 24 24 24 24 34 36 34 23 33 37 37 1 24 24 37 21
## [56,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [57,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [58,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [59,] 62 62 62 62 72 74 72 48 68 75 77 39 62 62 75 59
## [60,] 62 62 62 62 72 74 72 19 68 75 30 39 62 62 75 59
## [61,] 62 62 62 62 72 74 72 48 68 75 77 39 62 62 75 59
## [62,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [63,] 62 62 62 62 72 74 72 48 68 75 77 39 62 62 75 59
## [64,] 63 63 63 63 73 75 73 48 68 76 77 40 63 63 76 60
## [65,] 63 63 63 63 73 75 73 48 68 76 77 40 63 63 76 60
## [66,] 63 63 63 63 73 75 73 48 68 76 77 40 63 63 76 60
## [67,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [68,] 64 64 64 64 74 76 74 48 69 77 77 41 64 64 77 61
## [69,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [70,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [71,] 64 64 64 64 74 76 74 48 69 77 77 41 64 64 77 61
## [72,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [73,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [74,] 64 64 64 64 74 76 74 48 69 77 77 41 64 64 77 61
## [75,] 64 64 64 64 74 76 74 48 69 77 77 41 64 64 77 61
## [76,] 64 64 64 64 74 76 74 48 69 77 77 41 64 64 77 61
## [77,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [78,] 64 64 64 64 74 76 74 19 69 77 30 41 64 64 77 61
## [79,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [80,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [81,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [82,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [83,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [84,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [85,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [86,] 65 65 65 65 75 77 75 20 70 78 32 42 65 65 78 62
## [87,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [88,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [89,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [90,] 0 0 0 0 0 2 0 10 14 15 16 0 0 0 3 2
## [91,] 65 65 65 65 75 77 75 20 70 78 32 42 65 65 78 62
## [92,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [93,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [94,] 65 65 65 65 75 77 75 20 70 78 32 42 65 65 78 62
## [95,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [96,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [97,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [98,] 66 66 66 66 76 78 76 50 71 79 80 43 66 66 79 63
## [99,] 65 65 65 65 75 77 75 49 70 78 78 42 65 65 78 62
## [100,] 66 66 66 66 76 78 76 50 71 79 80 43 66 66 79 63
#Valores promedios cada banda
ms <- aggregate(df, list(datos$class), mean)
ms
## Group.1 B1 B2 B3 B4 B5 B6 B7
## 1 fissure 45.266667 45.266667 45.266667 45.266667 55.26667 57.26667 55.26667
## 2 gap 8.862069 8.862069 8.862069 8.862069 10.24138 11.34483 10.24138
## 3 wall 62.607143 62.607143 62.607143 62.607143 72.42857 74.42857 72.42857
## B8 B9 B10 B11 B12 B13 B14 B15
## 1 36.60000 52.40000 58.26667 58.26667 22.600000 45.266667 45.266667 58.26667
## 2 11.06897 17.17241 19.10345 17.86207 5.689655 8.862069 8.862069 12.34483
## 3 45.01786 67.94643 75.64286 71.82143 40.017857 62.607143 62.607143 75.42857
## B16
## 1 42.266667
## 2 9.896552
## 3 59.696429
#Pasar valores a Excel
#install.packages("writexl")
library(writexl)
#write_xlsx(ms, "C:/Users/ASUS/Downloads/PRACTICA 4/FINAL PRACTICA 04.xlsx" )
#PREGUNTAS ##1. ¿Cual es la resolucion espacial de las bandas? ### Respuesta: La resolucion espacial de las bandas B1 hasta la B16 es de x=0.1 , y=0.1
##2. ¿En cuales bandas la reflectancia es igual entre clases? ### Respuesta: En las bandas B1, B2, B3 Y B4
##3. ¿Cual banda da mejor resepuesta a cada clase? ### Respuesta: Las bandas B10, B11 Y B15
##4. Conclusiones ### Respuesta: Al observar la grafica final obtenida de valores promedios en Excel, se puede observar el alto porcentaje de fisuras en toda la fachada, se obtuvo un muy buen analisis de las caracteristicas de la fachada.