Title: | 'sf'-Based Interface to the 'HERE' REST APIs |
---|---|
Description: | Interface to the 'HERE' REST APIs <https://developer.here.com/develop/rest-apis>: (1) geocode and autosuggest addresses or reverse geocode POIs using the 'Geocoder' API; (2) route directions, travel distance or time matrices and isolines using the 'Routing', 'Matrix Routing' and 'Isoline Routing' APIs; (3) request real-time traffic flow and incident information from the 'Traffic' API; (4) find request public transport connections and nearby stations from the 'Public Transit' API; (5) request intermodal routes using the 'Intermodal Routing' API; (6) get weather forecasts, reports on current weather conditions, astronomical information and alerts at a specific location from the 'Destination Weather' API. Locations, routes and isolines are returned as 'sf' objects. |
Authors: | Merlin Unterfinger [aut, cre] , Daniel Possenriede [ctb] |
Maintainer: | Merlin Unterfinger <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1 |
Built: | 2024-11-28 07:06:01 UTC |
Source: | CRAN |
Some example Areas of Interest (AOIs): The boundary polygons of the districts of Zurich. The districts serve as the basis for administrative tasks within the City of Zurich.
data(aoi)
data(aoi)
An object of class "sf", "data.frame"
.
City of Zurich - Department of Civil Engineering and Waste Management - Geomatics + Surveying @geocat.ch
data(aoi)
data(aoi)
Completes addresses using the HERE 'Geocoder Autosuggest' API.
autosuggest(address, results = 5, url_only = FALSE)
autosuggest(address, results = 5, url_only = FALSE)
address |
character, address text to propose suggestions. |
results |
numeric, maximum number of suggestions (Valid range: 1 and 100). |
url_only |
boolean, only return the generated URLs ( |
A data.frame
object, containing the suggestions for the input addresses.
HERE Geocoder API: Autosuggest
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") suggestions <- autosuggest(address = poi$city, url_only = TRUE)
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") suggestions <- autosuggest(address = poi$city, url_only = TRUE)
Route public transport connections with geometries (LINESTRING
) between pairs of points using the HERE 'Public Transit' API.
Two modes are provided:
summary = FALSE
: The public transport connections are returned as mulitple sections with the same vehicle and transport mode. Each section has a detailed route geometry.
summary = TRUE
: A summary of the connections is retrieved, where each connection is represented as one row with a unified and simplified geometry.
connection( origin, destination, datetime = Sys.time(), arrival = FALSE, results = 3, transfers = -1, transport_mode = NULL, summary = FALSE, url_only = FALSE )
connection( origin, destination, datetime = Sys.time(), arrival = FALSE, results = 3, transfers = -1, transport_mode = NULL, summary = FALSE, url_only = FALSE )
origin |
|
destination |
|
datetime |
|
arrival |
boolean, calculate connections for arrival at the defined time ( |
results |
numeric, maximum number of suggested public transport routes (Valid range: 1 and 6). |
transfers |
numeric, maximum number of transfers allowed per route (Valid range: -1 and 6, whereby the |
transport_mode |
character, enable or disable ( |
summary |
boolean, return a summary of the public transport connections instead of the sections of the routes ( |
url_only |
boolean, only return the generated URLs ( |
An sf
object containing the requested routes.
HERE Public Transit API: Transit Route
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Connection sections sections <- connection( origin = poi[3:4, ], destination = poi[5:6, ], summary = FALSE, url_only = TRUE ) # Connection summary summary <- connection( origin = poi[3:4, ], destination = poi[5:6, ], summary = TRUE, url_only = TRUE )
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Connection sections sections <- connection( origin = poi[3:4, ], destination = poi[5:6, ], summary = FALSE, url_only = TRUE ) # Connection summary summary <- connection( origin = poi[3:4, ], destination = poi[5:6, ], summary = TRUE, url_only = TRUE )
Real-time traffic flow from the HERE 'Traffic' API in areas of interest (AOIs). The traffic flow data contains speed and congestion information, which corresponds to the status of the traffic at the time of the query.
flow(aoi, min_jam_factor = 0, url_only = FALSE)
flow(aoi, min_jam_factor = 0, url_only = FALSE)
aoi |
|
min_jam_factor |
numeric, only retrieve flow information with a jam factor greater than the value provided ( |
url_only |
boolean, only return the generated URLs ( |
An sf
object containing the requested traffic flow information.
The maximum width and height of the bounding box of the input AOIs is 1 degree.
This means that each polygon (= one row) in the AOI sf
object should fit in a 1 x 1 degree bbox.
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Real-time traffic flow flow_data <- flow( aoi = aoi, url_only = TRUE )
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Real-time traffic flow flow_data <- flow( aoi = aoi, url_only = TRUE )
Geocodes addresses using the HERE 'Geocoding & Search API' API.
geocode(address, alternatives = FALSE, sf = TRUE, url_only = FALSE)
geocode(address, alternatives = FALSE, sf = TRUE, url_only = FALSE)
address |
character, addresses to geocode or a list containing qualified queries with the keys "country", "state", "county", "city", "district", "street", "houseNumber" or "postalCode". |
alternatives |
boolean, return also alternative results ( |
sf |
boolean, return an |
url_only |
boolean, only return the generated URLs ( |
If sf = TRUE
, an sf
object, containing the position coordinates
geocoded addresses as geometry list column and the access coordinates as
well-known text (WKT).
If sf = FALSE
, a data.frame
containing the coordinates of the
geocoded addresses as lng
, lat
columns.
According to the Geocoding and Search API Reference, the access coordinates are "[c]oordinates of the place you are navigating to (for example, driving or walking). This is a point on a road or in a parking lot." The position coordinates are "[t]he coordinates (latitude, longitude) of a pin on a map corresponding to the searched place."
HERE Geocoding & Search API: Geocode
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") locs <- geocode(address = poi$city, url_only = TRUE)
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") locs <- geocode(address = poi$city, url_only = TRUE)
Traffic incident information from the HERE 'Traffic' API in areas of interest (AOIs). The incidents contain information about location, duration, severity, type, description and further details.
incident(aoi, from = NULL, to = NULL, url_only = FALSE)
incident(aoi, from = NULL, to = NULL, url_only = FALSE)
aoi |
|
from |
|
to |
|
url_only |
boolean, only return the generated URLs ( |
An sf
object containing the traffic incidents.
The maximum width and height of the bounding box of the input AOIs is 1 degree.
This means that each polygon (= one row) in the AOI sf
object should fit in a 1 x 1 degree bbox.
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Traffic incidents incidents <- incident( aoi = aoi, url_only = TRUE )
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Traffic incidents incidents <- incident( aoi = aoi, url_only = TRUE )
Calculates route geometries (LINESTRING
) between given pairs of points using the HERE 'Intermodal Routing' API.
intermodal_route( origin, destination, datetime = Sys.time(), results = 3, transfers = -1, url_only = FALSE )
intermodal_route( origin, destination, datetime = Sys.time(), results = 3, transfers = -1, url_only = FALSE )
origin |
|
destination |
|
datetime |
|
results |
numeric, maximum number of suggested route alternatives (Valid range: 1 and 7, |
transfers |
numeric, maximum number of transfers allowed per route (Valid range: -1 and 6, |
url_only |
boolean, only return the generated URLs ( |
An sf
object containing the requested intermodal routes.
HERE Intermodal Routing API: Routes
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Intermodal routing routes <- intermodal_route( origin = poi[1:3, ], destination = poi[4:6, ], url_only = TRUE )
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Intermodal routing routes <- intermodal_route( origin = poi[1:3, ], destination = poi[4:6, ], url_only = TRUE )
Calcuates isolines (POLYGON
or MULTIPOLYGON
) using the HERE 'Isoline Routing' API
that connect the end points of all routes leaving from defined centers (POIs) with either
a specified length, a specified travel time or consumption (only the default E-car available).
isoline( poi, datetime = Sys.time(), arrival = FALSE, range = seq(5, 30, 5) * 60, range_type = "time", routing_mode = "fast", transport_mode = "car", traffic = TRUE, optimize = "balanced", consumption_model = NULL, aggregate = FALSE, url_only = FALSE )
isoline( poi, datetime = Sys.time(), arrival = FALSE, range = seq(5, 30, 5) * 60, range_type = "time", routing_mode = "fast", transport_mode = "car", traffic = TRUE, optimize = "balanced", consumption_model = NULL, aggregate = FALSE, url_only = FALSE )
poi |
|
datetime |
|
arrival |
boolean, are the provided Points of Interest (POIs) the origin or destination locations ( |
range |
numeric, a vector of type |
range_type |
character, unit of the isolines: |
routing_mode |
character, set the routing mode: |
transport_mode |
character, set the transport mode: |
traffic |
boolean, use real-time traffic or prediction in routing ( |
optimize |
character, specifies how isoline calculation is optimized: |
consumption_model |
character, specify the consumption model of the vehicle ( |
aggregate |
boolean, aggregate (with function |
url_only |
boolean, only return the generated URLs ( |
An sf
object containing the requested isolines.
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Isochrone for 5, 10, 15, 20, 25 and 30 minutes driving time isolines <- isoline( poi = poi, range = seq(5, 30, 5) * 60, url_only = TRUE )
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Isochrone for 5, 10, 15, 20, 25 and 30 minutes driving time isolines <- isoline( poi = poi, range = seq(5, 30, 5) * 60, url_only = TRUE )
Some example Points of Interest (POIs): Cities in Switzerland and Liechtenstein with more than 100'000 inhabitants.
data(poi)
data(poi)
An object of class "sf", "data.frame"
.
Made with Natural Earth. Free vector and raster map data @naturalearthdata.com
data(poi)
data(poi)
Get addresses from locations using the HERE 'Geocoder' API.
The return value is an sf
object, containing point geometries
with suggestions for addresses near the provided POIs.
reverse_geocode(poi, results = 1, sf = TRUE, url_only = FALSE)
reverse_geocode(poi, results = 1, sf = TRUE, url_only = FALSE)
poi |
|
results |
numeric, maximum number of results (Valid range: 1 and 100). |
sf |
boolean, return an |
url_only |
boolean, only return the generated URLs ( |
If sf = TRUE
, an sf
object, containing the position coordinates
of the reverse geocoded POIs as geometry list column and the access
coordinates as well-known text (WKT).
If sf = FALSE
, a data.frame
containing the
coordinates of the reverse geocoded POIs as lng
, lat
columns.
If no addresses are found near a POI, NULL
for this POI is returned.
In this case the rows corresponding to this particular POI are missing and merging the POIs by row is not possible.
However, in the returned sf
object, the column "id"
matches the rows of the input POIs.
The "id"
column can be used to join the original POIs.
HERE Geocoder API: Reverse Geocode
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Get addresses addresses <- reverse_geocode(poi = poi, results = 3, url_only = TRUE)
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Get addresses addresses <- reverse_geocode(poi = poi, results = 3, url_only = TRUE)
Calculates route geometries (LINESTRING
) between given pairs of points using the HERE 'Routing' API.
Routes can be created for various transport modes, as for example 'car' or 'bicycle',
incorporating current traffic information, if available.
For routes using the transport mode "car"
a vehicle consumption model can be specified,
to obtain an estimate of the consumption.
route( origin, destination, datetime = Sys.time(), arrival = FALSE, results = 1, routing_mode = "fast", transport_mode = "car", traffic = TRUE, avoid_area = NULL, avoid_feature = NULL, consumption_model = NULL, vignettes = TRUE, url_only = FALSE )
route( origin, destination, datetime = Sys.time(), arrival = FALSE, results = 1, routing_mode = "fast", transport_mode = "car", traffic = TRUE, avoid_area = NULL, avoid_feature = NULL, consumption_model = NULL, vignettes = TRUE, url_only = FALSE )
origin |
|
destination |
|
datetime |
|
arrival |
boolean, calculate routes for arrival at the defined time ( |
results |
numeric, maximum number of suggested routes (Valid range: 1 and 7). |
routing_mode |
character, set the routing type: |
transport_mode |
character, set the transport mode: |
traffic |
boolean, use real-time traffic or prediction in routing ( |
avoid_area |
|
avoid_feature |
character, transport network features to avoid, e.g. |
consumption_model |
character, specify the consumption model of the vehicle ( |
vignettes |
boolean, include vignettes in the total toll cost of routes ( |
url_only |
boolean, only return the generated URLs ( |
An sf
object containing the requested routes.
Tolls are requested for routes with transport mode "car"
,
"truck"
"taxi"
or "bus"
. The currency defaults to the
current system locale settings. A different currency can be set using
set_currency and a currency code compliant to ISO 4217.
HERE Routing API: Calculate Route
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Get all from - to combinations from POIs to <- poi[rep(seq_len(nrow(poi)), nrow(poi)), ] from <- poi[rep(seq_len(nrow(poi)), each = nrow(poi)), ] idx <- apply(to != from, any, MARGIN = 1) to <- to[idx, ] from <- from[idx, ] # Routing routes <- route( origin = from, destination = to, results = 3, transport_mode = "car", url_only = TRUE )
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Get all from - to combinations from POIs to <- poi[rep(seq_len(nrow(poi)), nrow(poi)), ] from <- poi[rep(seq_len(nrow(poi)), each = nrow(poi)), ] idx <- apply(to != from, any, MARGIN = 1) to <- to[idx, ] from <- from[idx, ] # Routing routes <- route( origin = from, destination = to, results = 3, transport_mode = "car", url_only = TRUE )
Calculates a matrix of M:N, M:1 or 1:N route summaries between given points of interest (POIs) using the HERE 'Matrix Routing' API.
Various transport modes and traffic information at a provided timestamp are supported.
The requested matrix is split into (sub-)matrices of dimension 15x100 to use the
maximum matrix size per request and thereby minimize the number of overall needed requests.
The result is one route summary matrix, that fits the order of the provided POIs: orig_id
, dest_id
.
route_matrix( origin, destination = origin, datetime = Sys.time(), routing_mode = "fast", transport_mode = "car", traffic = TRUE, url_only = FALSE )
route_matrix( origin, destination = origin, datetime = Sys.time(), routing_mode = "fast", transport_mode = "car", traffic = TRUE, url_only = FALSE )
origin |
|
destination |
|
datetime |
|
routing_mode |
character, set the routing type: |
transport_mode |
character, set the transport mode: |
traffic |
boolean, use real-time traffic or prediction in routing ( |
url_only |
boolean, only return the generated URLs ( |
A data.frame
, which is an edge list containing the requested M:N route combinations.
This feature is no longer available with new freemium keys on the HERE platform. For more details, refer to the HERE API documentation.
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Create routes summaries between all POIs mat <- route_matrix( origin = poi, url_only = TRUE )
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Create routes summaries between all POIs mat <- route_matrix( origin = poi, url_only = TRUE )
If the currency is not set using this function call, the currency defined in
the monetary representations in the current locale is used. If the monetary
formatting category "LC_MONETARY"
of the C locale is not set,
"USD"
is set as default.
set_currency(currency = NULL)
set_currency(currency = NULL)
currency |
character, the currency code compliant to ISO 4217 to use in
the requests (default = |
None.
set_currency("CHF")
set_currency("CHF")
If set to TRUE
the hereR package limits the requests per second (RPS)
sent to the APIs and routing matrices will be chopped up into submatrices
of size 15x100. This option is necessary for freemium licenses to avoid
hitting the rate limit of the APIs with status code 429. Deactivate this
option to increase speed of requests for paid plans.
set_freemium(ans = TRUE)
set_freemium(ans = TRUE)
ans |
boolean, use limits or not (default = |
None.
set_freemium(FALSE)
set_freemium(FALSE)
Provide an API Key for a HERE project of type 'REST'. The key is set for the current R session and is used to authenticate in the requests to the APIs.
set_key(api_key)
set_key(api_key)
api_key |
character, the API key from a HERE project. |
No login yet? Get a login and key here: klick
None.
set_key("<YOUR API KEY>")
set_key("<YOUR API KEY>")
If set to TRUE
the hereR package is messaging information about
the amount of requests sent to the APIs and data size received.
set_verbose(ans = FALSE)
set_verbose(ans = FALSE)
ans |
boolean, verbose or not (default = |
None.
set_verbose(TRUE)
set_verbose(TRUE)
Retrieve stations with the corresponding line information around given locations using the HERE 'Public Transit' API.
station(poi, radius = 500, results = 50, url_only = FALSE)
station(poi, radius = 500, results = 50, url_only = FALSE)
poi |
|
radius |
numeric, the search radius in meters ( |
results |
numeric, maximum number of suggested public transport stations (Valid range: 1 and 50, |
url_only |
boolean, only return the generated URLs ( |
An sf
object containing the requested stations with the corresponding line information.
HERE Public Transit API: Station Search
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Stations stations <- station(poi = poi, url_only = TRUE)
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Stations stations <- station(poi = poi, url_only = TRUE)
Remove previously set HERE API key from the current R session.
unset_key()
unset_key()
None.
unset_key()
unset_key()
Weather forecasts, reports on current weather conditions, astronomical information and alerts at a specific location (coordinates or location name) based on the HERE 'Destination Weather' API. The information comes from the nearest available weather station and is not interpolated.
weather(poi, product = "observation", url_only = FALSE)
weather(poi, product = "observation", url_only = FALSE)
poi |
|
product |
character, weather product of the 'Destination Weather API'. Supported products: |
url_only |
boolean, only return the generated URLs ( |
An sf
object containing the requested weather information at the nearest weather station.
The point geometry in the sf
object is the location of the weather station.
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Observation observation <- weather(poi = poi, product = "observation", url_only = TRUE) # Forecast forecast <- weather(poi = poi, product = "forecast_hourly", url_only = TRUE) # Astronomy astronomy <- weather(poi = poi, product = "forecast_astronomy", url_only = TRUE) # Alerts alerts <- weather(poi = poi, product = "alerts", url_only = TRUE)
# Provide an API Key for a HERE project set_key("<YOUR API KEY>") # Observation observation <- weather(poi = poi, product = "observation", url_only = TRUE) # Forecast forecast <- weather(poi = poi, product = "forecast_hourly", url_only = TRUE) # Astronomy astronomy <- weather(poi = poi, product = "forecast_astronomy", url_only = TRUE) # Alerts alerts <- weather(poi = poi, product = "alerts", url_only = TRUE)