Client tool to get data and metadata from AEMET and convert json to
tibble
.
Arguments
- apidest
Character string as destination URL. See https://opendata.aemet.es/dist/index.html.
- verbose
Logical
TRUE/FALSE
. Provides information about the flow of information between the client and server.
Value
A tibble
(if possible) or the results of the query as
provided by httr2::resp_body_raw()
or httr2::resp_body_string()
.
See also
Some examples on how to use these functions on
vignette("extending-climaemet")
.
Examples
# Run this example only if AEMET_API_KEY is detected
url <- "/api/valores/climatologicos/inventarioestaciones/todasestaciones"
get_data_aemet(url)
#> # A tibble: 947 × 7
#> latitud provincia altitud indicativo nombre indsinop longitud
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 394924N ILLES BALEARS 490 B013X ESCORCA, LLUC "08304" 025309E
#> 2 394744N ILLES BALEARS 5 B051A SÓLLER, PUERTO "08316" 024129E
#> 3 394121N ILLES BALEARS 60 B087X BANYALBUFAR "" 023046E
#> 4 393445N ILLES BALEARS 52 B103B ANDRATX - SANT ELM "99103" 022208E
#> 5 393305N ILLES BALEARS 50 B158X CALVIÀ, ES CAPDEL… "" 022759E
#> 6 393319N ILLES BALEARS 3 B228 PALMA, PUERTO "08301" 023731E
#> 7 393832N ILLES BALEARS 95 B236C PALMA, UNIVERSIDAD "" 023837E
#> 8 394406N ILLES BALEARS 1030 B248 SIERRA DE ALFABIA… "08303" 024247E
#> 9 393621N BALEARES 49 B275E SON BONET, AEROPU… "08302" 024224E
#> 10 393339N ILLES BALEARS 8 B278 PALMA DE MALLORCA… "08306" 024412E
#> # ℹ 937 more rows
# Metadata
get_metadata_aemet(url)
#> # A tibble: 7 × 7
#> unidad_generadora periodicidad descripcion formato copyright notaLegal
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 2 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 3 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 4 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 5 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 6 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> 7 Servicio del Banco de Da… 1 vez al día Inventario… applic… © AEMET.… https://…
#> # ℹ 1 more variable: campos <df[,4]>
# We can get data from any API endpoint
# Plain text
plain <- get_data_aemet("/api/prediccion/nacional/hoy")
#>
#> Results are MIME type: text/plain
#> Returning data as string
cat(plain)
#> AGENCIA ESTATAL DE METEOROLOGÍA
#> PREDICCIÓN GENERAL PARA ESPAÑA
#> DÍA 17 DE JULIO DE 2024 A LAS 11:05 HORA OFICIAL
#> PREDICCIÓN VÁLIDA PARA EL MIÉRCOLES 17
#>
#> A.- FENÓMENOS SIGNIFICATIVOS
#> Temperaturas significativamente elevadas en gran parte del
#> interior de la mitad sur y en el valle del Ebro.
#>
#> B.- PREDICCIÓN
#> Se prevé tiempo estable en la mayor parte del país con cielos
#> poco nubosos o despejados, aunque en el extremo norte peninsular
#> se esperan algunos intervalos de nubes bajas. También algunas
#> nubes altas que se desplazarán de oeste a este, tendiendo a
#> despejar por el oeste. Puede darse alguna nubosidad de evolución
#> por la tarde en montañas del extremo norte, en general de poca
#> importancia, con baja probabilidad de algún chubasco ocasional en
#> la Cantábrica occidental y Pirineos. Asimismo, se prevén nubes
#> bajas matinales en el Levante, sin descartar lluvias débiles
#> durante la mañana y principio de la tarde en el entorno del cabo
#> de la Nao. En Canarias, algunos intervalos nubosos en el norte de
#> las islas de mayor relieve.
#>
#> Probables bancos de niebla matinales en interiores del extremo
#> norte y del interior de Levante. Posible calima en el sudeste,
#> algo más probable y densa en Melilla. No se descarta la
#> formación de brumas o nieblas costeras en Alborán.
#>
#> Las temperaturas máximas descenderán en el área mediterránea
#> peninsular y en Canarias, ascendiendo en el resto del país, de
#> forma incluso notable en el alto Ebro. Se superarán los 35 grados
#> en buena parte del interior de la mitad sur y, de forma probable,
#> en zonas del medio Ebro. También es probable que se superen los
#> 38 en puntos del Guadalquivir sin descartarse en el resto de los
#> valles atlánticos de la mitad sur.
#>
#> Alisios en Canarias con intervalos de fuerte en zonas expuestas.
#> En la Península y Baleares se esperan vientos flojos en general y
#> algo más intensos en litorales, con predominio de la componente
#> este en el área mediterránea y Ebro, con levante en el Estrecho,
#> vientos de componentes norte y este en la cantábrica y de oeste y
#> sur en la atlántica.
#>
# An image
image <- get_data_aemet("/api/mapasygraficos/analisis")
#>
#> Results are MIME type: image/gif
#> Returning raw data
# Write and read
tmp <- tempfile(fileext = ".gif")
writeBin(image, tmp)
gganimate::gif_file(tmp)
#> Error in shell.exec(url): file association for 'C:\Users\RUNNER~1\AppData\Local\Temp\RtmpsFwOWg\file62c11c3016.gif' not available or invalid