powered by
This function processes a JSON response body from the Azure Maps API, extracts the route information, and converts it into a spatial (sf) object.
sf
json_to_sf(body, main_route = TRUE, linestring = TRUE)
An sf object containing the spatial features from the route response, or NULL if no valid features are found.
NULL
A list, typically the parsed JSON response from an httr2 request.
A logical value. If TRUE (the default), only the main route is processed. If FALSE, alternative routes are processed instead.
TRUE
FALSE
A logical value. If TRUE (the default), it filters for LineString geometries (the route path).
if (FALSE) { # Assuming 'resp' is an httr2 response object from req_route_directions body <- httr2::resp_body_json(resp) route_sf <- json_to_sf(body) plot(sf::st_geometry(route_sf)) }
Run the code above in your browser using DataLab