Destination Weather API

Weather forecasts, reports on current weather conditions, astronomical information and alerts at a specific location based on the ‘HERE Destination Weather’ API.

Observations

In order to request information about the current weather situation points of interest (POIs) have to be provided. The POIs must be an sf object containing geometries of type POINT or a character vector containing place names (e.g. cities). These POIs are passed to the weather() function, whereby the product parameter is set to "observation":

observation <- weather(
  poi = poi,
  product = "observation"
)

The return value is an sf object, which contains the POINT geometries of the provided POIs and the most recent record on the observed weather. The measurements are taken from the nearest weather observation stations with respect to the POIs. The distance of the stations to the provided POIs is an indicator for the reliabilty of the weather information at each POI. A table of the observed weather near the example POIs:

station distance description temperature humidity windSpeed windDirection
Rönnimoos 450 Partly sunny. Mild. 19.00 88 0.00 0
Lugano 670 Thunderstorms. Low clouds. Mild. 17.61 98 1.85 0
Chailly 340 Mild. 19.39 66 5.56 220
Kleinhüningen 430 Partly sunny. Mild. 22.00 65 9.27 300
Kehrsatz 620 Sunny. Mild. 21.00 69 5.56 0
Zürich (Kreis 6) / Oberstrass 820 Partly sunny. Mild. 20.00 69 3.71 80
Geneva 490 Partly sunny. Mild. 20.78 56 11.12 230
Vaduz 940 Overcast. Mild. 18.61 84 0.00 190

Print the weather observation information on an interactive leaflet map:

if (requireNamespace("mapview", quietly = TRUE)) {
  m <-
    mapview::mapview(observation,
                     zcol = "temperature",
                     cex = observation$humidity/4,
                     layer.name = "Observation",
                     map.types = c("Esri.WorldTopoMap"),
                     homebutton = FALSE
    ) +
    mapview::mapview(poi,
                     zcol = "city",
                     cex = 1,
                     col.region = "black",
                     legend = FALSE,
                     homebutton = FALSE
    )
  m
}

Forecast

An hourly forecast of the predicted weather for the following seven days can be obtained by setting the product parameter to "forecast_hourly":

forecast <- weather(
  poi = poi,
  product = "forecast_hourly"
)

Print the weather observation information on an interactive leaflet map with popup graphs for temperature and humidity:

  1. Create a list containing the temperature and humidity graphs for every POI:
if (requireNamespace("ggplot2", quietly = TRUE)) {
  g <- lapply(seq_len(nrow(forecast)), function(x) {
    fc <- data.frame(
      dt = as.POSIXct(forecast$forecast[[x]]$utcTime, format = "%Y-%m-%dT%H:%M:%OS", tz = "UTC"),
      te = as.numeric(forecast$forecast[[x]]$temperature),
      rh = as.numeric(forecast$forecast[[x]]$humidity)
    )
    ggplot2::ggplot(fc, ggplot2::aes(x = dt)) +
      ggplot2::geom_line(ggplot2::aes(y = te, colour = "Temperature")) +
      ggplot2::geom_line(ggplot2::aes(y = rh/5, colour = "Humidity")) +
      ggplot2::scale_y_continuous(sec.axis = ggplot2::sec_axis(~.*5, name = "Relative humidity [%]")) +
      ggplot2::scale_colour_manual(values = c("blue", "red")) +
      ggplot2::labs(y = "Air temperature [°C]", x = "", colour = "") +
      ggplot2::ggtitle(forecast$station[x]) +
      ggplot2::theme_minimal() +
      ggplot2::theme(legend.position="bottom", panel.background = ggplot2::element_rect(color = NA))
  })
}
  1. Then add list of graphs to the leaflet map using the the popup parameter:
if (requireNamespace(c("ggplot2", "mapview", "leafpop"), quietly = TRUE)) {
  m <-
    mapview::mapview(forecast,
                     color = "black",
                     col.region = "yellow",
                     layer.name = "Weather station",
                     zcol = "station",
                     map.types = c("Esri.WorldTopoMap"),
                     homebutton = FALSE,
                     legend = FALSE,
                     popup = leafpop::popupGraph(g)
    ) +
    mapview::mapview(poi,
                     zcol = "city",
                     cex = 1,
                     col.region = "black",
                     layer.name = "POI",
                     legend = FALSE,
                     homebutton = FALSE
    )
  m
}

Astronomy

An astronomical forecast is requested by setting the product parameter to "forecast_astronomy":

astronomy <- weather(
  poi = poi,
  product = "forecast_astronomy"
)

Print a table for the sun and moon times of the first example POI, where the nearest station is ‘Emmenbrücke’:

date sunrise sunset moonrise moonset phase
2021-09-26 7:18AM 7:17PM 9:50PM 12:56PM Waning gibbous
2021-09-27 7:19AM 7:15PM 10:24PM 1:59PM Waning gibbous
2021-09-28 7:21AM 7:13PM 11:07PM 2:59PM Waning gibbous
2021-09-29 7:22AM 7:11PM 11:59PM 3:53PM Last Quarter
2021-09-30 7:23AM 7:09PM
4:38PM Last Quarter
2021-10-01 7:25AM 7:07PM 12:59AM 5:16PM Waning crescent
2021-10-02 7:26AM 7:05PM 2:07AM 5:48PM Waning crescent
2021-10-03 7:27AM 7:03PM 3:20AM 6:13PM Waning crescent

Alerts

Current weather alerts, near provided POIs, are obtain by the product alerts:

alerts <- weather(
  poi = poi,
  product = "alerts"
)

This returns an sf object with the POIs and the attribute "alerts", which is a data.table, which contains the current weather alerts. If no alerts are recorded near a POI the attribute "alerts" is NULL.

API Reference