library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
library(AOI)
library(climateR)
library(raster)
## Loading required package: sp
library(rasterVis)
## Loading required package: lattice
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:raster':
##
## intersect, select, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(stars)
## Loading required package: abind
library(leaflet)
library(leafem)
library(RColorBrewer)
Este cuaderno nos ayudara a evidenciar la variable climatica usando climate R para el municipio de Santander.
(col <- st_read("MGN_MPIO_POLITICO.shp"))
## Reading layer `MGN_MPIO_POLITICO' from data source
## `/cloud/project/Datos/MGN_MPIO_POLITICO.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1181 features and 11 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -81.73562 ymin: -4.229406 xmax: -66.84722 ymax: 13.39473
## Geodetic CRS: WGS 84
## Simple feature collection with 1181 features and 11 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -81.73562 ymin: -4.229406 xmax: -66.84722 ymax: 13.39473
## Geodetic CRS: WGS 84
## First 10 features:
## DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR
## 1 52 083 BELÉN
## 2 52 110 BUESACO
## 3 52 203 COLÓN
## 4 52 480 NARIÑO
## 5 52 506 OSPINA
## 6 52 720 SAPUYES
## 7 52 786 TAMINANGO
## 8 52 788 TANGUA
## 9 52 240 CHACHAGÜÍ
## 10 52 254 EL PEÑOL
## MPIO_CRSLC MPIO_NAREA
## 1 Ordenanza 53 Noviembre 29 de 1985 41.84541
## 2 1899 635.96083
## 3 Ordenanza 37 de 1921 61.75053
## 4 Ordenanza 027 de Noviembre. 29 de 1999. Decreto 0312 del 24 25.31281
## 5 Ordenanza 50 de 1865 64.84321
## 6 1849 115.54851
## 7 1834 234.65783
## 8 Ordenanza 103 de 1874 217.95977
## 9 Ordenanza 20 Noviembre 24 de 1992 146.27176
## 10 Ordenanza 036 de Diciembre 7 de 1998 119.85744
## MPIO_CCNCT MPIO_NANO DPTO_CNMBR SHAPE_AREA SHAPE_LEN ORIG_FID
## 1 52083 2020 NARIÑO 0.003391678 0.3732840 0
## 2 52110 2020 NARIÑO 0.051533090 1.2292312 1
## 3 52203 2020 NARIÑO 0.005005108 0.4592866 2
## 4 52480 2020 NARIÑO 0.002050175 0.2642048 3
## 5 52506 2020 NARIÑO 0.005249269 0.3371496 4
## 6 52720 2020 NARIÑO 0.009351438 0.6599792 5
## 7 52786 2020 NARIÑO 0.019009395 0.6601636 6
## 8 52788 2020 NARIÑO 0.017652117 0.7808421 7
## 9 52240 2020 NARIÑO 0.011849554 0.7373282 8
## 10 52254 2020 NARIÑO 0.009707107 0.5550189 9
## geometry
## 1 POLYGON ((-77.07227 1.63422...
## 2 POLYGON ((-77.23516 1.45240...
## 3 POLYGON ((-77.04473 1.67173...
## 4 POLYGON ((-77.34282 1.31465...
## 5 POLYGON ((-77.55776 1.07006...
## 6 POLYGON ((-77.71499 1.0915,...
## 7 POLYGON ((-77.32644 1.67981...
## 8 POLYGON ((-77.36152 1.19568...
## 9 POLYGON ((-77.30295 1.51777...
## 10 POLYGON ((-77.39239 1.60127...
Desde aqui el nuevo cuaderno en R
stder <- dplyr::filter(col, DPTO_CNMBR =="SANTANDER")
oneyear = seq(1,12)
# CWD
evapo = getTerraClimNormals(stder, param = "aet", period = "19812010", month=oneyear)
## Spherical geometry (s2) switched off
## Spherical geometry (s2) switched on
evapo1 = getTerraClim(stder, param = "aet", startDate = "2010-02")
## Spherical geometry (s2) switched off
## Spherical geometry (s2) switched on
evapo1
## $terraclim_aet
## class : RasterStack
## dimensions : 60, 50, 3000, 1 (nrow, ncol, ncell, nlayers)
## resolution : 0.04166667, 0.04166667 (x, y)
## extent : -74.54167, -72.45833, 5.666667, 8.166667 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : X2010.02
## min values : 16.4
## max values : 94.4
evapo
## $terraclim_19812010_aet
## class : RasterStack
## dimensions : 60, 50, 3000, 12 (nrow, ncol, ncell, nlayers)
## resolution : 0.04166667, 0.04166667 (x, y)
## extent : -74.54167, -72.45833, 5.666667, 8.166667 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : X01, X02, X03, X04, X05, X06, X07, X08, X09, X10, X11, X12
## min values : 33.5, 28.5, 44.7, 65.7, 67.7, 64.6, 64.2, 63.8, 68.4, 66.7, 60.9, 51.9
## max values : 103.8, 98.9, 124.4, 126.4, 125.6, 123.3, 131.2, 135.3, 129.4, 118.4, 109.6, 113.2
capas <-names(evapo)
# histogram
par(mfcol=c(12,12), mfrow=c(4,3), oma=c(1,1,0,0),
mar=c(1,1,1,0), tcl=-0.1, mgp=c(0,0,0))
for (penta in capas) {
hist(evapo[[penta]], ylab=NA, cex.axis=0.5, font.main=1, cex.main=0.8)
}
###calculo de la evapotranspiracion normal al año
year_evapo <- sum(evapo$terraclim_19812010_aet)
year_evapo
## class : RasterLayer
## dimensions : 60, 50, 3000 (nrow, ncol, ncell)
## resolution : 0.04166667, 0.04166667 (x, y)
## extent : -74.54167, -72.45833, 5.666667, 8.166667 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## source : memory
## names : layer
## values : 694.1, 1349 (min, max)
epal <- colorNumeric(c("orange", "yellow", "#a1d99b", "#deebf7", "#9ecae1","#3182bd", "darkblue"), values(year_evapo$layer),
na.color = "transparent")
leaflet() %>% addTiles() %>%
addRasterImage(year_evapo, colors = epal, opacity = 0.8) %>%
addLegend(pal = epal, values = values(year_evapo$layer),
title = "Actual Evapotranspiration")
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in Proj4 definition
# temperatura maxima
tmax = getTerraClimNormals(stder, param = "tmax", period = "19812010", month=oneyear)
## Spherical geometry (s2) switched off
## Spherical geometry (s2) switched on
tmax
## $terraclim_19812010_tmax
## class : RasterStack
## dimensions : 60, 50, 3000, 12 (nrow, ncol, ncell, nlayers)
## resolution : 0.04166667, 0.04166667 (x, y)
## extent : -74.54167, -72.45833, 5.666667, 8.166667 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : X01, X02, X03, X04, X05, X06, X07, X08, X09, X10, X11, X12
## min values : 9.4, 9.5, 9.2, 8.6, 8.2, 7.0, 6.7, 7.3, 8.0, 7.9, 8.2, 8.9
## max values : 34.1, 34.7, 34.7, 33.9, 33.4, 33.4, 34.2, 33.7, 33.7, 32.9, 32.2, 32.8
(year_tmax = max(tmax$terraclim_19812010_tmax))
## class : RasterLayer
## dimensions : 60, 50, 3000 (nrow, ncol, ncell)
## resolution : 0.04166667, 0.04166667 (x, y)
## extent : -74.54167, -72.45833, 5.666667, 8.166667 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## source : memory
## names : layer
## values : 9.5, 34.7 (min, max)
# Temperatura minima
tmin = getTerraClimNormals(stder, param = "tmin", period = "19812010", month=oneyear)
## Spherical geometry (s2) switched off
## Spherical geometry (s2) switched on
tmin
## $terraclim_19812010_tmin
## class : RasterStack
## dimensions : 60, 50, 3000, 12 (nrow, ncol, ncell, nlayers)
## resolution : 0.04166667, 0.04166667 (x, y)
## extent : -74.54167, -72.45833, 5.666667, 8.166667 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : X01, X02, X03, X04, X05, X06, X07, X08, X09, X10, X11, X12
## min values : -1.0, -1.0, 0.3, 1.0, 0.9, 1.0, 0.5, 0.4, 0.5, 0.9, 0.8, 0.1
## max values : 23.9, 24.0, 24.7, 24.5, 24.3, 24.2, 23.9, 24.0, 24.0, 23.9, 24.2, 24.3
(year_tmin = min(tmin$terraclim_19812010_tmin))
## class : RasterLayer
## dimensions : 60, 50, 3000 (nrow, ncol, ncell)
## resolution : 0.04166667, 0.04166667 (x, y)
## extent : -74.54167, -72.45833, 5.666667, 8.166667 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## source : memory
## names : layer
## values : -1, 23.4 (min, max)
(temp <- stack(year_tmin, year_tmax))
## class : RasterStack
## dimensions : 60, 50, 3000, 2 (nrow, ncol, ncell, nlayers)
## resolution : 0.04166667, 0.04166667 (x, y)
## extent : -74.54167, -72.45833, 5.666667, 8.166667 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : layer.1, layer.2
## min values : -1.0, 9.5
## max values : 23.4, 34.7
names(temp) <- c("tmin", "tmax")
#(valores <- seq(from=-1,to=36,by=6))
tvals <- sort(c(values(temp$tmin),values(temp$tmax)))
#(valores <- seq(from=-1,to=36,by=6))
tvals <- sort(c(values(temp$tmin),values(temp$tmax)))
pal <- colorNumeric(rev(c("red", "orange", "#fff9ae",
"#77ab59", "#dcf3ff", "#a2d2df", "#257ca3")),
tvals, na.color = "transparent")
capas <- names(temp)
# Create leaflet widget --------------------------------------------------------
mapa <- leaflet() %>%
addTiles(group = "OSM (default)") %>%
addRasterImage(year_tmin, colors = pal, opacity = 0.8, group= capas[1]) %>%
addRasterImage(year_tmax, colors = pal, opacity = 0.8, group= capas[2])
## Warning in colors(.): Some values were outside the color scale and will be
## treated as NA
#
# Additional leaflet options
m <- mapa %>%
# Add layers controls
addLayersControl(
overlayGroups = rev(capas),
options = layersControlOptions(collapsed = FALSE)
) %>%
# Add common legend
addLegend(pal = pal, values = tvals,
title = "Temperatura anual")
mapa