Closed jesbrz closed 1 month ago
Hay varias maneras de hacerlo, una puede ser simplemente llamando a todas las alertas con alerts_region <- aemet_alerts(return_sf = TRUE)
y luego filtrando por COD_Z
según las que necesites.
En cuanto a tu duda sobre los nombres, el problema es que las comarcas en España no son por lo general entidades oficiales (creo que en alguna comunidad si, pero no en todas). Además de que existen diferentes tipos de comarcas (agricolas, ganaderas, históricas, etc.). Lo que hay que tener en cuenta aqui es que la AEMET no usacomarcas, sino "zonas de aviso", asi que en lugar de usar las comarcas de mapSpain habria que usar las zonas de aviso aemet_alert_zones
. Mas info en https://www.aemet.es/documentos/es/eltiempo/prediccion/avisos/plan_meteoalerta/METEOALERTA_ANX2_Zonas_aviso.pdf.
Te paso de todas maneras un script modificado.
library(climaemet)
library(dplyr)
#>
#> Adjuntando el paquete: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# Mostrar los nombres de la zona de aviso filtrando por regex en el nombre (contiene partícula "Bierzo").
bierzo <- aemet_alert_zones() %>%
distinct() %>%
filter(grepl("Bierzo", NOM_Z))
glimpse(bierzo)
#> Rows: 1
#> Columns: 6
#> $ COD_Z <chr> "672402"
#> $ NOM_Z <chr> "Bierzo de León"
#> $ COD_PROV <chr> "6724"
#> $ NOM_PROV <chr> "León"
#> $ COD_CCAA <chr> "67"
#> $ NOM_CCAA <chr> "Castilla y León"
# Obtener el mapa base de la zona específica pero con climaemet
basemap <- aemet_alert_zones(return_sf = TRUE) %>%
filter(COD_Z == bierzo$COD_Z)
# Solamente para comprobar
com_auto <- mapSpain::esp_get_prov("Castilla y Leon")
ggplot(basemap) +
geom_sf(data = com_auto) +
geom_sf((aes(fill = NOM_Z)))
# Obtener todas las alertas
alerts_region <- aemet_alerts(
return_sf = TRUE
) %>%
# Y filtrar por COD_Z
filter(COD_Z %in% bierzo$COD_Z)
# Hoy no hay
Sys.Date()
#> [1] "2024-08-26"
alerts_region
#> Simple feature collection with 0 features and 28 fields
#> Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA
#> Geodetic CRS: WGS 84
#> # A tibble: 0 × 29
#> # ℹ 29 variables: NOM_CCAA <chr>, COD_CCAA <chr>, NOM_PROV <chr>,
#> # COD_PROV <chr>, NOM_Z <chr>, COD_Z <chr>, language <chr>, category <chr>,
#> # event <chr>, responseType <chr>, urgency <chr>, severity <chr>,
#> # certainty <chr>, AEMET-Meteoalerta fenomeno <chr>, effective <dttm>,
#> # onset <dttm>, expires <dttm>, senderName <chr>, headline <chr>,
#> # description <chr>, instruction <chr>, web <chr>, contact <chr>,
#> # AEMET-Meteoalerta nivel <chr>, AEMET-Meteoalerta parametro <chr>, …
Created on 2024-08-26 with reprex v2.1.1
La verdad es que lo de los nombres es un follón.... esta solución funciona de perlas, gracias.
Nueva version en CRAN con esta función incluida #65
Hola. Estoy probando la nueva característica de aemet_alerts para descargar las alertas para una comarca, pero no encuentro la forma. Este es el código que uso:
Pero en el tercer paso me falla, claro está porque no es una ccaa:
¿Cuál sería el código a incluir? Para liar más la cosa, AEMET le llama a la comarca "Bierzo de León" y mapSpain "Bierzo" lo que intuyo que también puede dificultar las cosas.
Saludos.