rm(list=ls())
Primero vamos a llemar a la librería
library(raster)
## Loading required package: sp
dem <- raster(ncol=4, nrow=4, xmn=100, xmx=120, ymn=100, ymx=120)
ncell(dem)
## [1] 16
res(dem)
## [1] 5 5
valores <- c(50, 45, 50, 48, 30, 29, 30, 29, 10, 9, 9, 10, 25, 23, 19, 21)
(values(dem) <- valores)
## [1] 50 45 50 48 30 29 30 29 10 9 9 10 25 23 19 21
plot(dem, main = "DEM")
text(dem)
crs(dem) <- CRS('+init=epsg:3115')
(slope = terrain(dem, '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 +proj=tmerc +lat_0=4.596200416666666 +lon_0=-77.07750791666666 +k=1 +x_0=1000000 +y_0=1000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
## source : memory
## names : slope
## values : 36.05503, 75.62313 (min, max)
plot(slope, main = "Pendiente")
text(slope)
(aspecto = terrain(dem, '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 +proj=tmerc +lat_0=4.596200416666666 +lon_0=-77.07750791666666 +k=1 +x_0=1000000 +y_0=1000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
## source : memory
## names : aspect
## values : 164.0546, 181.4688 (min, max)
plot(aspecto, main = "Aspecto")
text(aspecto)