library(AOI)
library(climateR)
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(raster)
## Warning: package 'raster' was built under R version 4.0.5
## Loading required package: sp
library(rasterVis)
## Warning: package 'rasterVis' was built under R version 4.0.5
## Loading required package: terra
## Warning: package 'terra' was built under R version 4.0.5
## terra version 1.1.4
## Loading required package: lattice
## Loading required package: latticeExtra
## Warning: package 'latticeExtra' was built under R version 4.0.5
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:terra':
##
## collapse, desc, intersect, near, select, union
## 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
list.files()
## [1] "123333.html"
## [2] "123333.Rmd"
## [3] "94_GUAINIA"
## [4] "bbsh.html"
## [5] "bbsh.Rmd"
## [6] "ciudades.txt"
## [7] "cuadeno-6.html"
## [8] "cuadeno 6.Rmd"
## [9] "Cuaderno-3.html"
## [10] "Cuaderno 3.Rmd"
## [11] "cuaderno_4.1nuevo"
## [12] "cuaderno_4.2nuevo"
## [13] "Cuaderno_4.html"
## [14] "Cuaderno_4.Rmd"
## [15] "cuaderno1.html"
## [16] "cuaderno1.Rmd"
## [17] "cuaderno2.html"
## [18] "cuaderno2.Rmd"
## [19] "cuaderno6.1"
## [20] "cuaderno6.html"
## [21] "cuarno5.html"
## [22] "cuarno5.Rmd"
## [23] "este-es-el-ultimo-cuaderno-6.Rmd"
## [24] "este es el ultimo cuaderno 6.Rmd"
## [25] "Evaluaciones_Agropecuarias_Municipales_EVA.csv"
## [26] "guainia 12.tif"
## [27] "guainia sate.tif"
## [28] "Guainia_Dem_z10.tif"
## [29] "MGN2020_DPTO_POLITICO"
## [30] "n03_w068_1arc_v3.tif"
## [31] "rep_Guainia_Dem_z10.tif"
## [32] "rsconnect"
## [33] "sdr.html"
## [34] "sdr.Rmd"
(guainia<- st_read("94_GUAINIA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp"))
## Reading layer `MGN_MPIO_POLITICO' from data source `C:\Users\Juan Narvaez\Documents\geomatica\94_GUAINIA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp' using driver `ESRI Shapefile'
## Simple feature collection with 9 features and 9 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -70.94249 ymin: 1.165633 xmax: -66.84722 ymax: 4.045026
## geographic CRS: WGS 84
## Simple feature collection with 9 features and 9 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -70.94249 ymin: 1.165633 xmax: -66.84722 ymax: 4.045026
## geographic CRS: WGS 84
## DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR
## 1 94 94001 INÍRIDA
## 2 94 94343 BARRANCO MINA
## 3 94 94663 MAPIRIPANA
## 4 94 94883 SAN FELIPE
## 5 94 94884 PUERTO COLOMBIA
## 6 94 94885 LA GUADALUPE
## 7 94 94886 CACAHUAL
## 8 94 94887 PANÁ-PANÁ (Campo Alegre)
## 9 94 94888 MORICHAL (Morichal Nuevo)
## MPIO_CRSLC MPIO_NAREA
## 1 Decreto 1593 de Agosto 5 de 1974 15970.268
## 2 Resolución 83 del 1 de Febrero de 1988 que aprueba con modi 9467.804
## 3 ACUERDO COMISARIAL 018 DEL 25 DE AGOSTO DE 1990 4927.971
## 4 Resolución 83 2926.365
## 5 Resolución 83 15700.545
## 6 Resolución 83 1178.868
## 7 Resolución 83 2335.323
## 8 Resolución 83 de 1988 10227.139
## 9 1988 8554.996
## MPIO_NANO DPTO_CNMBR Shape_Leng Shape_Area geometry
## 1 2017 GUAINÍA 9.256685 1.2869895 POLYGON ((-67.67638 3.91228...
## 2 2017 GUAINÍA 6.825914 0.7652557 POLYGON ((-68.91332 3.68215...
## 3 2017 GUAINÍA 5.010789 0.3990354 POLYGON ((-70.10453 3.38436...
## 4 2017 GUAINÍA 4.029719 0.2346116 POLYGON ((-67.34976 2.50451...
## 5 2017 GUAINÍA 9.166487 1.2632740 POLYGON ((-67.5385 3.177568...
## 6 2017 GUAINÍA 1.750810 0.0943385 POLYGON ((-66.96243 1.66858...
## 7 2017 GUAINÍA 2.364174 0.1876089 POLYGON ((-67.49529 3.75681...
## 8 2017 GUAINÍA 7.805305 0.8250362 POLYGON ((-68.77132 2.42182...
## 9 2017 GUAINÍA 6.916544 0.6917881 POLYGON ((-69.46493 2.88960...
(Climate Hazards Group InfraRed Precipitation with Station data) , es una base de datos de precipitación disponible al público desde 2014 creada por el Servicio Geológico de los Estados Unidos (USGS por sus siglas en inglés) y la Universidad de California - Santa Bárbara (UCSB)
chirps.guai = getCHIRPS(guainia, startDate = "2020-11-01", endDate = "2020-11-06" )
chirps.guai
## class : RasterStack
## dimensions : 58, 83, 4814, 6 (nrow, ncol, ncell, nlayers)
## resolution : 0.05, 0.05 (x, y)
## extent : -70.95, -66.8, 1.15, 4.05 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : prcp_20201101, prcp_20201102, prcp_20201103, prcp_20201104, prcp_20201105, prcp_20201106
## min values : 0, 0, 0, 0, 0, 0
## max values : 255, 255, 255, 255, 255, 255
names(chirps.guai) <- c("P1","P2","P3", "P4", "P5", "P6")
chirps.guai
## class : RasterStack
## dimensions : 58, 83, 4814, 6 (nrow, ncol, ncell, nlayers)
## resolution : 0.05, 0.05 (x, y)
## extent : -70.95, -66.8, 1.15, 4.05 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : P1, P2, P3, P4, P5, P6
## min values : 0, 0, 0, 0, 0, 0
## max values : 255, 255, 255, 255, 255, 255
(capas <- names(chirps.guai))
## [1] "P1" "P2" "P3" "P4" "P5" "P6"
pentads <-c("P1", "P2", "P3", "P4", "P5", "P6")
cellStats(chirps.guai, mean)
## P1 P2 P3 P4 P5 P6
## 27.533860 7.424595 16.025966 68.981097 9.669298 4.517241
for (penta in capas) {
tmp <- chirps.guai[[penta]]
print(cellStats(tmp, max))
}
## [1] 103
## [1] 59
## [1] 95
## [1] 164
## [1] 74
## [1] 69
(valores <- seq(from=1,to=180,by=5))
## [1] 1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91
## [20] 96 101 106 111 116 121 126 131 136 141 146 151 156 161 166 171 176
library(leaflet)
library(RColorBrewer)
pal <- colorNumeric(c("red", "orange", "#fcc000","yellow",
"cyan", "blue", "#3240cd"),
valores, na.color = "transparent")
#se crea un folleto
m <- leaflet() %>%
addTiles(group = "OSM (default)")
# agregar el bucle en los layers
for (penta in capas) {
tmp <- chirps.guai[[penta]]
m <- m %>%
addRasterImage(tmp, colors = pal, opacity = 0.8, group= penta)
}
## 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
## 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
## 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
## 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
## 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
## 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
## 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
## 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
## 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
## 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
## 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
## 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
#
# se crea un felloeto adicional
m <- m %>%
# controladores
addLayersControl(
baseGroups = pentads,
options = layersControlOptions(collapsed = FALSE)
) %>%
# se agraga una leyenda
addLegend(pal = pal, values = valores,
title = "CHIRPS - Noviembre .2020")
m
###Estadísticas básicas de datos climáticos
par(mfrow=c(2,3))
for (penta in capas) {
hist(chirps.guai[[penta]])
}
sessionInfo()
## R version 4.0.4 (2021-02-15)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19042)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=Spanish_Colombia.1252 LC_CTYPE=Spanish_Colombia.1252
## [3] LC_MONETARY=Spanish_Colombia.1252 LC_NUMERIC=C
## [5] LC_TIME=Spanish_Colombia.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] RColorBrewer_1.1-2 leaflet_2.0.4.1 dplyr_1.0.5
## [4] rasterVis_0.50.1 latticeExtra_0.6-29 lattice_0.20-41
## [7] terra_1.1-4 raster_3.4-5 sp_1.4-5
## [10] sf_0.9-7 climateR_0.1.0 AOI_0.2.0.9000
##
## loaded via a namespace (and not attached):
## [1] httr_1.4.2 rnaturalearth_0.1.0 sass_0.3.1
## [4] jsonlite_1.7.2 viridisLite_0.3.0 foreach_1.5.1
## [7] bslib_0.2.4 shiny_1.6.0 assertthat_0.2.1
## [10] highr_0.8 yaml_2.2.1 pillar_1.5.1
## [13] glue_1.4.2 digest_0.6.27 promises_1.2.0.1
## [16] rvest_1.0.0 colorspace_2.0-0 htmltools_0.5.1.1
## [19] httpuv_1.5.5 pkgconfig_2.0.3 purrr_0.3.4
## [22] xtable_1.8-4 scales_1.1.1 jpeg_0.1-8.1
## [25] later_1.1.0.1 tibble_3.1.0 proxy_0.4-25
## [28] leaflet.extras_1.0.0 generics_0.1.0 farver_2.1.0
## [31] ellipsis_0.3.1 hexbin_1.28.2 magrittr_2.0.1
## [34] crayon_1.4.1 mime_0.10 evaluate_0.14
## [37] fansi_0.4.2 doParallel_1.0.16 xml2_1.3.2
## [40] class_7.3-18 tools_4.0.4 USAboundaries_0.3.1
## [43] lifecycle_1.0.0 stringr_1.4.0 munsell_0.5.0
## [46] compiler_4.0.4 jquerylib_0.1.3 e1071_1.7-5
## [49] RNetCDF_2.4-2 rlang_0.4.10 classInt_0.4-3
## [52] units_0.7-0 grid_4.0.4 iterators_1.0.13
## [55] htmlwidgets_1.5.3 crosstalk_1.1.1 base64enc_0.1-3
## [58] rmarkdown_2.7 codetools_0.2-18 DBI_1.1.1
## [61] R6_2.5.0 zoo_1.8-9 knitr_1.31
## [64] rgdal_1.5-23 fastmap_1.1.0 utf8_1.1.4
## [67] KernSmooth_2.23-18 stringi_1.5.3 parallel_4.0.4
## [70] Rcpp_1.0.6 vctrs_0.3.6 png_0.1-7
## [73] tidyselect_1.1.0 xfun_0.22