Weather forecasts, reports on current weather conditions, astronomical information and alerts at a specific location based on the ‘HERE Destination Weather’ API.
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"
:
<- weather(
observation 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 | Passing clouds. Chilly. | 4.00 | 93 | 3.71 | 0 |
Lugano | 670 | Clear. Cool. | 10.00 | 88 | 1.85 | 0 |
Chailly | 340 | Quite cool. | 6.78 | 86 | 1.85 | 120 |
Kleinhüningen | 430 | Low clouds. Chilly. | 3.50 | 97 | 9.27 | 350 |
Kehrsatz | 620 | Fog. Chilly. | 3.00 | 93 | 7.41 | 320 |
Zürich (Kreis 7) / Fluntern | 850 | Fog. Chilly. | 3.00 | 100 | 3.71 | 0 |
Geneva | 490 | Clear. Quite cool. | 6.00 | 87 | 3.71 | 20 |
Vaduz | 940 | Quite cool. | 4.89 | 88 | 1.85 | 10 |
Print the weather observation information on an interactive leaflet map:
if (requireNamespace("mapview", quietly = TRUE)) {
<-
m ::mapview(observation,
mapviewzcol = "temperature",
cex = observation$humidity/4,
layer.name = "Observation",
map.types = c("Esri.WorldTopoMap"),
homebutton = FALSE
+
) ::mapview(poi,
mapviewzcol = "city",
cex = 1,
col.region = "black",
legend = FALSE,
homebutton = FALSE
)
m }
An hourly forecast of the predicted weather for the following seven days can be obtained by setting the product
parameter to "forecast_hourly"
:
<- weather(
forecast poi = poi,
product = "forecast_hourly"
)
Print the weather observation information on an interactive leaflet map with popup graphs for temperature and humidity:
if (requireNamespace("ggplot2", quietly = TRUE)) {
<- lapply(seq_len(nrow(forecast)), function(x) {
g <- data.frame(
fc 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)
)::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))
ggplot2
}) }
popup
parameter:if (requireNamespace(c("ggplot2", "mapview", "leafpop"), quietly = TRUE)) {
<-
m ::mapview(forecast,
mapviewcolor = "black",
col.region = "yellow",
layer.name = "Weather station",
zcol = "station",
map.types = c("Esri.WorldTopoMap"),
homebutton = FALSE,
legend = FALSE,
popup = leafpop::popupGraph(g)
+
) ::mapview(poi,
mapviewzcol = "city",
cex = 1,
col.region = "black",
layer.name = "POI",
legend = FALSE,
homebutton = FALSE
)
m }
An astronomical forecast is requested by setting the product
parameter to "forecast_astronomy"
:
<- weather(
astronomy 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-11-19 | 7:35AM | 4:48PM | 4:53PM | 7:33AM | Full moon |
2021-11-20 | 7:37AM | 4:47PM | 5:22PM | 8:39AM | Full moon |
2021-11-21 | 7:38AM | 4:46PM | 5:58PM | 9:42AM | Waning gibbous |
2021-11-22 | 7:39AM | 4:45PM | 6:43PM | 10:40AM | Waning gibbous |
2021-11-23 | 7:41AM | 4:44PM | 7:36PM | 11:32AM | Waning gibbous |
2021-11-24 | 7:42AM | 4:44PM | 8:37PM | 12:14PM | Waning gibbous |
2021-11-25 | 7:43AM | 4:43PM | 9:44PM | 12:49PM | Waning gibbous |
2021-11-26 | 7:45AM | 4:42PM | 10:53PM | 1:17PM | Waning gibbous |
Current weather alerts, near provided POIs, are obtain by the product alerts
:
<- weather(
alerts 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
.