library(rasterVis)
Loading required package: raster
Loading required package: sp
Loading required package: lattice
Loading required package: latticeExtra
library(raster)
library(rgl)
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
library(rgdal)
rgdal: version: 1.4-8, (SVN revision 845)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/oaparicio15/Documents/R/win-library/3.6/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/oaparicio15/Documents/R/win-library/3.6/rgdal/proj
Linking to sp version: 1.4-1
#####Revisemos el contenido de la carpeta:
list.files("C:/Users/oaparicio15/Desktop/QGIS/ColombiaDatos/50_META/ADMINISTRATIVO")
[1] "MGN_DPTO_POLITICO.cpg"
[2] "MGN_DPTO_POLITICO.dbf"
[3] "MGN_DPTO_POLITICO.prj"
[4] "MGN_DPTO_POLITICO.sbn"
[5] "MGN_DPTO_POLITICO.sbx"
[6] "MGN_DPTO_POLITICO.shp"
[7] "MGN_DPTO_POLITICO.shp.DG_EST118.1768.8604.sr.lock"
[8] "MGN_DPTO_POLITICO.shp.xml"
[9] "MGN_DPTO_POLITICO.shx"
[10] "MGN_MPIO_POLITICO.cpg"
[11] "MGN_MPIO_POLITICO.dbf"
[12] "MGN_MPIO_POLITICO.prj"
[13] "MGN_MPIO_POLITICO.sbn"
[14] "MGN_MPIO_POLITICO.sbx"
[15] "MGN_MPIO_POLITICO.shp"
[16] "MGN_MPIO_POLITICO.shp.DG_EST118.1768.8604.sr.lock"
[17] "MGN_MPIO_POLITICO.shp.xml"
[18] "MGN_MPIO_POLITICO.shx"
#elevation <- get_elev_raster(vila, z = 8)
elevation <- get_elev_raster(villa, z = 8)
Downloading DEMs [========>------------------] 33% eta: 2s
Downloading DEMs [=============>-------------] 50% eta: 3s
Downloading DEMs [=================>---------] 67% eta: 2s
Downloading DEMs [=====================>-----] 83% eta: 1s
Downloading DEMs [===========================] 100% eta: 0s
Merging DEMs
Reprojecting DEM to original projection
ning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -InfNote: Elevation units are in meters.
Note: The coordinate reference system is:
+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
#elevation <- raster("./dem/elev_z8.tif")
elevation
class : RasterLayer
dimensions : 1546, 1033, 1597018 (nrow, ncol, ncell)
resolution : 0.00275, 0.00274 (x, y)
extent : -74.545, -71.70425, 1.393646, 5.629686 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
source : memory
names : layer
values : -1.570384, 4150.449 (min, max)
writeRaster(elevation, filename="C:/Users/oaparicio15/Documents/R/win-library/3.6/elevatr", datatype='INT4S', overwrite=TRUE)
class : RasterLayer
dimensions : 1546, 1033, 1597018 (nrow, ncol, ncell)
resolution : 0.00275, 0.00274 (x, y)
extent : -74.545, -71.70425, 1.393646, 5.629686 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
source : C:/Users/oaparicio15/Documents/R/win-library/3.6/elevatr.grd
names : layer
values : -2, 4150 (min, max)
elev_crop
class : RasterLayer
dimensions : 129, 216, 27864 (nrow, ncol, ncell)
resolution : 0.00275, 0.00274 (x, y)
extent : -73.7695, -73.1755, 3.936366, 4.289826 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
source : memory
names : layer
values : 203.7742, 3577.458 (min, max)
#####Cuando se trabaja con DEM, siempre es una buena idea usar coordenadas de mapa en lugar de coordenadas geográficas. Esto se debe al hecho de que, en coordenadas geográficas, las unidades de dimensiones horizontales son grados decimales, PERO la unidad de dimensión vertical es metros. Vuelva a proyectar los datos de elevación.
pr3 = projectExtent(elev_crop, spatialref)
res(pr3) = 100
rep_elev = projectRaster(elev_crop, pr3)
ning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Inf
rep_elev
class : RasterLayer
dimensions : 391, 660, 258060 (nrow, ncol, ncell)
resolution : 100, 100 (x, y)
extent : 1034192, 1100192, 927079.8, 966179.8 (xmin, xmax, ymin, ymax)
crs : +proj=tmerc +lat_0=4.596200416666666 +lon_0=-74.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 : layer
values : 201.3911, 3585.355 (min, max)
(rep_villa = spTransform(villa,spatialref))
class : SpatialPolygonsDataFrame
features : 1
extent : 1034342, 1100224, 926940.8, 965985.1 (xmin, xmax, ymin, ymax)
crs : +proj=tmerc +lat_0=4.596200416666666 +lon_0=-74.07750791666666 +k=1 +x_0=1000000 +y_0=1000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
variables : 9
names : DPTO_CCDGO, MPIO_CCDGO, MPIO_CNMBR, MPIO_CRSLC, MPIO_NAREA, MPIO_NANO, DPTO_CNMBR, Shape_Leng, Shape_Area
value : 50, 50001, VILLAVICENCIO, 1840, 1285.93087074, 2017, META, 2.03977418027, 0.104718109413
writeRaster(rep_elev, filename = "C:/Users/oaparicio15/Desktop/Rstudio/rep_villa_elev", dataType='INT4S', overwrite=TRUE)
argument "datatype" misspelled as "dataType"
class : RasterLayer
dimensions : 391, 660, 258060 (nrow, ncol, ncell)
resolution : 100, 100 (x, y)
extent : 1034192, 1100192, 927079.8, 966179.8 (xmin, xmax, ymin, ymax)
crs : +proj=tmerc +lat_0=4.596200416666666 +lon_0=-74.07750791666666 +k=1 +x_0=1000000 +y_0=1000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
source : C:/Users/oaparicio15/Desktop/Rstudio/rep_villa_elev.grd
names : layer
values : 201, 3585 (min, max)
#####Primero, calcule la pendiente, el aspecto y el sombreado:
#####La biblioteca rayshader es un paquete de código abierto para producir visualizaciones de datos 2D y 3D en R. rayshader utiliza datos de elevación en una matriz base R y una combinación de trazado de rayos, mapeo de texturas esféricas, superposiciones y oclusión ambiental para generar hermosos mapas topográficos 2D y 3D . Además de los mapas, rayshader también permite al usuario traducir objetos ggplot2 en visualizaciones de datos 3D.
#install.packages("rayshader")
elmat = raster_to_matrix(rep_elev)
[1] "Dimensions of matrix are: 660x391."
######detect_water y add_water agrega una capa de agua al mapa:
#install.packages("jpeg")
out = getv(map, aspect, slope)
ning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Infning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Infning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Infning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Infning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Infning昼㹡n argumento finito para min; retornando Infningun argumento finito para max; retornando -Inf