Creates an origin-destination cost matrix containing the travel cost between every origin and destination.
Usage
od_cost_matrix(
origins,
destinations = origins,
travel_mode = NULL,
default_cutoff = NULL,
default_target_destination_count = NULL,
output_type = NULL,
time_of_day = NULL,
u_turns = NULL,
use_hierarchy = NULL,
impedance = NULL,
accumulate_impedance = NULL,
restrictions = NULL,
attribute_parameter_values = NULL,
point_barriers = NULL,
line_barriers = NULL,
polygon_barriers = NULL,
return_geometry = character(0),
ignore_invalid_locations = TRUE,
return_empty_results = FALSE,
geometry_precision = NULL,
locate_settings = NULL,
crs = 4326,
token = arcgisutils::arc_token()
)Arguments
- origins
an
sforsfcobject containing point geometries representing the starting points.- destinations
default
origins. Ansforsfcobject containing point geometries representing the ending points.- travel_mode
Character. The name of the travel mode to use. See
get_travel_modes()for available options. Default:NULL.- default_cutoff
default
NULL. A numeric scalar. The travel time or distance value at which to stop searching for facilities.- default_target_destination_count
default
NULL. An integer scalar. The maximum number of destinations to find per origin.- output_type
default
NULL. A scalar character. One of"no_lines","straight_lines","sparse_matrix". Controls whether route geometry is returned.- time_of_day
default
NULL. A scalar date-time. Either aPOSIXtscalar or a character string parseable byas.POSIXlt(). The time and date at which travel begins.- u_turns
default
NULL. A scalar character. U-turn policy at junctions. One of"allow_backtrack","deadend_intersection","deadend","no_backtrack".- use_hierarchy
Logical. Whether to use hierarchy when finding routes. Default:
NULL.- impedance
default
NULL. A scalar character. The impedance to minimize. One of"travel_time","minutes","truck_travel_time","truck_minutes","walk_time","miles","kilometers".- accumulate_impedance
default
NULL. A character vector. Additional impedance values to accumulate.- restrictions
Character vector. Restriction names to honor. Default:
NULL.- attribute_parameter_values
default
NULL. A list of objects. Additional values required by an attribute or restriction.- point_barriers
default
NULL. Ansforsfcobject of point geometries representing barriers to restrict or add cost to travel.- line_barriers
default
NULL. Ansforsfcobject of line geometries representing barriers to restrict or add cost to travel.- polygon_barriers
Polygon barriers as
sforsfcobject. Default:NULL.- return_geometry
default
character(0). A character vector. Valid values:"origins","destinations","barriers","polyline_barriers","polygon_barriers".- ignore_invalid_locations
Logical. Whether to ignore invalid locations. Default:
TRUE.- return_empty_results
default
FALSE. A logical scalar. Returns empty results instead of an error on failure.- geometry_precision
default
NULL. An integer scalar. Decimal places for x and y values in response geometries.- locate_settings
default
NULL. A list controlling how inputs are located on the network.- crs
default
4326. The coordinate reference system of the output geometries. Passed toarcgisutils::as_spatial_reference().- token
Authorization token. Default:
arcgisutils::arc_token().
Value
A named list. Elements present depend on return_geometry and output_type:
od_cost_matrix: nested cost matrix returned whenoutput_type = "sparse_matrix". A list withcostAttributeNamesand, per origin ID, a list mapping destination ID to its cost values.od_lines: OD cost matrix featuresorigins: origin featuresdestinations: destination featuresbarriers: point barrier featurespolyline_barriers: polyline barrier featurespolygon_barriers: polygon barrier featuresmessages: status and warning messages from the service
See also
Other direct:
find_closest_facilities(),
find_routes(),
find_service_areas(),
route_vehicles(),
snap_to_roads()
Other od:
download_od_results(),
od_cost_matrix_job()
Examples
if (FALSE) { # \dontrun{
# This example is not executed since it requires a network connection
# to ArcGIS Online and a valid authentication token
library(sf)
library(arcgisutils)
set_arc_token(auth_user())
origins <- st_sfc(
st_point(c(-122.4194, 37.7749)),
st_point(c(-122.4313, 37.7793)),
crs = 4326
)
destinations <- st_sfc(
st_point(c(-122.4083, 37.7858)),
st_point(c(-122.4000, 37.7900)),
st_point(c(-122.4561, 37.7513)),
crs = 4326
)
result <- od_cost_matrix(
origins = origins,
destinations = destinations
)
result
} # }
