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. Warm. | 29.00 | 51 | 5.56 | 0 |
Lugano | 670 | Scattered clouds. Warm. | 30.50 | 65 | 7.41 | 190 |
Chailly | 340 | Passing clouds. Warm. | 29.89 | 46 | 20.39 | 350 |
Kleinhüningen | 430 | Passing clouds. Pleasantly warm. | 29.11 | 39 | 5.56 | 310 |
Kehrsatz | 620 | Passing clouds. Warm. | 29.00 | 48 | 14.83 | 320 |
Zürich (Kreis 6) / Oberstrass | 820 | Partly sunny. Warm. | 28.00 | 45 | 9.27 | 0 |
Geneva | 490 | Passing clouds. Pleasantly warm. | 30.28 | 31 | 12.97 | 60 |
Vaduz | 940 | Passing clouds. Warm. | 28.89 | 53 | 11.12 | 330 |
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 |
---|---|---|---|---|---|
2022-07-24 | 5:55AM | 9:10PM | 1:59AM | 6:22PM | Waning crescent |
2022-07-25 | 5:57AM | 9:09PM | 2:34AM | 7:22PM | Waning crescent |
2022-07-26 | 5:58AM | 9:07PM | 3:17AM | 8:14PM | Waning crescent |
2022-07-27 | 5:59AM | 9:06PM | 4:09AM | 8:57PM | Waning crescent |
2022-07-28 | 6:00AM | 9:05PM | 5:10AM | 9:32PM | New moon |
2022-07-29 | 6:01AM | 9:04PM | 6:15AM | 9:59PM | New moon |
2022-07-30 | 6:02AM | 9:03PM | 7:23AM | 10:22PM | New moon |
2022-07-31 | 6:04AM | 9:01PM | 8:31AM | 10:41PM | Waxing crescent |
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
.