CREACION DEL RASTER
rm(list=ls())
install.packages("raster")
library(raster)
CREACION DEM
dem <- raster(ncol=3, nrow=3, xmn=100, xmx=115, ymn=100, ymx=115)
QUEREMOS SABER EL NUMERO DE CELDAS QUE COMPONEN EL DEM
ncell(dem)
[1] 9
QUEREMOS SABER LA RESOLUCION O TAMAÑO DE LA CELDA
res(dem)
[1] 5 5
ASIGNAMOS VALORES DE ELEVAVACION
valores <- c(50, 45, 50, 30, 30, 30, 8, 10, 10)
LE PEDIMOS QUE NOS DIGA QUE VALORES HAY ALLI
(values(dem) <- valores)
[1] 50 45 50 30 30 30 8 10 10
TRASAMOS EL DEM A LO LARGO DE LOS VALORES
plot(dem, main = "DEM")
text(dem)
LE ASIGNAMOS UN SISTEMA DE CORDENADAS AL DEM
crs(dem) <- CRS('+init=epsg:3115')
CALCULAMOS PENDIENTE
(slope = terrain(dem, 'slope', unit='degrees', neighbors=8))
class : RasterLayer
dimensions : 3, 3, 9 (nrow, ncol, ncell)
resolution : 5, 5 (x, y)
extent : 100, 115, 100, 115 (xmin, xmax, ymin, ymax)
crs : +init=epsg:3115
source : memory
names : slope
values : 75.25766, 75.25766 (min, max)
GRAFICAMOS PENDIENTE
plot(slope, main = "Pendiente")
text(slope)
CALCULAMOS ASPECTO
(aspecto = terrain(dem, 'aspect', unit='degrees', neighbors=8))
class : RasterLayer
dimensions : 3, 3, 9 (nrow, ncol, ncell)
resolution : 5, 5 (x, y)
extent : 100, 115, 100, 115 (xmin, xmax, ymin, ymax)
crs : +init=epsg:3115
source : memory
names : aspect
values : 180.7538, 180.7538 (min, max)
GRAFICAMOS ASPECTO
plot(aspecto, main = "Aspecto")
text(aspecto)
EJERCICIO: Escriba el código R para calcular la pendiente y el aspecto para el siguiente DEM
CREAMOS EL DEM
demARTURO<- raster(ncol=4, nrow=4, xmn=100, xmx=120, ymn=100, ymx=120)
QUEREMOS SABER EL NUMERO DE CELDAS QUE COMPONEN EL DEM
ncell(demARTURO)
[1] 16
QUEREMOS SABER LA RESOLUCION O TAMAÑO DE LA CELDA
res(demARTURO)
[1] 5 5
ASIGNAMOS VALORES DE ELEVAVACION
valoresARTURO <- c(50, 45, 50, 48,30, 29, 30, 29, 10, 9, 9, 10, 25, 23, 19, 21)
LE PEDIMOS QUE NOS DIGA QUE VALORES HAY ALLI
(values(demARTURO) <- valoresARTURO)
[1] 50 45 50 48 30 29 30 29 10 9 9 10 25 23 19 21
TRASAMOS EL DEM A LO LARGO DE LOS VALORES
plot(demARTURO, main = "DEM")
text(demARTURO)
LE ASIGNAMOS UN SISTEMA DE CORDENADAS AL DEM
crs(demARTURO) <- CRS('+init=epsg:3115')
CALCULAMOS PENDIENTE
(slopeARTURO = terrain(demARTURO, 'slope', unit='degrees', neighbors=8))
class : RasterLayer
dimensions : 4, 4, 16 (nrow, ncol, ncell)
resolution : 5, 5 (x, y)
extent : 100, 120, 100, 120 (xmin, xmax, ymin, ymax)
crs : +init=epsg:3115
source : memory
names : slope
values : 36.05503, 75.62313 (min, max)
GRAFICAMOS LA PENDIENTE
plot(slopeARTURO, main = "PENDIENTE")
text(slopeARTURO)
CALCUAMOS ASPECTO
(aspectoARTURO = terrain(demARTURO, 'aspect', unit ='degrees' , neighbors=8))
class : RasterLayer
dimensions : 4, 4, 16 (nrow, ncol, ncell)
resolution : 5, 5 (x, y)
extent : 100, 120, 100, 120 (xmin, xmax, ymin, ymax)
crs : +init=epsg:3115
source : memory
names : aspect
values : 164.0546, 181.4688 (min, max)
GRAFICAMOS ASPETO
plot(aspectoARTURO, main="ASPECTO")
text(aspectoARTURO)