arcgis.network module¶
The arcgis.network module contains classes and functions for network analysis. Network layers and analysis can be used for operations such as finding the closest facility, the best route for a vehicle, the best routes for a fleet of vehicles, locating facilities using location allocation, calculating an OD cost matrix, and generating service areas.
NetworkLayer¶
-
class
arcgis.network.
NetworkLayer
(url, gis=None)¶ NetworkLayer represents a single network layer. It provides basic information about the network layer such as its name, type, and network classes. Additionally, depending on the layer type, it provides different pieces of information.
It is a base class for RouteLayer, ServiceAreaLayer, and ClosestFacilityLayer.
-
retrieve_travel_modes
()¶ identify all the valid travel modes that have been defined on the network dataset or in the portal if the GIS server is federated
-
RouteLayer¶
-
class
arcgis.network.
RouteLayer
(url, gis=None)¶ The Route Layer which has common properties of Network Layer as well as some attributes unique to Route Network Layer only.
-
solve
(stops, barriers=None, polyline_barriers=None, polygon_barriers=None, travel_mode=None, attribute_parameter_values=None, return_directions=True, return_routes=True, return_stops=False, return_barriers=False, return_polyline_barriers=False, return_polygon_barriers=False, out_sr=None, ignore_invalid_locations=True, output_lines=None, find_best_sequence=False, preserve_first_stop=True, preserve_last_stop=True, use_time_windows=False, start_time=None, start_time_is_utc=False, accumulate_attribute_names=None, impedance_attribute_name=None, restriction_attribute_names=None, restrict_u_turns=None, use_hierarchy=True, directions_language=None, directions_output_type=None, directions_style_name=None, directions_length_units=None, directions_time_attribute_name=None, output_geometry_precision=None, output_geometry_precision_units=None, return_z=False, overrides=None, preserve_objectid=False, future=False, time_windows_are_utc=False, return_traversed_edges=None, return_traversed_junctions=None, return_traversed_turns=None, geometry_precision=None, geometry_precision_z=None, geometry_precision_m=None, locate_settings=None, return_empty_results=False)¶ The solve operation is performed on a network layer resource. The solve operation is supported on a network layer whose layerType is esriNAServerRouteLayer. You can provide arguments to the solve route operation as query parameters.
Parameter
Description
stops
Required Points/FeatureSet/a list of Features. The set of stops loaded as network locations during analysis. Stops can be specified using a simple comma / semi-colon based syntax or as a JSON structure. If stops are not specified, preloaded stops from the map document are used in the analysis.
barriers
Optional Point/FeatureSet. The set of barriers loaded as network locations during analysis. Barriers can be specified using a simple comma/semi-colon based syntax or as a JSON structure. If barriers are not specified, preloaded barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded barriers are ignored.
polyline_barriers
Optional Polyline/FeatureSet. The set of polyline barriers loaded as network locations during analysis. If polyline barriers are not specified, preloaded polyline barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded polyline barriers are ignored.
polygon_barriers
Optional Polygon/FeatureSet. The set of polygon barriers loaded as network locations during analysis. If polygon barriers are not specified, preloaded polygon barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded polygon barriers are ignored.
travel_mode
Optional string. Travel modes provide override values that help you quickly and consistently model a vehicle or mode of transportation. The chosen travel mode must be preconfigured on the network dataset that the routing service references.
attribute_parameter_values
Optional string/list. A set of attribute parameter values that can be parameterized to determine which network elements can be used by a vehicle.
return_directions
Optional boolean. If true, directions will be generated and returned with the analysis results. Default is true.
return_routes
Optional boolean. If true, routes will be returned with the analysis results. Default is true.
return_stops
Optional boolean. If true, stops will be returned with the analysis results. Default is false.
return_barriers
Optional boolean. If true, barriers will be returned with the analysis results. Default is false.
return_polyline_barriers
Optional boolean. If true, polyline barriers will be returned with the analysis results. Default is False.
return_polygon_barriers
Optional boolean. If true, polygon barriers will be returned with the analysis results. Default is False.
out_sr
Optional Integer. The spatial reference of the geometries returned with the analysis results.
ignore_invalid_locations
Optional boolean. - If true, the solver will ignore invalid locations. Otherwise, it will raise an error. Default is true.
output_lines
The type of output lines to be generated in the result. The default is as defined in the network layer. Values: esriNAOutputLineTrueShape |
esriNAOutputLineTrueShapeWithMeasure | esriNAOutputLineStraight | esriNAOutputLineNone
find_best_sequence
Optional boolean. If true, the solver should re-sequence the route in the optimal order. The default is as defined in the network layer.
preserve_first_stop
Optional boolean. If true, the solver should keep the first stop fixed in the sequence. The default is as defined in the network layer.
preserve_last_stop
Optional boolean. If true, the solver should keep the last stop fixed in the sequence. The default is as defined in the network layer.
use_time_window
Optional boolean. If true, the solver should consider time windows. The default is as defined in the network layer.
start_time
Optional string. The time the route begins. If not specified, the solver will use the default as defined in the network layer.
start_time_is_utc
Optional boolean. The time zone of the startTime parameter.
accumulate_attribute_names
Optional string. A list of network attribute names to be accumulated with the analysis. The default is as defined in the network layer. The value should be specified as a comma separated list of attribute names. You can also specify a value of none to indicate that no network attributes should be accumulated.
impedance_attribute_name
Optional string. The network attribute name to be used as the impedance attribute in analysis. The default is as defined in the network layer.
restriction_attribute_names
Optional string. -The list of network attribute names to be used as restrictions with the analysis. The default is as defined in the network layer. The value should be specified as a comma separated list of attribute names. You can also specify a value of none to indicate that no network attributes should be used as restrictions.
restrict_u_turns
Optional boolean. Specifies how U-Turns should be restricted in the analysis. The default is as defined in the network layer. Values: esriNFSBAllowBacktrack | esriNFSBAtDeadEndsOnly |
esriNFSBNoBacktrack | esriNFSBAtDeadEndsAndIntersections
use_hierarchy
Optional boolean. If true, the hierarchy attribute for the network should be used in analysis. The default is as defined in the network layer.
directions_language
Optional string. The language to be used when computing directions. The default is the language of the server’s operating system. The list of supported languages can be found in REST layer description.
directions_output_type
Optional string. Defines content, verbosity of returned directions. The default is esriDOTInstructionsOnly. Values: esriDOTComplete | esriDOTCompleteNoEvents
esriDOTInstructionsOnly | esriDOTStandard |esriDOTSummaryOnly
directions_style_name
Optional string. The style to be used when returning the directions. The default is as defined in the network layer. The list of supported styles can be found in REST layer description.
directions_length_units
Optional string. The length units to use when computing directions. The default is as defined in the network layer. Values: esriNAUFeet | esriNAUKilometers | esriNAUMeters |
esriNAUMiles | esriNAUNauticalMiles | esriNAUYards | esriNAUUnknown
directions_time_attribute_name
Optional string. The name of network attribute to use for the drive time when computing directions. The default is as defined in the network layer.
output_geometry_precision
Optional float. The precision of the output geometry after generalization. If 0, no generalization of output geometry is performed. The default is as defined in the network service configuration.
output_geometry_precision_units
Optional string. The units of the output geometry precision. The default value is esriUnknownUnits. Values: esriUnknownUnits | esriCentimeters | esriDecimalDegrees |
esriDecimeters | esriFeet | esriInches | esriKilometers | esriMeters | esriMiles | esriMillimeters | esriNauticalMiles | esriPoints | esriYards
return_z
Optional boolean. If true, Z values will be included in the returned routes and compressed geometry if the network dataset is Z-aware. The default is false.
overrides
Optional dictionary. Specify additional settings that can influence the behavior of the solver. A list of supported override settings for each solver and their acceptable values can be obtained by contacting Esri Technical Support.
preserve_objectid
Optional Boolean. If True, all objectid values are maintained. The default is False.
future
Optional boolean. If True, a future object will be returned and the process will not wait for the task to complete. The default is False, which means wait for results.
time_windows_are_utc
Optional boolean. Specify whether the TimeWindowStart and TimeWindowEnd attribute values on stops are specified in coordinated universal time (UTC) or geographically local time.
return_traversed_edges
Optional boolean. Specify whether traversed edges will be returned by the service.
return_traversed_junctions
Optional boolean. Specify whether traversed junctions will be returned by the service.
return_traversed_turns
Optional boolean. Specify whether traversed turns will be returned by the service.
geometry_precision
Optional Integer. Use this parameter to specify the number of decimal places in the response geometries returned by solve operation. This applies to x/y values only (not m- or z-values).
geometry_precision_z
Optional Integer. Use this parameter specify the number of decimal places in the response geometries returned by solve operation. This applies to z-value only.
geometry_precision_m
Optional Integer. Use this parameter to specify the number of decimal places in the response geometries returned by solve operation. This applies to m-value only.
locate_settings
Optional dictionary containing additional input location settings. Use this parameter to specify settings that affect how inputs are located, such as the maximum search distance to use when locating the inputs on the network or the network sources being used for locating. To restrict locating on a portion of the source, you can specify a where clause for a source.
The dictionary of parameters can be assigned to the ‘default’, or to the ‘overrides’ key which holds the dictionary of parameters for each override, types of override are ‘stops’, ‘barriers’, ‘polylineBarriers’, ‘polygonBarriers’. Use the
LocateSettings
class to create the dictionary for each override or for the default.Note
‘default’ has to be present if you want to pass in any locate_settings to the service. In addition, locate settings for default have to be complete, meaning all properties need to be present. For each override, the keys do not have to be complete.
Note
for ‘polylineBarriers’ and ‘polygonBarriers’, tolerance and tolerance_units are not supported.
from arcgis.network import LocateSettings locate_settings = LocateSettings( tolerance=5000, tolerance_units=ToleranceUnits.meters, allow_auto_relocate=True, sources=[{"name": "Routing_Streets"}] ) result = route_layer.solve(stops=stops, locate_settings={"default": locate_settings.to_dict()})
return_empty_results
Optional boolean. If True, the service will return empty results instead of the error property when the request fails. The default is False.
- Returns
dict
# USAGE EXAMPLE: Solving the routing problem by passing in a FeatureSet # get a FeatureSet through query fl = sample_cities.layers[0] cities_to_visit = fl.query(where="ST = 'CA' AND POP2010 > 300000", out_fields='NAME', out_sr=4326) type(cities_to_visit) >> arcgis.features.feature.FeatureSet # pass in the FeatureSet result = route_layer.solve(stops=cities_to_visit, preserve_first_stop=True, preserve_last_stop=True, find_best_sequence=True, return_directions=False, return_stops=True, return_barriers=False, return_polygon_barriers=False, return_polyline_barriers=False, return_routes=True, output_lines='esriNAOutputLineStraight')
-
ServiceAreaLayer¶
-
class
arcgis.network.
ServiceAreaLayer
(url, gis=None)¶ The Service Area Layer which has common properties of Network Layer as well as some attributes unique to Service Area Layer only.
-
solve_service_area
(facilities, barriers=None, polyline_barriers=None, polygon_barriers=None, travel_mode=None, attribute_parameter_values=None, default_breaks=None, exclude_sources_from_polygons=None, merge_similar_polygon_ranges=None, output_lines=None, output_polygons=None, overlap_lines=None, overlap_polygons=None, split_lines_at_breaks=None, split_polygons_at_breaks=None, trim_outer_polygon=None, trim_polygon_distance=None, trim_polygon_distance_units=None, return_facilities=False, return_barriers=False, return_polyline_barriers=False, return_polygon_barriers=False, out_sr=None, accumulate_attribute_names=None, impedance_attribute_name=None, restriction_attribute_names=None, restrict_u_turns=None, output_geometry_precision=None, output_geometry_precision_units='esriUnknownUnits', use_hierarchy=None, time_of_day=None, time_of_day_is_utc=None, travel_direction=None, return_z=False, overrides=None, preserve_objectid=False, future=False, ignore_invalid_locations=True, geometry_precision=None, geometry_precision_z=None, geometry_precision_m=None, locate_settings=None, return_empty_results=False, include_source_information_on_lines=True)¶ The solve service area operation is performed on a network layer resource of type service area (layerType is esriNAServerServiceArea). You can provide arguments to the solve service area operation as query parameters.
Parameter
Description
facilities
The set of facilities loaded as network locations during analysis. Facilities can be specified using a simple comma / semi-colon based syntax or as a JSON structure. If facilities are not specified, preloaded facilities from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded facilities are ignored.
barriers
The set of barriers loaded as network locations during analysis. Barriers can be specified using a simple comma/semicolon-based syntax or as a JSON structure. If barriers are not specified, preloaded barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’), preloaded barriers are ignored.
polyline_barriers
The set of polyline barriers loaded as network locations during analysis. If polyline barriers are not specified, preloaded polyline barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’), preloaded polyline barriers are ignored.
polygon_barriers
The set of polygon barriers loaded as network locations during analysis. If polygon barriers are not specified, preloaded polygon barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’), preloaded polygon barriers are ignored.
travel_mode
Travel modes provide override values that help you quickly and consistently model a vehicle or mode of transportation. The chosen travel mode must be preconfigured on the network dataset that the service area service references.
attribute_parameter_values
A set of attribute parameter values that can be parameterized to determine which network elements can be used by a vehicle.
default_breaks
A comma-separated list of doubles. The default is defined in the network analysis layer.
exclude_sources_from_polygons
A comma-separated list of string names. The default is defined in the network analysis layer.
merge_similar_polygon_ranges
If true, similar ranges will be merged in the result polygons. The default is defined in the network analysis layer.
output_lines
The type of lines(s) generated. The default is as defined in the network analysis layer. Values: esriNAOutputLineNone | esriNAOutputLineTrueShape | esriNAOutputLineTrueShapeWithMeasure
output_polygons
The type of polygon(s) generated. The default is as defined in the network analysis layer.
overlap_lines
Indicates if the lines should overlap from multiple facilities. The default is defined in the network analysis layer.
overlap_polygons
Indicates if the polygons for all facilities should overlap. The default is defined in the network analysis layer.
splitLines_at_breaks
If true, lines will be split at breaks. The default is defined in the network analysis layer.
split_polygons_at_breaks
If true, polygons will be split at breaks. The default is defined in the network analysis layer.
trim_outer_polygon
If true, the outermost polygon (at the maximum break value) will be trimmed. The default is defined in the network analysis layer.
trim_polygon_distance
If polygons are being trimmed, provides the distance to trim. The default is defined in the network analysis layer.
trim_polygon_distance_units
If polygons are being trimmed, specifies the units of the trimPolygonDistance. The default is defined in the network analysis layer.
return_facilities
If true, facilities will be returned with the analysis results. Default is false.
return_barriers
If true, barriers will be returned with the analysis results. Default is false.
return_polyline_barriers
If true, polyline barriers will be returned with the analysis results. Default is false.
return_polygon_barriers
If true, polygon barriers will be returned with the analysis results. Default is false.
out_sr
The well-known ID of the spatial reference for the geometries returned with the analysis results. If outSR is not specified, the geometries are returned in the spatial reference of the map.
accumulate_attribute_names
The list of network attribute names to be accumulated with the analysis. The default is as defined in the network analysis layer. The value should be specified as a comma separated list of attribute names. You can also specify a value of none to indicate that no network attributes should be accumulated.
impedance_attribute_name
The network attribute name to be used as the impedance attribute in analysis. The default is as defined in the network analysis layer.
restriction_attribute_names
The list of network attribute names to be used as restrictions with the analysis. The default is as defined in the network analysis layer. The value should be specified as a comma separated list of attribute names. You can also specify a value of none to indicate that no network attributes should be used as restrictions.
restrict_u_turns
Specifies how U-Turns should be restricted in the analysis. The default is as defined in the network analysis layer. Values: esriNFSBAllowBacktrack | esriNFSBAtDeadEndsOnly | esriNFSBNoBacktrack | esriNFSBAtDeadEndsAndIntersections
output_geometry_precision
The precision of the output geometry after generalization. If 0, no generalization of output geometry is performed. The default is as defined in the network service configuration.
output_geometry_precision_units
The units of the output geometry precision. The default value is esriUnknownUnits. Values: esriUnknownUnits | esriCentimeters | esriDecimalDegrees | esriDecimeters | esriFeet | esriInches | esriKilometers | esriMeters | esriMiles | esriMillimeters | esriNauticalMiles | esriPoints | esriYards
use_hierarchy
If true, the hierarchy attribute for the network should be used in analysis. The default is as defined in the network layer. This cannot be used in conjunction with outputLines.
time_of_day
The date and time at the facility. If travelDirection is set to esriNATravelDirectionToFacility, the timeOfDay value specifies the arrival time at the facility. if travelDirection is set to esriNATravelDirectionFromFacility, the timeOfDay value is the departure time from the facility. The time zone for timeOfDay is specified by timeOfDayIsUTC.
time_of_day_is_utc
The time zone or zones of the timeOfDay parameter. When set to false, which is the default value, the timeOfDay parameter refers to the time zone or zones in which the facilities are located. Therefore, the start or end times of the service areas are staggered by time zone.
travel_direction
Options for traveling to or from the facility. The default is defined in the network analysis layer. Values: esriNATravelDirectionFromFacility |
esriNATravelDirectionToFacility
return_z
If true, Z values will be included in saPolygons and saPolylines geometry if the network dataset is Z-aware. The default is false.
overrides
Optional dictionary. Specify additional settings that can influence the behavior of the solver. A list of supported override settings for each solver and their acceptable values can be obtained by contacting Esri Technical Support.
preserve_objectid
Optional Boolean. If True, all objectid values are maintained. The default is False.
future
Optional boolean. If True, a future object will be returned and the process will not wait for the task to complete. The default is False, which means wait for results.
ignore_invalid_locations
If true, the solver will ignore invalid locations. Otherwise, it will raise an error. Default is true.
geometry_precision
Optional Integer. Use this parameter to specify the number of decimal places in the response geometries returned by solve operation. This applies to x/y values only (not m- or z-values).
geometry_precision_z
Optional Integer. Use this parameter to specify the number of decimal places in the response geometries returned by solve operation. This applies to z values only.
geometry_precision_m
Optional Integer. Use this parameter to specify the number of decimal places in the response geometries returned by solve operation. This applies to m values only.
locate_settings
Optional dictionary containing additional input location settings. Use this parameter to specify settings that affect how inputs are located, such as the maximum search distance to use when locating the inputs on the network or the network sources being used for locating. To restrict locating on a portion of the source, you can specify a where clause for a source.
The dictionary of parameters can be assigned to the ‘default’, or to the ‘overrides’ key which holds the dictionary of parameters for each override, types of override are ‘facilities’, ‘barriers’, ‘polylineBarriers’, ‘polygonBarriers’. Use the
LocateSettings
class to create the dictionary for each override or for the default.Note
‘default’ has to be present if you want to pass in any locate_settings to the service. In addition, locate settings for default have to be complete, meaning all properties need to be present. For each override, the keys do not have to be complete.
Note
for ‘polylineBarriers’ and ‘polygonBarriers’, tolerance and tolerance_units are not supported.
from arcgis.network import LocateSettings locate_settings = LocateSettings(tolerance=5000, tolerance_units=ToleranceUnits.meters, allow_auto_relocate=True, sources=[{"name": "Routing_Streets"}]) result = route_layer.solve(stops=stops, locate_settings={"default": locate_settings.to_dict()})
return_empty_results
Optional boolean. If True, the service will return empty results instead of the error property when the request fails. The default is False.
include_source_information_on_lines
Optional boolean. Specify whether the service will include network source fields on the output saPolylines. Source fields on saPolylines are SourceID, SourceOID, FromPosition and ToPosition.
true—The saPolylines property in the JSON response will include network source fields.
false—The saPolylines property in the JSON response will not include network source fields.
The default value is true.
Setting this parameter has no effect if output_lines is set to esriNAOutputLineNone. You can set this to false if you don’t need network source fields on saPolylines and this will reduce the response size.
-
ClosestFacilityLayer¶
-
class
arcgis.network.
ClosestFacilityLayer
(url, gis=None)¶ The Closest Facility Network Layer which has common properties of Network Layer as well as some attributes unique to Closest Facility Layer only.
-
solve_closest_facility
(incidents, facilities, barriers=None, polyline_barriers=None, polygon_barriers=None, travel_mode=None, attribute_parameter_values=None, return_directions=False, directions_language=None, directions_style_name=None, directions_length_units=None, directions_time_attribute_name=None, return_cf_routes=True, return_facilities=False, return_incidents=False, return_barriers=False, return_polyline_barriers=False, return_polygon_barriers=False, output_lines=None, default_cutoff=None, default_target_facility_count=None, travel_direction=None, out_sr=None, accumulate_attribute_names=None, impedance_attribute_name=None, restriction_attribute_names=None, restrict_u_turns=None, use_hierarchy=True, output_geometry_precision=None, output_geometry_precision_units=None, time_of_day=None, time_of_day_is_utc=None, time_of_day_usage=None, return_z=False, overrides=None, preserve_objectid=False, future=False, ignore_invalid_locations=True, directions_output_type=None, return_traversed_edges=None, return_traversed_junctions=None, return_traversed_turns=None, geometry_precision=None, geometry_precision_z=None, geometry_precision_m=None, locate_settings=None, return_empty_results=False)¶ The solve operation is performed on a network layer resource of type closest facility (layerType is esriNAServerClosestFacilityLayer). You can provide arguments to the solve route operation as query parameters.
Parameter
Description
facilities
The set of facilities loaded as network locations during analysis. Facilities can be specified using a simple comma / semi-colon based syntax or as a JSON structure. If facilities are not specified, preloaded facilities from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded facilities are ignored.
incidents
The set of incidents loaded as network locations during analysis. Incidents can be specified using a simple comma / semi-colon based syntax or as a JSON structure. If incidents are not specified, preloaded incidents from the map document are used in the analysis.
barriers
The set of barriers loaded as network locations during analysis. Barriers can be specified using a simple comma / semi-colon based syntax or as a JSON structure. If barriers are not specified, preloaded barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded barriers are ignored.
polyline_barriers
The set of polyline barriers loaded as network locations during analysis. If polyline barriers are not specified, preloaded polyline barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded polyline barriers are ignored.
polygonBarriers
The set of polygon barriers loaded as network locations during analysis. If polygon barriers are not specified, preloaded polygon barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded polygon barriers are ignored.
travel_mode
Travel modes provide override values that help you quickly and consistently model a vehicle or mode of transportation. The chosen travel mode must be preconfigured on the network dataset that the routing service references.
attribute_parameter_values
A set of attribute parameter values that can be parameterized to determine which network elements can be used by a vehicle.
return_directions
If true, directions will be generated and returned with the analysis results. Default is false.
directions_language
The language to be used when computing directions. The default is the language of the server’s operating system. The list of supported languages can be found in REST layer description.
directions_output_type
Defines content, verbosity of returned directions. The default is esriDOTStandard. Values: esriDOTComplete | esriDOTCompleteNoEvents | esriDOTInstructionsOnly | esriDOTStandard | esriDOTSummaryOnly
directions_style_name
The style to be used when returning the directions. The default is as defined in the network layer. The list of supported styles can be found in REST layer description.
directions_length_units
The length units to use when computing directions. The default is as defined in the network layer. Values: esriNAUFeet | esriNAUKilometers | esriNAUMeters | esriNAUMiles | esriNAUNauticalMiles | esriNAUYards | esriNAUUnknown
directions_time_attribute_name
The name of network attribute to use for the drive time when computing directions. The default is as defined in the network layer.
return_cf_routes
If true, closest facilities routes will be returned with the analysis results. Default is true.
return_facilities
If true, facilities will be returned with the analysis results. Default is false.
return_incidents
If true, incidents will be returned with the analysis results. Default is false.
return_barriers
If true, barriers will be returned with the analysis results. Default is false.
return_polyline_barriers
If true, polyline barriers will be returned with the analysis results. Default is false.
return_polygon_barriers
If true, polygon barriers will be returned with the analysis results. Default is false.
output_lines
The type of output lines to be generated in the result. The default is as defined in the network layer. Values: esriNAOutputLineTrueShape | esriNAOutputLineTrueShapeWithMeasure | esriNAOutputLineStraight | esriNAOutputLineNone
default_cutoff
The default cutoff value to stop traversing.
default_target_facility_count
The default number of facilities to find.
travel_direction
Options for traveling to or from the facility. The default is defined in the network layer. Values: esriNATravelDirectionFromFacility | esriNATravelDirectionToFacility
out_sr
The spatial reference of the geometries returned with the analysis results.
accumulate_attribute_names
The list of network attribute names to be accumulated with the analysis. The default is as defined in the network layer. The value should be specified as a comma separated list of attribute names. You can also specify a value of none to indicate that no network attributes should be accumulated.
impedance_attribute_name
The network attribute name to be used as the impedance attribute in analysis. The default is as defined in the network layer.
restriction_attribute_names
The list of network attribute names to be used as restrictions with the analysis. The default is as defined in the network layer. The value should be specified as a comma separated list of attribute names. You can also specify a value of none to indicate that no network attributes should be used as restrictions.
restrict_u_turns
Specifies how U-Turns should be restricted in the analysis. The default is as defined in the network layer. Values: esriNFSBAllowBacktrack | esriNFSBAtDeadEndsOnly | esriNFSBNoBacktrack | esriNFSBAtDeadEndsAndIntersections
use_hierarchy
If true, the hierarchy attribute for the network should be used in analysis. The default is as defined in the network layer.
output_geometry_precision
The precision of the output geometry after generalization. If 0, no generalization of output geometry is performed. The default is as defined in the network service configuration.
output_geometry_precision_units
The units of the output geometry precision. The default value is esriUnknownUnits. Values: esriUnknownUnits | esriCentimeters | esriDecimalDegrees | esriDecimeters | esriFeet | esriInches | esriKilometers | esriMeters | esriMiles | esriMillimeters | esriNauticalMiles | esriPoints | esriYards
time_of_day
Arrival or departure date and time. Values: specified by number of milliseconds since midnight Jan 1st, 1970, UTC.
time_of_day_is_utc
The time zone of the timeOfDay parameter. By setting timeOfDayIsUTC to true, the timeOfDay parameter refers to Coordinated Universal Time (UTC). Choose this option if you want to find what’s nearest for a specific time, such as now, but aren’t certain in which time zone the facilities or incidents will be located.
time_of_day_usage
Defines the way timeOfDay value is used. The default is as defined in the network layer. Values: esriNATimeOfDayUseAsStartTime | esriNATimeOfDayUseAsEndTime
return_z
If true, Z values will be included in the returned routes and compressed geometry if the network dataset is Z-aware. The default is false.
overrides
Optional dictionary. Specify additional settings that can influence the behavior of the solver. A list of supported override settings for each solver and their acceptable values can be obtained by contacting Esri Technical Support.
preserve_objectid
Optional Boolean. If True, all objectid values are maintained. The default is False.
future
Optional boolean. If True, a future object will be returned and the process will not wait for the task to complete. The default is False, which means wait for results.
ignore_invalid_locations
If true, the solver will ignore invalid locations. Otherwise, it will raise an error. Default is true.
return_traversed_edges
Optional boolean. Specify whether traversed edges will be returned by the service.
return_traversed_junctions
Optional boolean. Specify whether traversed junctions will be returned by the service.
return_traversed_turns
Optional boolean. Specify whether traversed turns will be returned by the service.
geometry_precision
Optional Integer. Use this parameter to specify the number of decimal places in the response geometries returned by solve operation. This applies to x/y values only (not m- or z-values).
geometry_precision_z
Optional Integer. Use this parameter specify the number of decimal places in the response geometries returned by solve operation. This applies to z-value only.
geometry_precision_m
Optional Integer. Use this parameter to specify the number of decimal places in the response geometries returned by solve operation. This applies to m-value only.
locate_settings
Optional dictionary containing additional input location settings. Use this parameter to specify settings that affect how inputs are located, such as the maximum search distance to use when locating the inputs on the network or the network sources being used for locating. To restrict locating on a portion of the source, you can specify a where clause for a source.
The dictionary of parameters can be assigned to the ‘default’, or to the ‘overrides’ key which holds the dictionary of parameters for each override, types of override are ‘incidents’, ‘facilities’, ‘barriers’, ‘polylineBarriers’, ‘polygonBarriers’. Use the
LocateSettings
class to create the dictionary for each override or for the default.Note
‘default’ has to be present if you want to pass in any locate_settings to the service. In addition, locate settings for default have to be complete, meaning all properties need to be present. For each override, the keys do not have to be complete.
Note
for ‘polylineBarriers’ and ‘polygonBarriers’, tolerance and tolerance_units are not supported.
from arcgis.network import LocateSettings locate_settings = LocateSettings(tolerance=5000, tolerance_units=ToleranceUnits.meters, allow_auto_relocate=True, sources=[{"name": "Routing_Streets"}]) result = route_layer.solve(stops=stops, locate_settings={"default": locate_settings.to_dict()})
return_empty_results
Optional boolean. If True, the service will return empty results instead of the error property when the request fails. The default is False.
-
NetworkDataset¶
-
class
arcgis.network.
NetworkDataset
(url, gis=None)¶ A network dataset containing a collection of network layers including route layers, service area layers and closest facility layers.
-
property
closest_facility_layers
¶ List of closest facility layers in this network dataset
-
classmethod
fromitem
(item)¶ Creates a network dataset from a ‘Network Analysis Service’ Item in the GIS
-
property
od_cost_matrix_layers
¶ List of OD Cost Matrix Layers
- Returns
List
-
property
route_layers
¶ List of route layers in this network dataset
-
property
service_area_layers
¶ List of service area layers in this network dataset
-
property
NetworkDatasetLayer¶
-
class
arcgis.network.
NetworkDatasetLayer
(url, gis=None)¶ The network dataset layer resource represents a single network dataset layer in routing services published by ArcGIS Server. It provides basic information about the network dataset layer, such as its name, type, locate settings, travel modes, and other information as in the JSON syntax below. It also provides information about the network dataset, such as name build time, build state, network attributes and, network sources.
Note
This is only available for ArcGIS Enterprise 11.1+
-
locate
(input_locations, travel_mode=None, locate_settings=None, barriers=None, polyline_barriers=None, polygon_barriers=None, return_barriers=False, return_polyline_barriers=False, return_polygon_barriers=False, output_source_field_names=None, out_sr=None, future=False)¶ When performing analysis using routing services, the inputs to an analysis rarely fall exactly on top of the edges or junctions of the network dataset the service is using. For example, you may be using a network dataset constructed from street centerline to power your routing services, and the input points you want to analyze are the centroids of parcels in your city. These parcel centroids do not fall on top of the street centerline; rather, they are offset some distance from the streets. To successfully perform a network analysis using your routing services, the routing services must identify the location on the network dataset where each analysis input lies. This network location, rather than the input’s original location, is used in the analysis. Typically, the longitude and latitude of the inputs are passed in and the routing services compute the location on the network during the solve operation. With the locate service, you can compute the locations on the network before calling the solve operation.
The locate service is performed on a network dataset layer resource. You can provide arguments to the locate service as query parameters defined in the parameters table below. The locate service can be used in scenarios such as the following:
Reuse location fields during the solve operation - You have a set of regularly serviced customers. You can use the locate service to calculate location fields, and use the located inputs in the routing services. This helps to speed up routing services since the service doesn’t need to locate inputs again and you can reuse the locations in multiple places.
Note
The settings and barriers you use to locate inputs should match the eventual analysis settings when you perform routing service; otherwise, the routing services may still relocate because the locations are not valid for a different travel mode or with barriers.
Compute serviceability - Before you perform a routing request, you can call locate to determine serviceability. For example, the mode of travel may only allow service inputs that are 500 meters off the streets. You can perform a locate service with 500 meters as the search tolerance and determine which inputs cannot be serviced before you perform a more advanced routing service.
Use DistanceToNetworkInMeters to calculate service time - You can gain information from the locate service response to fine-tune your routing service settings. For example, if you want to know how far each input is off network to perform delivery analysis, and it takes time to go from the parked vehicle location to the delivery location, you can use the DistanceToNetworkInMeters field for each record in the response. Once you know how far away the actual location is from the network, you can use a speed factor to calculate a service time for each input based on its distance off the network.
Query fields from the underlying source features -The locate service also supports returning additional field values from the source features where the inputs are located. For example, you can set different curb approaches on the inputs depending on the type of road on which they’re located. If the input is located on a major road, you can set it to right or left side of the vehicle, depending on the driving side of the country where it’s located. If the input is located on a local road, either side of curb approach will work since a vehicle can cross a local road for a delivery.
Parameter
Description
input_locations
Required FeatureSet, list of Point geometries, or a comma separated string. To see the fields that can be included in your Feature Set refer to the Locate Service doc.
travel_mode
Optional string. Travel modes provide override values that help you quickly and consistently model a vehicle or mode of transportation. The chosen travel mode must be pre-configured on the network dataset that the routing service references.
locate_settings
Optional dictionary containing additional input location settings. Use this parameter to specify settings that affect how inputs are located, such as the maximum search distance to use when locating the inputs on the network or the network sources being used for locating. To restrict locating on a portion of the source, you can specify a where clause for a source.
The dictionary of parameters can be assigned to the ‘default’, or to the ‘overrides’ key which holds the dictionary of parameters for each override, types of override are ‘inputLocations’, ‘barriers’, ‘polylineBarriers’, ‘polygonBarriers’. Use the
LocateSettings
class to create the dictionary for each override or for the default.Note
‘default’ has to be present if you want to pass in any locate_settings to the service. In addition, locate settings for default have to be complete, meaning all properties need to be present. For each override, the keys do not have to be complete.
Note
for ‘polyline_barriers’ and ‘polygon_barriers’, tolerance and tolerance_units are not supported.
# Usage Example: >>> from arcgis.network import LocateSettings >>> locate_settings = LocateSettings( tolerance=5000, tolerance_units=ToleranceUnits.meters, allow_auto_relocate=True, sources=[ {"name": "Routing_Streets"} ] ) >>> result = route_layer.solve( stops=stops, locate_settings={ "default": locate_settings.to_dict() } )
barriers
Optional Point/FeatureSet. The set of barriers loaded as network locations during analysis. Barriers can be specified using a simple comma/semi-colon based syntax or as a JSON structure. If barriers are not specified, preloaded barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded barriers are ignored.
polyline_barriers
Optional Polyline/FeatureSet. The set of polyline barriers loaded as network locations during analysis. If polyline barriers are not specified, preloaded polyline barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded polyline barriers are ignored.
polygon_barriers
Optional Polygon/FeatureSet. The set of polygon barriers loaded as network locations during analysis. If polygon barriers are not specified, preloaded polygon barriers from the map document are used in the analysis. If an empty json object is passed (‘{}’) preloaded polygon barriers are ignored.
return_barriers
Optional boolean. If true, barriers will be returned with the analysis results. Default is False.
return_polyline_barriers
Optional boolean. If true, polyline barriers will be returned with the analysis results. Default is False.
return_polygon_barriers
Optional boolean. If true, polygon barriers will be returned with the analysis results. Default is False.
output_source_field_names
Optional string.The fields from which the located source feature values will be retrieved. This parameter is specified as a comma-separated list of names. The values can be specified as in the example below:
outputSourceFieldNames=ROAD_CLASS,FULL_STREET_NAME
Note
These value are specific to the services published with the ArcGIS StreetMap Premium data. The values will be different if you are using other data for the analysis.
out_sr
Optional Integer. Specify the spatial reference of the geometries.
future
Optional boolean. If True, a future object will be returned and the process will not wait for the task to complete. The default is False, which means wait for results.
- Returns
Dictionary
-
ODCostMatrixLayer¶
-
class
arcgis.network.
ODCostMatrixLayer
(url, gis=None)¶ OD Cost Matrix Layer is part of the Network Layer services. It allows users to generate cost matrix data for a given set of input.
-
retrieve_travel_modes
()¶ Identify all the valid travel modes that have been defined on the network dataset or in the portal if the GIS server is federated
- Returns
Dictionary
-
solve_od_cost_matrix
(origins, destinations, default_cutoff=None, default_target_destination_count=None, travel_mode=None, output_type='Sparse Matrix', time_of_day=None, time_of_day_is_utc=None, barriers=None, polyline_barriers=None, polygon_barriers=None, impedance_attribute_name=None, accumulate_attribute_names=None, restriction_attribute_names=None, attribute_parameter_values=None, restrict_u_turns=None, use_hierarchy=True, return_origins=False, return_destinations=False, return_barriers=False, return_polyline_barriers=False, return_polygon_barriers=False, out_sr=None, ignore_invalid_locations=True, return_z=False, overrides=None, future=False, geometry_precision=None, geometry_precision_z=None, locate_settings=None, return_empty_results=False)¶ The Origin Destination Cost Matrix service helps you to create an origin-destination (OD) cost matrix from multiple origins to multiple destinations. An Origin Destination Cost Matrix is a table that contains the cost, such as the travel time or travel distance, from every origin to every destination. Additionally, it ranks the destinations that each origin connects to in ascending order based on the minimum cost required to travel from that origin to each destination. When generating an OD Cost Matrix, you can optionally specify the maximum number of destinations to find for each origin and the maximum time or distance to travel when searching for destinations.
The results from the Origin Destination Cost Matrix service often become input for other spatial analyses where the cost to travel on the street network is more appropriate than straight-line cost.
The travel time and/or distance for each origin-destination pair is stored in the output matrix (default) or as part of the attributes of the output lines, which can have no shapes or a straight line shape. Even though the lines are straight, they always store the travel time and/or travel distance based on the street network, not based on Euclidean distance.
Parameter
Description
origins
Required FeatureLayer/SeDF/FeatureSet. Specifies the starting points from which to travel to the destinations.
destinations
Required FeatureLayer/SeDF/FeatureSet. Specifies the ending point locations to travel to from the origins.
default_cutoff
Optional Float. Specify the travel time or travel distance value at which to stop searching for destinations. The default value is None which means to search until all destinations are found for every origin. The units are the same as the impedance attribute units.
default_target_destination_count
Optional Integer. Specify the number of destinations to find per origin. The default value is None which means to search until all destinations are found for every origin.
travel_mode
Optional String. Choose the mode of transportation for the analysis.
output_type
Optional String. Specify the type of output returned by the service. Allowed value: Sparse Matrix (default), Straight Lines, or No Lines.
time_of_day
Optional Datetime. The time_of_day value represents the time at which the travel begins from the input origins. If a value of now is passed, the travel begins at current time.
time_of_day_is_utc
Optional Boolean. Specify the time zone or zones of the time_of_day parameter. The default is as defined in the network layer.
barriers
Optional FeatureLayer/SeDF/FeatureSet. Specify one or more points that act as temporary restrictions or represent additional time or distance that may be required to travel on the underlying streets.
polyline_barriers
Optional FeatureLayer/SeDF/FeatureSet. Specify one or more lines that prohibit travel anywhere the lines intersect the streets.
polygon_barriers
Optional FeatureLayer/SeDF/FeatureSet. Specify polygons that either prohibit travel or proportionately scale the time or distance required to travel on the streets intersected by the polygons.
impedance_attribute_name
Optional String. Specify the impedance. The default is as defined in the network layer.
accumulate_attribute_names
Optional String. Specify whether the service should accumulate values other than the value specified for impedance_attribute_names.
The default is as defined in the network layer. The parameter value should be specified as a comma-separated list of names.
restriction_attribute_names
Optional String. Specify which restrictions should be honored by the service.
attribute_parameter_values
Optional String. Specify additional values required by an attribute or restriction.
restrict_u_turns
Optional String. Restrict or permit the route from making U-turns at junctions. The default is as defined in the network layer.
Values:
esriNFSBAllowBacktrack
esriNFSBAtDeadEndsOnly
esriNFSBNoBacktrack
esriNFSBAtDeadEndsAndIntersections
use_hierarchy
Optional Boolean. Specify whether hierarchy should be used when finding the shortest paths. The default value is true.
return_origins
Optional Boolean. Specify whether origins will be returned by the service. The default value is false.
return_destinations
Optional Boolean. Specify whether origins will be returned by the service. The default value is false.
return_barriers
Optional Boolean. Specify whether barriers will be returned by the service. The default value is false.
return_polyline_barriers
Optional Boolean. Specify whether polyline barriers will be returned by the service. The default value is false.
return_polygon_barriers
Optional Boolean. Specify whether polygon barriers will be returned by the service. The default value is false.
out_sr
Optional Integer. Specify the spatial reference of the geometries.
ignore_invalid_locations
Optional Boolean. Specify whether invalid input locations should be ignored when finding the best solution. The default is True.
return_z
Optional Boolean. Include z values for the returned geometries if supported by the underlying network. The default value is false.
overrides
Optional Dict. Specify additional settings that can influence the behavior of the solver.
future
Optional boolean. If True, a future object will be returned and the process will not wait for the task to complete. The default is False, which means wait for results.
geometry_precision
Optional Integer. Use this parameter to specify the number of decimal places in the response geometries returned by solve operation. This applies to x/y values only (not m- or z-values).
geometry_precision_z
Optional Integer. Use this parameter specify the number of decimal places in the response geometries returned by solve operation. This applies to z-value only.
locate_settings
Optional dictionary containing additional input location settings. Use this parameter to specify settings that affect how inputs are located, such as the maximum search distance to use when locating the inputs on the network or the network sources being used for locating. To restrict locating on a portion of the source, you can specify a where clause for a source.
The dictionary of parameters can be assigned to the ‘default’, or to the ‘overrides’ key which holds the dictionary of parameters for each override, types of override are ‘origins’, ‘destinations’, ‘barriers’, ‘polylineBarriers’, ‘polygonBarriers’. Use the
LocateSettings
class to create the dictionary for each override or for the default.Note
‘default’ has to be present if you want to pass in any locate_settings to the service. In addition, locate settings for default have to be complete, meaning all properties need to be present. For each override, the keys do not have to be complete.
Note
for ‘polylineBarriers’ and ‘polygonBarriers’, tolerance and tolerance_units are not supported.
# Usage example: >>> from arcgis.network import LocateSettings >>> locate_settings = LocateSettings( tolerance=5000, tolerance_units=ToleranceUnits.meters, allow_auto_relocate=True, sources=[ {"name": "Routing_Streets"} ] ) >>> result = route_layer.solve( stops=stops, locate_settings={ "default": locate_settings.to_dict() } )
return_empty_results
Optional boolean. If True, the service will return empty results instead of the error property when the request fails. The default is False.
- Returns
Dictionary or NAJob when future=True
-
LocateSettings¶
-
class
arcgis.network.
LocateSettings
(tolerance, tolerance_units, allow_auto_relocate, sources)¶ Parameters available for locate settings that can be passed to the solve operation. See locateSettings for full descriptions.
Parameter
Description
tolerance
Allows you to control the maximum search distance when locating inputs. If no valid network location is found within this distance, the input features will be considered unlocated. A small search tolerance decreases the likelihood of locating on the wrong street but increases the likelihood of not finding any valid network location.
tolerance_units
Argument should be specified as one of
ToleranceUnits
allow_auto_relocate
Allows you to control whether inputs with existing network location fields can be automatically relocated to ensure valid, routable location fields for the analysis.
sources
Allows you to control which network source can be used for locating. For example, you can configure the analysis to locate inputs on streets but not on sidewalks. The list of possible sources on which to locate is specific to the network dataset this service references.
# Usage Example: >>> locate_settings = LocateSettings( tolerance=5000, tolerance_units=ToleranceUnits.meters, allow_auto_relocate=True, sources=[ {"name": "Routing_Streets"} ] )
-
allow_auto_relocate
: bool¶
-
sources
: list[dict[str, Any]] | None¶
-
to_dict
()¶
-
tolerance
: float¶
-
tolerance_units
: str | ToleranceUnits¶
-
publish_routing_services¶
-
arcgis.network.
publish_routing_services
(datastore, path, server_id=None, folder=None, solver_types=<SolverType.ALL: ['ClosestFacility', 'Location-Allocation', 'OriginDestinationCostMatrix', 'Route', 'ServiceArea', 'VehicleRoutingProblem']>, config=None, gis=None)¶ Parameter
Description
datastore
Required Item. The registered datastore where the network dataset resides.
path
Required String. The relative path to the network dataset in the data store.
server_id
Required String. The unique ID of the server to publish the dataset to.
folder
Optional String. The name for the server folder that will contain all the routing services created by this service. The service returns an error if the folder contains existing services. The default value is Routing
solver_types
Optional
SolverType
. The list of Network Analyst solvers to be included in the services. The default is to include all the solvers.config
Optional str. The file containing additional configuration for the services. If no value is specified, the system default configuration file is used. For a full list of config values and explanation, please reach out to support@esri.com.
gis
Optional GIS. The GIS object where the dataset will be hosted at. If None is provided, the datastore’s GIS will be used.
# Usage Example >>> job = publish_routing_services(datastore=gis.content.get("05cb079948f241a799651b3ac0401309"), path="/streets/NorthAmerica.gdb/Routing/Routing_ND", config=config_file, solver_types=[SolverType.ROUTE, SolverType.VEHICLEROUTINGPROBLEM], server_id=gis.servers['servers'][0]['id']) >>> type(job) <:class:`~arcgis.geoprocessing._job.GPJob>
- Returns
Enumerations¶
ToleranceUnits¶
-
class
arcgis.network.
ToleranceUnits
(value)¶ An enumeration.
-
centimeters
= 'esriCentimeters'¶
-
decimaldegrees
= 'esriDecimalDegrees'¶
-
decimeters
= 'esriDecimeters'¶
-
feet
= 'esriFeet'¶
-
inches
= 'esriInches'¶
-
intFeet
= 'esriIntFeet'¶
-
intInches
= 'esriIntInches'¶
-
intMiles
= 'esriIntMiles'¶
-
intNauticalMiles
= 'esriIntNauticalMiles'¶
-
intYards
= 'esriIntYards'¶
-
kilometers
= 'esriKilometers'¶
-
meters
= 'esriMeters'¶
-
miles
= 'esriMiles'¶
-
millimeters
= 'esriMillimeters'¶
-
nauticalMiles
= 'esriNauticalMiles'¶
-
yards
= 'esriYards'¶
-
SolverType¶
-
class
arcgis.network.
SolverType
(value)¶ An enumeration.
-
ALL
: list = ['ClosestFacility', 'Location-Allocation', 'OriginDestinationCostMatrix', 'Route', 'ServiceArea', 'VehicleRoutingProblem']¶
-
CLOSESTFACILITY
: str = 'ClosestFacility'¶
-
LOCATIONALLOCATION
: str = 'Location-Allocation'¶
-
ORIGINDESTINATIONCOSTMATRIX
: str = 'OriginDestinationCostMatrix'¶
-
ROUTE
: str = 'Route'¶
-
SERVICEAREA
: str = 'ServiceArea'¶
-
VEHICLEROUTINGPROBLEM
: str = 'VehicleRoutingProblem'¶
-