arcgis.network module
The arcgis.network module contains classes and functions for network analysis. Network layers and analysis can be usedfor operations such as finding the closest facility, the best route for a vehicle, the best routes for a fleet ofvehicles, locating facilities using location allocation, calculating an OD cost matrix, and generating service areas.
NetworkLayer
- classarcgis.network.NetworkLayer(url,gis=None,**kwargs)
NetworkLayer represents a single network layer. It provides basicinformation about the network layer such as its name, type, and networkclasses. Additionally, depending on the layer type, it provides differentpieces of information.
It is a base class for RouteLayer, ServiceAreaLayer, andClosestFacilityLayer.
RouteLayer
- classarcgis.network.RouteLayer(url,gis=None,**kwargs)
The Route Layer which has common properties of Network Layeras well as some attributes unique to Route Network Layer only.
- solve(stops:list[Point]|list[FeatureSet]|FeatureSet,barriers:Point|FeatureSet|dict[str,Any]|None=None,polyline_barriers:Polyline|FeatureSet|dict[str,Any]|None=None,polygon_barriers:Polygon|FeatureSet|dict[str,Any]|None=None,travel_mode:str|None=None,attribute_parameter_values:str|list[str]|None=None,return_directions:bool=True,return_routes:bool=True,return_stops:bool=False,return_barriers:bool=False,return_polyline_barriers:bool=False,return_polygon_barriers:bool=False,out_sr:int|None=None,ignore_invalid_locations:bool=True,output_lines:str|None=None,find_best_sequence:bool=False,preserve_first_stop:bool=True,preserve_last_stop:bool=True,use_time_windows:bool=False,start_time:str|None=None,start_time_is_utc:bool=False,accumulate_attribute_names:str|None=None,impedance_attribute_name:str|None=None,restriction_attribute_names:str|None=None,restrict_u_turns:bool|None=None,use_hierarchy:bool=True,directions_language:str|None=None,directions_output_type:str|None=None,directions_style_name:str|None=None,directions_length_units:str|None=None,directions_time_attribute_name:str|None=None,output_geometry_precision:float|None=None,output_geometry_precision_units:str|None=None,return_z:bool=False,overrides:dict[str,Any]|None=None,preserve_objectid:bool=False,future:bool=False,time_windows_are_utc:bool=False,return_traversed_edges:bool|None=None,return_traversed_junctions:bool|None=None,return_traversed_turns:bool|None=None,geometry_precision:int|None=None,geometry_precision_z:int|None=None,geometry_precision_m:int|None=None,locate_settings:dict|None=None,return_empty_results:bool|None=False)
The solve operation is performed on a network layer resource.The solve operation is supported on a network layer whose layerTypeis esriNAServerRouteLayer. You can provide arguments to the solveroute operation as query parameters.
Parameter
Description
stops
Required Points/FeatureSet/a list of Features. The set of stopsloaded as network locations during analysis. Stops can be specifiedusing a simple comma / semi-colon based syntax or as a JSONstructure. If stops are not specified, preloaded stops from the mapdocument are used in the analysis.
barriers
Optional Point/FeatureSet. The set of barriers loaded as networklocations during analysis. Barriers can be specified using a simplecomma/semi-colon based syntax or as a JSON structure. If barriersare not specified, preloaded barriers from the map document are usedin the analysis. If an empty json object is passed (‘{}’) preloadedbarriers are ignored.
polyline_barriers
Optional Polyline/FeatureSet. The set of polyline barriers loadedas network locations during analysis. If polyline barriers are notspecified, preloaded polyline barriers from the map document areused 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 asnetwork locations during analysis. If polygon barriers are notspecified, preloaded polygon barriers from the map document are usedin the analysis. If an empty json object is passed (‘{}’) preloadedpolygon barriers are ignored.
travel_mode
Optional string. Travel modes provide override values that help youquickly and consistently model a vehicle or mode of transportation.The chosen travel mode must be preconfigured on the network datasetthat the routing service references.
attribute_parameter_values
Optional string/list. A set of attribute parameter values that can beparameterized to determine which network elements can be used by avehicle.
return_directions
Optional boolean. If true, directions will be generated and returnedwith the analysis results. Default is true.
return_routes
Optional boolean. If true, routes will be returned with the analysisresults. Default is true.
return_stops
Optional boolean. If true, stops will be returned with the analysisresults. Default is false.
return_barriers
Optional boolean. If true, barriers will be returned with theanalysis results. Default is false.
return_polyline_barriers
Optional boolean. If true, polyline barriers will be returned withthe analysis results. Default is False.
return_polygon_barriers
Optional boolean. If true, polygon barriers will be returned withthe analysis results. Default is False.
out_sr
Optional Integer. The spatial reference of the geometries returnedwith the analysis results.
ignore_invalid_locations
Optional boolean. - If true, the solver will ignore invalidlocations. Otherwise, it will raise an error. Default is true.
output_lines
The type of output lines to be generated in the result. The defaultis 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 inthe optimal order. The default is as defined in the network layer.
preserve_first_stop
Optional boolean. If true, the solver should keep the first stopfixed in the sequence. The default is as defined in the networklayer.
preserve_last_stop
Optional boolean. If true, the solver should keep the last stop fixedin 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, thesolver 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 accumulatedwith the analysis. The default is as defined in the network layer.The value should be specified as a comma separated list of attributenames. You can also specify a value of none to indicate that nonetwork attributes should be accumulated.
impedance_attribute_name
Optional string. The network attribute name to be used as the impedanceattribute in analysis. The default is as defined in the network layer.
restriction_attribute_names
Optional string. -The list of network attribute names to beused as restrictions with the analysis. The default is as defined inthe network layer. The value should be specified as a commaseparated list of attribute names. You can also specify a value ofnone to indicate that no network attributes should be used asrestrictions.
restrict_u_turns
Optional boolean. Specifies how U-Turns should be restricted in theanalysis. 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 networkshould be used in analysis. The default is as defined in the networklayer.
directions_language
Optional string. The language to be used when computing directions.The default is the language of the server’s operating system. The listof 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 ofsupported 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 drivetime when computing directions. The default is as defined in the networklayer.
output_geometry_precision
Optional float. The precision of the output geometry aftergeneralization. If 0, no generalization of output geometry isperformed. The default is as defined in the network serviceconfiguration.
output_geometry_precision_units
Optional string. The units of the output geometry precision. Thedefault 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 returnedroutes and compressed geometry if the network dataset is Z-aware.The default is false.
overrides
Optional dictionary. Specify additional settings that can influencethe behavior of the solver. A list of supported override settingsfor each solver and their acceptable values can be obtained bycontacting Esri Technical Support.
preserve_objectid
Optional Boolean. If True, all objectid values are maintained. Thedefault is False.
future
Optional boolean. If True, a future object will be returned and the processwill 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 TimeWindowEndattribute 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 returnedby the service.
return_traversed_junctions
Optional boolean. Specify whether traversed junctions will be returnedby the service.
return_traversed_turns
Optional boolean. Specify whether traversed turns will be returnedby the service.
geometry_precision
Optional Integer. Use this parameter to specify the number of decimalplaces in the response geometries returned by solve operation. Thisapplies to x/y values only (not m- or z-values).
geometry_precision_z
Optional Integer. Use this parameter specify the number of decimal placesin the response geometries returned by solve operation. This applies toz-value only.
geometry_precision_m
Optional Integer. Use this parameter to specify the number of decimalplaces 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 thenetwork or the network sources being used for locating. To restrict locatingon 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 orfor the default.Note
‘default’ has to be present if you want to pass in any locate_settings to theservice. In addition, locate settings for default have to be complete, meaningall 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 arenot supported.
fromarcgis.networkimportLocateSettingslocate_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 resultsinstead of the error property when the request fails. The defaultis False.
- Returns:
dict
# USAGE EXAMPLE: Solving the routing problem by passing in a FeatureSet# get a FeatureSet through queryfl=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 FeatureSetresult=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
- classarcgis.network.ServiceAreaLayer(url,gis=None,**kwargs)
The Service Area Layer which has common properties of NetworkLayer as well as some attributes unique to Service Area Layeronly.
- solve_service_area(facilities:FeatureSet|Point|list|dict,barriers:Point|FeatureSet|dict[str,Any]|None=None,polyline_barriers:Polyline|FeatureSet|dict[str,Any]|None=None,polygon_barriers:Polygon|FeatureSet|dict[str,Any]|None=None,travel_mode:str|None=None,attribute_parameter_values:str|list|None=None,default_breaks:list[float]|None=None,exclude_sources_from_polygons:list[str]|None=None,merge_similar_polygon_ranges:bool|None=None,output_lines:str|None=None,output_polygons:str|None=None,overlap_lines:str|None=None,overlap_polygons:str|None=None,split_lines_at_breaks:bool|None=None,split_polygons_at_breaks:bool|None=None,trim_outer_polygon:bool|None=None,trim_polygon_distance:str|int|None=None,trim_polygon_distance_units:str|None=None,return_facilities:bool=False,return_barriers:bool=False,return_polyline_barriers:bool=False,return_polygon_barriers:bool=False,out_sr:int|None=None,accumulate_attribute_names:list[str]|None=None,impedance_attribute_name:str|None=None,restriction_attribute_names:list[str]|None=None,restrict_u_turns:str|None=None,output_geometry_precision:int|None=None,output_geometry_precision_units:str='esriUnknownUnits',use_hierarchy:bool|None=None,time_of_day:datetime|None=None,time_of_day_is_utc:bool|None=None,travel_direction:str|None=None,return_z:bool=False,overrides:dict[str,Any]|None=None,preserve_objectid:bool=False,future:bool=False,ignore_invalid_locations:bool=True,geometry_precision:int|None=None,geometry_precision_z:int|None=None,geometry_precision_m:int|None=None,locate_settings:dict[str,Any]|None=None,return_empty_results:bool|None=False,include_source_information_on_lines:bool|None=True)
The solve service area operation is performed on a network layerresource of type service area (layerType is esriNAServerServiceArea).You can provide arguments to the solve service area operation asquery parameters.
Parameter
Description
facilities
The set of facilities loaded as network locationsduring analysis. Facilities can be specified usinga simple comma / semi-colon based syntax or as aJSON structure. If facilities are not specified,preloaded facilities from the map document are usedin the analysis. If an empty json object is passed(‘{}’) preloaded facilities are ignored.
barriers
The set of barriers loaded as network locations duringanalysis. Barriers can be specified using a simplecomma/semicolon-based syntax or as a JSON structure.If barriers are not specified, preloaded barriers fromthe map document are used in the analysis. If an emptyjson object is passed (‘{}’), preloaded barriers areignored.
polyline_barriers
The set of polyline barriers loaded as networklocations during analysis. If polyline barriersare not specified, preloaded polyline barriersfrom 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 networklocations during analysis. If polygon barriersare not specified, preloaded polygon barriersfrom 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 youquickly and consistently model a vehicle or mode oftransportation. The chosen travel mode must bepreconfigured on the network dataset that theservice area service references.
attribute_parameter_values
A set of attribute parameter values thatcan be parameterized to determine whichnetwork elements can be used by a vehicle.
default_breaks
A comma-separated list of doubles. The default isdefined 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 asdefined in the network analysis layer.Values: esriNAOutputLineNone | esriNAOutputLineTrueShape |esriNAOutputLineTrueShapeWithMeasure
output_polygons
The type of polygon(s) generated. The default isas defined in the network analysis layer.
overlap_lines
Indicates if the lines should overlap from multiplefacilities. The default is defined in the networkanalysis layer.
overlap_polygons
Indicates if the polygons for all facilitiesshould overlap. The default is defined in thenetwork analysis layer.
splitLines_at_breaks
If true, lines will be split at breaks. Thedefault is defined in the network analysislayer.
split_polygons_at_breaks
If true, polygons will be split at breaks.The default is defined in the networkanalysis layer.
trim_outer_polygon
If true, the outermost polygon (at the maximumbreak value) will be trimmed. The default isdefined in the network analysis layer.
trim_polygon_distance
If polygons are being trimmed, provides thedistance to trim. The default is defined inthe network analysis layer.
trim_polygon_distance_units
If polygons are being trimmed, specifiesthe units of the trimPolygonDistance. Thedefault is defined in the network analysislayer.
return_facilities
If true, facilities will be returned with theanalysis results. Default is false.
return_barriers
If true, barriers will be returned with the analysisresults. Default is false.
return_polyline_barriers
If true, polyline barriers will be returnedwith the analysis results. Default is false.
return_polygon_barriers
If true, polygon barriers will be returnedwith the analysis results. Default is false.
out_sr
The well-known ID of the spatial reference for the geometriesreturned 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 beaccumulated with the analysis. The defaultis as defined in the network analysis layer.The value should be specified as a commaseparated list of attribute names. You canalso specify a value of none to indicate thatno network attributes should be accumulated.
impedance_attribute_name
The network attribute name to be used as theimpedance attribute in analysis. The defaultis as defined in the network analysis layer.
restriction_attribute_names
The list of network attribute names to beused as restrictions with the analysis. Thedefault is as defined in the network analysislayer. The value should be specified as acomma separated list of attribute names.You can also specify a value of none toindicate that no network attributes shouldbe used as restrictions.
restrict_u_turns
Specifies how U-Turns should be restricted in theanalysis. The default is as defined in the networkanalysis layer. Values: esriNFSBAllowBacktrack |esriNFSBAtDeadEndsOnly | esriNFSBNoBacktrack |esriNFSBAtDeadEndsAndIntersections
output_geometry_precision
The precision of the output geometry aftergeneralization. If 0, no generalization ofoutput geometry is performed. The default isas 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 beused in analysis. The default is as defined in the networklayer. This cannot be used in conjunction with outputLines.
time_of_day
The date and time at the facility. If travelDirection is setto esriNATravelDirectionToFacility, the timeOfDay valuespecifies the arrival time at the facility. if travelDirectionis set to esriNATravelDirectionFromFacility, the timeOfDayvalue is the departure time from the facility. The time zonefor timeOfDay is specified by timeOfDayIsUTC.
time_of_day_is_utc
The time zone or zones of the timeOfDay parameter. Whenset to false, which is the default value, the timeOfDayparameter refers to the time zone or zones in which thefacilities are located. Therefore, the start or end timesof the service areas are staggered by time zone.
travel_direction
Options for traveling to or from the facility. Thedefault is defined in the network analysis layer.Values: esriNATravelDirectionFromFacility |
esriNATravelDirectionToFacility
return_z
If true, Z values will be included in saPolygons and saPolylinesgeometry if the network dataset is Z-aware. The default is false.
overrides
Optional dictionary. Specify additional settings that caninfluence the behavior of the solver. A list of supportedoverride settings for each solver and their acceptable valuescan be obtained by contacting Esri Technical Support.
preserve_objectid
Optional Boolean. If True, all objectid values aremaintained. The default is False.
future
Optional boolean. If True, a future object will be returned and the processwill 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 invalidlocations. Otherwise, it will raise an error.Default is true.
geometry_precision
Optional Integer. Use this parameter to specify the number of decimalplaces 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 ofdecimal 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 ofdecimal 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 thenetwork or the network sources being used for locating. To restrict locatingon 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 orfor the default.Note
‘default’ has to be present if you want to pass in any locate_settings to theservice. In addition, locate settings for default have to be complete, meaningall 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 arenot supported.
fromarcgis.networkimportLocateSettingslocate_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 insteadof 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 sourcefields on the outputsaPolylines. Source fields onsaPolylines areSourceID,SourceOID,FromPosition andToPosition.
true—ThesaPolylines property in the JSON response will include network source fields.
false—ThesaPolylines property in the JSON response will not include network source fields.
The default value is true.
Setting this parameter has no effect ifoutput_lines is set toesriNAOutputLineNone.You can set this to false if you don’t need network source fields onsaPolylinesand this will reduce the response size.
ClosestFacilityLayer
- classarcgis.network.ClosestFacilityLayer(url,gis=None,**kwargs)
The Closest Facility Network Layer which has common properties of NetworkLayer as well as some attributes unique to Closest Facility Layeronly.
- solve_closest_facility(incidents,facilities:FeatureSet|Point|list|dict,barriers:Point|FeatureSet|dict[str,Any]|None=None,polyline_barriers:Polyline|FeatureSet|dict[str,Any]|None=None,polygon_barriers:Polygon|FeatureSet|dict[str,Any]|None=None,travel_mode:str|None=None,attribute_parameter_values:str|list|None=None,return_directions:bool=False,directions_language:str|None=None,directions_style_name:str|None=None,directions_length_units:str|None=None,directions_time_attribute_name:str|None=None,return_cf_routes:bool=True,return_facilities:bool=False,return_incidents:bool=False,return_barriers:bool=False,return_polyline_barriers:bool=False,return_polygon_barriers:bool=False,output_lines:str|None=None,default_cutoff:float|None=None,default_target_facility_count:int|None=None,travel_direction:str|None=None,out_sr:int|None=None,accumulate_attribute_names:str|None=None,impedance_attribute_name:str|None=None,restriction_attribute_names:str|None=None,restrict_u_turns:str|None=None,use_hierarchy:bool=True,output_geometry_precision:str|None=None,output_geometry_precision_units:str|None=None,time_of_day:datetime|None=None,time_of_day_is_utc:str|None=None,time_of_day_usage:str|None=None,return_z:bool=False,overrides:dict[str,Any]|None=None,preserve_objectid:bool=False,future:bool=False,ignore_invalid_locations:bool=True,directions_output_type:str|None=None,return_traversed_edges:bool|None=None,return_traversed_junctions:bool|None=None,return_traversed_turns:bool|None=None,geometry_precision:int|None=None,geometry_precision_z:int|None=None,geometry_precision_m:int|None=None,locate_settings:dict|None=None,return_empty_results:bool|None=False)
The solve operation is performed on a network layer resource oftype closest facility (layerType is esriNAServerClosestFacilityLayer).You can provide arguments to the solve route operation as queryparameters.
Parameter
Description
facilities
The set of facilities loaded as network locationsduring analysis. Facilities can be specified usinga simple comma / semi-colon based syntax or as aJSON structure. If facilities are not specified,preloaded facilities from the map document are usedin the analysis. If an empty json object is passed(‘{}’) preloaded facilities are ignored.
incidents
The set of incidents loaded as network locationsduring analysis. Incidents can be specified usinga simple comma / semi-colon based syntax or as aJSON structure. If incidents are not specified,preloaded incidents from the map document are usedin the analysis.
barriers
The set of barriers loaded as network locations duringanalysis. Barriers can be specified using a simple comma/ semi-colon based syntax or as a JSON structure. Ifbarriers are not specified, preloaded barriers from themap document are used in the analysis. If an empty jsonobject is passed (‘{}’) preloaded barriers are ignored.
polyline_barriers
The set of polyline barriers loaded as networklocations during analysis. If polyline barriersare not specified, preloaded polyline barriersfrom 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 networklocations during analysis. If polygon barriersare not specified, preloaded polygon barriersfrom the map document are used in the analysis.If an empty json object is passed (‘{}’) preloadedpolygon barriers are ignored.
travel_mode
Travel modes provide override values that help youquickly and consistently model a vehicle or mode oftransportation. The chosen travel mode must bepreconfigured on the network dataset that the routingservice references.
attribute_parameter_values
A set of attribute parameter values thatcan be parameterized to determine whichnetwork elements can be used by a vehicle.
return_directions
If true, directions will be generated and returnedwith 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 operatingsystem. The list of supported languages can be foundin REST layer description.
directions_output_type
Defines content, verbosity of returneddirections. 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. Thelist of supported styles can be found in RESTlayer 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 forthe drive time when computing directions.The default is as defined in the networklayer.
return_cf_routes
If true, closest facilities routes will be returnedwith the analysis results. Default is true.
return_facilities
If true, facilities will be returned with theanalysis results. Default is false.
return_incidents
If true, incidents will be returned with theanalysis results. Default is false.
return_barriers
If true, barriers will be returned with the analysisresults. Default is false.
return_polyline_barriers
If true, polyline barriers will be returnedwith the analysis results. Default is false.
return_polygon_barriers
If true, polygon barriers will be returned withthe 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 theanalysis results.
accumulate_attribute_names
The list of network attribute names to beaccumulated with the analysis. The default isas defined in the network layer. The valueshould be specified as a comma separated listof attribute names. You can also specify avalue of none to indicate that no networkattributes should be accumulated.
impedance_attribute_name
The network attribute name to be used as theimpedance attribute in analysis. The default isas defined in the network layer.
restriction_attribute_names
The list of network attribute names to beused as restrictions with the analysis. Thedefault is as defined in the network layer.The value should be specified as a commaseparated list of attribute names. You canalso specify a value of none to indicate thatno network attributes should be used asrestrictions.
restrict_u_turns
Specifies how U-Turns should be restricted in theanalysis. The default is as defined in the networklayer. Values: esriNFSBAllowBacktrack |esriNFSBAtDeadEndsOnly | esriNFSBNoBacktrack |esriNFSBAtDeadEndsAndIntersections
use_hierarchy
If true, the hierarchy attribute for the network shouldbe used in analysis. The default is as defined in thenetwork layer.
output_geometry_precision
The precision of the output geometry aftergeneralization. If 0, no generalization ofoutput geometry is performed. The default isas defined in the network serviceconfiguration.
output_geometry_precision_units
The units of the output geometryprecision. The default value isesriUnknownUnits. 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 bynumber of milliseconds since midnight Jan 1st, 1970, UTC.
time_of_day_is_utc
The time zone of the timeOfDay parameter. By settingtimeOfDayIsUTC to true, the timeOfDay parameter refersto Coordinated Universal Time (UTC). Choose this optionif you want to find what’s nearest for a specific time,such as now, but aren’t certain in which time zone thefacilities or incidents will be located.
time_of_day_usage
Defines the way timeOfDay value is used. The defaultis as defined in the network layer.Values: esriNATimeOfDayUseAsStartTime |esriNATimeOfDayUseAsEndTime
return_z
If true, Z values will be included in the returned routes andcompressed geometry if the network dataset is Z-aware.The default is false.
overrides
Optional dictionary. Specify additional settings that can influencethe behavior of the solver. A list of supported override settingsfor each solver and their acceptable values can be obtained bycontacting Esri Technical Support.
preserve_objectid
Optional Boolean. If True, all objectid values aremaintained. The default is False.
future
Optional boolean. If True, a future object will be returned and the processwill 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 invalidlocations. Otherwise, it will raise an error.Default is true.
return_traversed_edges
Optional boolean. Specify whether traversed edges will be returnedby the service.
return_traversed_junctions
Optional boolean. Specify whether traversed junctions will bereturned by the service.
return_traversed_turns
Optional boolean. Specify whether traversed turns will be returnedby the service.
geometry_precision
Optional Integer. Use this parameter to specify the numberof 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 decimalplaces 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 decimalplaces 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 thenetwork or the network sources being used for locating. To restrict locatingon 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 orfor the default.Note
‘default’ has to be present if you want to pass in any locate_settings to theservice. In addition, locate settings for default have to be complete, meaningall 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 arenot supported.
fromarcgis.networkimportLocateSettingslocate_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 insteadof the error property when the request fails. The default is False.
NetworkDataset
NetworkDatasetLayer
- classarcgis.network.NetworkDatasetLayer(url,gis=None,**kwargs)
The network dataset layer resource represents a single network dataset layerin routing services published by ArcGIS Server. It provides basic informationabout the network dataset layer, such as its name, type, locate settings,travel modes, and other information as in the JSON syntax below. It also providesinformation 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:FeatureSet|list[Point]|str,travel_mode:str|None=None,locate_settings:dict|None=None,barriers:Point|FeatureSet|dict[str,Any]|None=None,polyline_barriers:Polyline|FeatureSet|dict[str,Any]|None=None,polygon_barriers:Polygon|FeatureSet|dict[str,Any]|None=None,return_barriers:bool=False,return_polyline_barriers:bool=False,return_polygon_barriers:bool=False,output_source_field_names:str|None=None,out_sr:int|None=None,future:bool=False)
When performing analysis using routing services, the inputs to an analysisrarely fall exactly on top of the edges or junctions of the network datasetthe service is using. For example, you may be using a network dataset constructedfrom street centerline to power your routing services, and the input pointsyou want to analyze are the centroids of parcels in your city. These parcelcentroids do not fall on top of the street centerline; rather, they are offsetsome distance from the streets. To successfully perform a network analysisusing your routing services, the routing services must identify the locationon 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 therouting services compute the location on the network during the solve operation.With the locate service, you can compute the locations on the networkbefore 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 definedin the parameters table below. The locate service can be used in scenariossuch 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 andyou can reuse the locations in multiple places.
Note
The settings and barriers you use to locate inputs should match the eventual analysissettings when you perform routing service; otherwise, the routing services may stillrelocate 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 locateto determine serviceability. For example, the mode of travel may only allow serviceinputs that are 500 meters off the streets. You can perform a locate service with500 meters as the search tolerance and determine which inputs cannot be servicedbefore you perform a more advanced routing service.
Use DistanceToNetworkInMeters to calculate service time - You can gain information from thelocate service response to fine-tune your routing service settings. For example, if you want toknow how far each input is off network to perform delivery analysis, and it takes time to gofrom the parked vehicle location to the delivery location, you can use the DistanceToNetworkInMetersfield for each record in the response. Once you know how far away the actual location is from thenetwork, you can use a speed factor to calculate a service time for each input basedon its distance off the network.
Query fields from the underlying source features -The locate service also supports returning additionalfield values from the source features where the inputs are located. For example, you can set differentcurb approaches on the inputs depending on the type of road on which they’re located. If the input islocated on a major road, you can set it to right or left side of the vehicle, depending on the drivingside of the country where it’s located. If the input is located on a local road, either side of curbapproach 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 theLocate Servicedoc.
travel_mode
Optional string. Travel modes provide override values that help youquickly and consistently model a vehicle or mode of transportation.The chosen travel mode must be pre-configured on the network datasetthat 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 thenetwork or the network sources being used for locating. To restrict locatingon 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 orfor the default.Note
‘default’ has to be present if you want to pass in any locate_settings to theservice. In addition, locate settings for default have to be complete, meaningall 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 arenot supported.
# Usage Example:>>>fromarcgis.networkimportLocateSettings>>>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 networklocations during analysis. Barriers can be specified using a simplecomma/semi-colon based syntax or as a JSON structure. If barriersare not specified, preloaded barriers from the map document are usedin the analysis. If an empty json object is passed (‘{}’) preloadedbarriers are ignored.
polyline_barriers
Optional Polyline/FeatureSet. The set of polyline barriers loadedas network locations during analysis. If polyline barriers are notspecified, preloaded polyline barriers from the map document areused 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 asnetwork locations during analysis. If polygon barriers are notspecified, preloaded polygon barriers from the map document are usedin the analysis. If an empty json object is passed (‘{}’) preloadedpolygon barriers are ignored.
return_barriers
Optional boolean. If true, barriers will be returned with the analysisresults. Default is False.
return_polyline_barriers
Optional boolean. If true, polyline barriers will be returned withthe analysis results. Default is False.
return_polygon_barriers
Optional boolean. If true, polygon barriers will be returned withthe analysis results. Default is False.
output_source_field_names
Optional string.The fields from which the located source feature valueswill be retrieved. This parameter is specified as a comma-separatedlist 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 ArcGISStreetMap Premium data. The values will be different if you areusing 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 processwill not wait for the task to complete. The default is False, which means wait for results.
- Returns:
Dictionary
ODCostMatrixLayer
- classarcgis.network.ODCostMatrixLayer(url,gis=None,**kwargs)
OD Cost Matrix Layer is part of the Network Layer services. It allows usersto generate cost matrix data for a given set of input.
- retrieve_travel_modes()
Identify all the valid travel modes that have been defined on thenetwork dataset or in the portal if the GIS server is federated
- Returns:
Dictionary
- solve_od_cost_matrix(origins,destinations,default_cutoff:float|None=None,default_target_destination_count:int|None=None,travel_mode:str|None=None,output_type:str='SparseMatrix',time_of_day:datetime|None=None,time_of_day_is_utc:str|None=None,barriers:Point|FeatureSet|dict[str,Any]|None=None,polyline_barriers:Polyline|FeatureSet|dict[str,Any]|None=None,polygon_barriers:Polygon|FeatureSet|dict[str,Any]|None=None,impedance_attribute_name:str|None=None,accumulate_attribute_names:str|None=None,restriction_attribute_names:str|None=None,attribute_parameter_values:str|None=None,restrict_u_turns:str|None=None,use_hierarchy:bool=True,return_origins:bool=False,return_destinations:bool=False,return_barriers:bool=False,return_polyline_barriers:bool=False,return_polygon_barriers:bool=False,out_sr:int|None=None,ignore_invalid_locations:bool=True,return_z:bool=False,overrides:dict[str,Any]|None=None,future:bool=False,geometry_precision:int|None=None,geometry_precision_z:int|None=None,locate_settings:dict|None=None,return_empty_results:bool|None=False)
The Origin Destination Cost Matrix service helps you to create anorigin-destination (OD) cost matrix from multiple origins tomultiple destinations. An Origin Destination Cost Matrix is a tablethat contains the cost, such as the travel time or travel distance,from every origin to every destination. Additionally, it ranks thedestinations that each origin connects to in ascending order basedon the minimum cost required to travel from that origin to eachdestination. When generating an OD Cost Matrix, you can optionallyspecify the maximum number of destinations to find for each originand the maximum time or distance to travel when searching fordestinations.
The results from the Origin Destination Cost Matrix service oftenbecome input for other spatial analyses where the cost to travel onthe street network is more appropriate than straight-line cost.
The travel time and/or distance for each origin-destination pair isstored in the output matrix (default) or as part of the attributesof the output lines, which can have no shapes or a straight lineshape. Even though the lines are straight, they always store thetravel time and/or travel distance based on the street network, notbased 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 atwhich to stop searching for destinations. The default value isNone which means to search until all destinations are found forevery origin. The units are the same as the impedance attributeunits.
default_target_destination_count
Optional Integer. Specify the number of destinations to find perorigin. The default value isNone which means to search until alldestinations 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, orNo Lines.
time_of_day
Optional Datetime. Thetime_of_day value represents the time at whichthe travel begins from the input origins.If a value ofnow is passed, the travel begins at current time.
time_of_day_is_utc
Optional Boolean. Specify the time zone or zones of thetime_of_day parameter. The default is as definedin the network layer.
barriers
Optional FeatureLayer/SeDF/FeatureSet. Specify one or more points that act astemporary restrictions or represent additional time or distance thatmay be required to travel on the underlying streets.
polyline_barriers
Optional FeatureLayer/SeDF/FeatureSet. Specify one or more lines that prohibittravel anywhere the lines intersect the streets.
polygon_barriers
Optional FeatureLayer/SeDF/FeatureSet. Specify polygons that either prohibittravel or proportionately scale the time or distance required totravel on the streets intersected by the polygons.
impedance_attribute_name
Optional String. Specify the impedance. The default is as definedin the network layer.
accumulate_attribute_names
Optional String. Specify whether the service should accumulatevalues other than the value specified forimpedance_attribute_names.
The default is as defined in the network layer. The parameter valueshould 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 atjunctions. The default is as defined in the network layer.
Values:
esriNFSBAllowBacktrack
esriNFSBAtDeadEndsOnly
esriNFSBNoBacktrack
esriNFSBAtDeadEndsAndIntersections
use_hierarchy
Optional Boolean. Specify whether hierarchy should be used whenfinding 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 returnedby the service. The default value is false.
return_polygon_barriers
Optional Boolean. Specify whether polygon barriers will be returnedby 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 beignored when finding the best solution. The default is True.
return_z
Optional Boolean. Include z values for the returned geometries if supportedby the underlying network. The default value is false.
overrides
Optional Dict. Specify additional settings that can influence the behaviorof the solver.
future
Optional boolean. If True, a future object will be returned and the processwill 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 decimalplaces in the response geometries returned by solve operation. Thisapplies to x/y values only (not m- or z-values).
geometry_precision_z
Optional Integer. Use this parameter specify the number of decimalplaces in the response geometries returned by solve operation. Thisapplies 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 thenetwork or the network sources being used for locating. To restrict locatingon 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 orfor the default.Note
‘default’ has to be present if you want to pass in any locate_settings to theservice. In addition, locate settings for default have to be complete, meaningall 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 arenot supported.
# Usage example:>>>fromarcgis.networkimportLocateSettings>>>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 insteadof the error property when the request fails. The default is False.
- Returns:
Dictionary orNAJob whenfuture=True
LocateSettings
- classarcgis.network.LocateSettings(tolerance:float,tolerance_units:str|ToleranceUnits,allow_auto_relocate:bool,sources:list[dict[str,Any]]|None)
Parameters available for locate settings that can bepassed to the solve operation. SeelocateSettingsfor full descriptions.
Parameter
Description
tolerance
Allows you to control the maximum searchdistance when locating inputs. If no valid networklocation is found within this distance, the inputfeatures will be considered unlocated. A smallsearch tolerance decreases the likelihood of locatingon the wrong street but increases the likelihood of notfinding any valid network location.
tolerance_units
Argument should be specified as one of
ToleranceUnits
allow_auto_relocate
Allows you to control whether inputs with existingnetwork location fields can be automaticallyrelocated to ensure valid, routable location fieldsfor the analysis.
sources
Allows you to control which network source canbe used for locating. For example, you can configurethe analysis to locate inputs on streets but noton sidewalks. The list of possible sources onwhich to locate is specific to the network datasetthis service references.
# Usage Example:>>>locate_settings=LocateSettings(tolerance=5000,tolerance_units=ToleranceUnits.meters,allow_auto_relocate=True,sources=[{"name":"Routing_Streets"}])
- tolerance_units:str|ToleranceUnits
publish_routing_services
- arcgis.network.publish_routing_services(datastore:Item,path:str,server_id:str|None=None,folder:str|None=None,solver_types:list[SolverType]|SolverType=SolverType.ALL,config:str=None,gis:GIS|None=None)→GPJob
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 returnsan error if the folder contains existing services. The default value isRouting
solver_types
Optional
SolverType
. The list of Network Analyst solversto 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 configurationfile is used. For a full list of config values and explanation, please reach out tosupport@esri.com.
gis
Optional GIS. The GIS object where the dataset will be hosted at. IfNone 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: