Finds one or more nearby facilities from incidents based on travel time or distance.
Usage
find_closest_facilities(
incidents,
facilities,
travel_mode = NULL,
default_target_facility_count = NULL,
travel_direction = NULL,
default_cutoff = NULL,
time_of_day = NULL,
time_of_day_usage = 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 = c("facilities", "incidents"),
directions_language = NULL,
directions_output_type = NULL,
directions_style = NULL,
directions_length_units = NULL,
directions_time_attribute = NULL,
output_lines = "true_shape",
ignore_invalid_locations = TRUE,
preserve_object_id = FALSE,
return_empty_results = FALSE,
output_geometry_precision = 10,
output_geometry_precision_units = "meters",
geometry_precision = NULL,
geometry_precision_m = NULL,
locate_settings = NULL,
crs = 4326,
token = arcgisutils::arc_token()
)Arguments
- incidents
an
sforsfcobject containing point geometries representing the locations to search from.- facilities
an
sforsfcobject containing point geometries representing the facilities to search for.- travel_mode
Character. The name of the travel mode to use. See
get_travel_modes()for available options. Default:NULL.- default_target_facility_count
default
NULL. An integer scalar. The number of closest facilities to find per incident.- travel_direction
default
"away". A scalar character. One of"away"(away from facility) or"towards"(toward facility).- default_cutoff
default
NULL. A numeric scalar. The travel time or distance value at which to stop searching for facilities.- 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.- time_of_day_usage
default
NULL. A scalar character. One of"start_time"or"end_time". Specifies whethertime_of_dayrepresents departure or arrival time.- 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
c("facilities", "incidents"). A character vector. Valid values:"cf_routes","facilities","incidents","directions","barriers","polyline_barriers","polygon_barriers","traversed_edges","traversed_junctions","traversed_turns". Use"everything"to return all.- directions_language
Character. Language code for directions (e.g.,
"en"). Default:"en".- directions_output_type
default
NULL. A scalar character. One of"standard","complete","complete_no_events","instructions_only","summary_only","feature_sets".- directions_style
default
NULL. A scalar character. One of"desktop","navigation","campus".- directions_length_units
default
NULL. A scalar character. One of"miles","kilometers","feet","meters","yards","nautical_miles".- directions_time_attribute
default
NULL. A scalar character. The time-based impedance attribute used for direction durations.- output_lines
default
NULL(no lines). A scalar character orNULL. One of"true_shape"or"with_measure".- ignore_invalid_locations
Logical. Whether to ignore invalid locations. Default:
TRUE.- preserve_object_id
default
FALSE. A logical scalar. Preserves object IDs from input locations in the output.- return_empty_results
default
FALSE. A logical scalar. Returns empty results instead of an error on failure.- output_geometry_precision
default
10. A numeric scalar. Simplification tolerance applied to output geometry.- output_geometry_precision_units
default
"meters". A scalar character. Units foroutput_geometry_precision. Same valid values astrim_polygon_distance_units.- geometry_precision
default
NULL. An integer scalar. Decimal places for x and y values in response geometries.- geometry_precision_m
default
NULL. A scalar character. Decimal places for m-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:
cf_routes: route features between incidents and facilitiesfacilities: facility featuresincidents: incident featuresdirection_points: point features for direction maneuversdirection_lines: line features for route segmentsbarriers: point barrier featurespolyline_barriers: polyline barrier featurespolygon_barriers: polygon barrier featurestraversed_edges: traversed edge featurestraversed_junctions: traversed junction featurestraversed_turns: traversed turn featuresmessages: status and warning messages from the service
See also
Other direct:
find_routes(),
find_service_areas(),
od_cost_matrix(),
route_vehicles(),
snap_to_roads()
Other closest facility:
find_closest_facilities_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())
incidents <- st_sfc(st_point(c(-122.4496, 37.7467)), crs = 4326)
facilities <- st_sf(
name = c("Station 11", "Station 20", "Station 24", "Station 39"),
geometry = st_sfc(
st_point(c(-122.4267, 37.7486)),
st_point(c(-122.4561, 37.7513)),
st_point(c(-122.4409, 37.7533)),
st_point(c(-122.4578, 37.7407)),
crs = 4326
)
)
result <- find_closest_facilities(
incidents = incidents,
facilities = facilities,
default_target_facility_count = 2,
travel_direction = "away",
default_cutoff = 3,
return_geometry = "cf_routes",
directions_length_units = "miles",
crs = 3857
)
result
} # }
