Learn R Programming

azuremapsr (version 0.0.2)

json_to_sf: Convert 'Azure Maps' JSON Response to an sf Object

Description

This function processes a JSON response body from the Azure Maps API, extracts the route information, and converts it into a spatial (sf) object.

Usage

json_to_sf(body, main_route = TRUE, linestring = TRUE)

Value

An sf object containing the spatial features from the route response, or NULL if no valid features are found.

Arguments

body

A list, typically the parsed JSON response from an httr2 request.

main_route

A logical value. If TRUE (the default), only the main route is processed. If FALSE, alternative routes are processed instead.

linestring

A logical value. If TRUE (the default), it filters for LineString geometries (the route path).

Examples

Run this code
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