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

View source: R/utils.R

json_to_sfR Documentation

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)

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).

Value

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

Examples

## Not run: 
# 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))

## End(Not run)

azuremapsr documentation built on Aug. 27, 2025, 5:11 p.m.