require(raster)
## Loading required package: raster
## Warning: package 'raster' was built under R version 4.2.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.2.3
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
require(geodaData)
## Loading required package: geodaData
## Warning: package 'geodaData' was built under R version 4.2.3
require(terra)
## Loading required package: terra
## Warning: package 'terra' was built under R version 4.2.3
## terra 1.7.46
require(sp)
require(sf)
## Loading required package: 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
require(RColorBrewer)
## Loading required package: RColorBrewer
require(leaflet)
## Loading required package: leaflet
## Warning: package 'leaflet' was built under R version 4.2.3
require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.3
require(readxl)
## Loading required package: readxl
## Warning: package 'readxl' was built under R version 4.2.3
require(terra)
require(rasterVis)
## Loading required package: rasterVis
## Warning: package 'rasterVis' was built under R version 4.2.3
## Loading required package: lattice
## Warning: package 'lattice' was built under R version 4.2.3
require(latticeExtra)
## Loading required package: latticeExtra
## Warning: package 'latticeExtra' was built under R version 4.2.3
##
## Attaching package: 'latticeExtra'
## The following object is masked from 'package:rasterVis':
##
## horizonplot
## The following object is masked from 'package:ggplot2':
##
## layer
require(rnaturalearth)
## Loading required package: rnaturalearth
## Warning: package 'rnaturalearth' was built under R version 4.2.3
require(dplyr)
## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 4.2.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:terra':
##
## intersect, 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
require(tidyr)
## Loading required package: tidyr
## Warning: package 'tidyr' was built under R version 4.2.3
##
## Attaching package: 'tidyr'
## The following object is masked from 'package:terra':
##
## extract
## The following object is masked from 'package:raster':
##
## extract
require(htmltools)
## Loading required package: htmltools
## Warning: package 'htmltools' was built under R version 4.2.3
#Temperatura
files = list.files("C:/Users/USUARIO/OneDrive - PUJ Cali/Master/3 semestre/GEOGRAFIA/U2/promedio_temp", full.names = TRUE)
tempe = stack(files)
names(tempe) = month.name
criterios_temp = tempe>20 & tempe<30
names(criterios_temp) = month.name
colores<- c("lightblue", "navy")
plot(criterios_temp, col= colores)
### Aplicando los criterios definidos líneas arriba, se identifica que
las zonas tropicales como las más aptas para el cultivo de caña
azucar.
#Precipitación
files_p = list.files("C:/Users/USUARIO/OneDrive - PUJ Cali/Master/3 semestre/GEOGRAFIA/U2/precipitacion", full.names = TRUE)
precip = stack(files_p)
names(precip) = month.name
criterios_prec = precip>=100 & precip<=285
names(criterios_prec) = month.name
colores_p<- c("lightgreen", "orange")
plot(criterios_prec, col= colores_p)
### Se identifica que, una vez aplicados los criterios de temperatura y
precipitación óptimos para el cultivo de caña de azúcar, los países
ubicados en el trópico muestran un potencial significativo para esta
actividad agrícola. .
ideales_temp = sum(criterios_temp)
ideales_temp = ideales_temp/12*100
eliminar_temp = which(ideales_temp[]<75)
ideales_temp[eliminar_temp]=NA
plot(ideales_temp, main = "Porcentaje de ideales en temperatura")
## Precipitación por mes
ideales_prec = sum(criterios_prec)
ideales_prec = ideales_prec/12*100
eliminar_prec = which(ideales_prec[]<75)
ideales_prec[eliminar_prec]=NA
plot(ideales_prec, main = "Porcentaje de ideales en precipitación")
### Con base en los resultados de temperatura y precipitación global
para el cultivo de caña de azúcar, se procede elige a Colombia, Chad e
Indonesia
globales<- ne_countries(scale = "medium", returnclass = "sf")
paises_optimos<- c("Colombia", "Indonesia", "Malaysia")
lugares_potenciales<- globales %>%
filter(admin %in% paises_optimos)
map = ggplot(data = globales) +
geom_sf(fill = "lightblue", color = "white")+
geom_sf(data = lugares_potenciales, aes(fill = admin), color = "navy") +
scale_fill_manual(values = c("Colombia" = "#008080", "Indonesia" = "#57CEEB", "Malaysia"= "#4CAF50")) +
theme_minimal() +
labs(title = "Países con temperatura y precipitación optima para la Caña de Azúcar",
fill ="País") +
theme(legend.position = "bottom")
map
## Punto 3
Identificar puntos en el Valle del Cauca para extraer información del clima.
library(leaflet)
set.seed(318)
puntos <- 3
puntos_aleatorios <- data.frame(
lat = runif(puntos, min = 3.2, max = 4.5),
lon = runif(puntos, min = -77.2, max = -75.8),
label = paste("Ubicación", 1:puntos)
)
mapa_valle <- leaflet(data = puntos_aleatorios) %>%
addTiles() %>%
addMarkers(lng = ~lon, lat = ~lat, popup = ~label)
mapa_valle
puntos_aleatorios <- puntos_aleatorios[, c("lon", "lat")]
temp_v=(raster::extract (tempe,puntos_aleatorios))
Tempe_Valle= as.data.frame(temp_v)
Tempe_Valle$Ubicación <- c("Localización 1", "Localización 2", "Localización 3")
Tempe_Valle_long <- pivot_longer(data = Tempe_Valle, cols = -Ubicación, names_to = "Mes", values_to = "Temperatura")
meses <- c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
Tempe_Valle_long$Mes <- factor(Tempe_Valle_long$Mes, levels = meses)
ggplot(Tempe_Valle_long, aes(x = Mes, y = Temperatura, fill = Ubicación)) +
geom_bar(stat = "identity", position = position_dodge(), width= 0.7) +
labs(title = "Comparación de Temperaturas por Localización",
x = "Mes",
y = "Temperatura Total",
fill = "Ubicación") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
preci_v=(raster::extract (precip,puntos_aleatorios))
Precip_Valle= as.data.frame(preci_v)
Precip_Valle$Ubicación <- c("Localización 1", "Localización 2", "Localización 3")
Precip_Valle_long <- pivot_longer(data = Precip_Valle, cols = -Ubicación, names_to = "Mes", values_to = "Precipitación")
meses_pre <- c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
Precip_Valle_long$Mes <- factor(Precip_Valle_long$Mes, levels = meses_pre)
ggplot(Precip_Valle_long, aes(x = Mes, y = Precipitación, fill = Ubicación)) +
geom_bar(stat = "identity", position = position_dodge(), width= 0.7) +
labs(title = "Comparación de Precipitación por Localización",
x = "Mes",
y = "Precipitación Total",
fill = "Ubicación") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
### Los 3 puntos aleatoros del Valle del Cauca, sobrezale la
localización 2 cumpliendo los criterios de temperatura y precipitación
ideal para el cultivo de caña de azúcar, la localización 3 no es optima
y la localización 1 solo es optima algunos meses del año.
Comparación de los puntos aleatorios con el resto del mundo, temperatura
tempe_locs = raster::extract(tempe, puntos_aleatorios)
euclidean_distance <- function(x, tempe_locs) {
distancias = apply(tempe_locs, 1, function(pt) {
sqrt(sum((x - pt)^2, na.rm = TRUE))
})
min(distancias, na.rm = TRUE)
}
distance_raster = calc(tempe, fun = function(x) euclidean_distance(x, tempe_locs))
# Visualizar el raster resultante de distancias euclidianas
plot(distance_raster, main = "Distancia Euclidiana a localizaciones del valle del cauca Temperatura")
preci_locs = raster::extract(precip, puntos_aleatorios)
euclidean_distance <- function(x, preci_locs) {
distancias_pre = apply(preci_locs, 1, function(pt) {
sqrt(sum((x - pt)^2, na.rm = TRUE))
})
min(distancias_pre, na.rm = TRUE)
}
distance_raster_pre = calc(precip, fun = function(x) euclidean_distance(x, preci_locs))
# Visualizar el raster resultante de distancias euclidianas
plot(distance_raster_pre, main = "Distancia Euclidiana a localizaciones del valle del cauca Precipitaciones")