rm(list=ls())
library(elevatr)
## Warning: package 'elevatr' was built under R version 4.2.3
## elevatr v0.99.0 NOTE: Version 0.99.0 of 'elevatr' uses 'sf' and 'terra'. Use
## of the 'sp', 'raster', and underlying 'rgdal' packages by 'elevatr' is being
## deprecated; however, get_elev_raster continues to return a RasterLayer. This
## will be dropped in future versions, so please plan accordingly.
library(sf)
## Warning: package 'sf' was built under R version 4.2.3
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.2.3
library(terra)
## Warning: package 'terra' was built under R version 4.2.3
## terra 1.7.71
library(MultiscaleDTM)
## Warning: package 'MultiscaleDTM' was built under R version 4.2.3
library(exactextractr)
## Warning: package 'exactextractr' was built under R version 4.2.3
Leer el modelo de elevacion digital de Casanare
(dem = terra::rast("datos/Elevacion_casanare.tif"))
## class : SpatRaster
## dimensions : 3573, 5128, 1 (nrow, ncol, nlyr)
## resolution : 0.0006856127, 0.0006856127 (x, y)
## extent : -73.125, -69.60918, 4.214913, 6.664608 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +ellps=GRS80 +no_defs
## source : Elevacion_casanare.tif
## name : Elevacion_casanare
## min value : -789
## max value : 5332
(dem2 = terra:: aggregate(dem,2, "mean"))
##
|---------|---------|---------|---------|
=========================================
## class : SpatRaster
## dimensions : 1787, 2564, 1 (nrow, ncol, nlyr)
## resolution : 0.001371225, 0.001371225 (x, y)
## extent : -73.125, -69.60918, 4.214228, 6.664608 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +ellps=GRS80 +no_defs
## source(s) : memory
## name : Elevacion_casanare
## min value : -234.75
## max value : 5312.25
Leer el modelo municipal de Casanare
(munic <- sf::st_read("datos/mun_casanare.gpkg"))
## Reading layer `municipiosdecolombia' from data source
## `C:\Users\usuagro\Documents\GB2\Rproyect\datos\mun_casanare.gpkg'
## using driver `GPKG'
## Simple feature collection with 19 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -73.07777 ymin: 4.287476 xmax: -69.83591 ymax: 6.346111
## Geodetic CRS: MAGNA-SIRGAS
## Simple feature collection with 19 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -73.07777 ymin: 4.287476 xmax: -69.83591 ymax: 6.346111
## Geodetic CRS: MAGNA-SIRGAS
## First 10 features:
## dpto_ccdgo mpio_ccdgo mpio_cdpmp mpio_cnmbr Area_km2
## 1 85 001 85001 YOPAL 2480.4271
## 2 85 010 85010 AGUAZUL 1441.4765
## 3 85 015 85015 CHÁMEZA 309.6568
## 4 85 125 85125 HATO COROZAL 5494.7289
## 5 85 136 85136 LA SALINA 199.7128
## 6 85 139 85139 MANÍ 3750.5337
## 7 85 162 85162 MONTERREY 778.8124
## 8 85 225 85225 NUNCHÍA 1100.7380
## 9 85 230 85230 OROCUÉ 4744.5075
## 10 85 250 85250 PAZ DE ARIPORO 12076.2384
## geom
## 1 MULTIPOLYGON (((-72.39513 5...
## 2 MULTIPOLYGON (((-72.56545 5...
## 3 MULTIPOLYGON (((-72.81017 5...
## 4 MULTIPOLYGON (((-70.3614 6....
## 5 MULTIPOLYGON (((-72.33885 6...
## 6 MULTIPOLYGON (((-72.34155 5...
## 7 MULTIPOLYGON (((-72.89989 5...
## 8 MULTIPOLYGON (((-72.19558 5...
## 9 MULTIPOLYGON (((-71.50965 5...
## 10 MULTIPOLYGON (((-70.32197 6...