# 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=True, return_polygon_barriers=True, 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)

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.

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)

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. Inputs:

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.

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

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

attributeParameterValues - A set of attribute parameter values that

can be parameterized to determine which network elements can be used by a vehicle.

defaultBreaks - A comma-separated list of doubles. The default is

defined in the network analysis layer.

excludeSourcesFromPolygons - A comma-separated list of string names.

The default is defined in the network analysis layer.

mergeSimilarPolygonRanges - If true, similar ranges will be merged

in the result polygons. The default is defined in the network analysis layer.

outputLines - The type of lines(s) generated. The default is as

defined in the network analysis layer. Values: esriNAOutputLineNone | esriNAOutputLineTrueShape | esriNAOutputLineTrueShapeWithMeasure

outputPolygons - The type of polygon(s) generated. The default is

as defined in the network analysis layer.

overlapLines - Indicates if the lines should overlap from multiple

facilities. The default is defined in the network analysis layer.

overlapPolygons - Indicates if the polygons for all facilities

should overlap. The default is defined in the network analysis layer.

splitLinesAtBreaks - If true, lines will be split at breaks. The

default is defined in the network analysis layer.

splitPolygonsAtBreaks - If true, polygons will be split at breaks.

The default is defined in the network analysis layer.

trimOuterPolygon - If true, the outermost polygon (at the maximum

break value) will be trimmed. The default is defined in the network analysis layer.

trimPolygonDistance - If polygons are being trimmed, provides the

distance to trim. The default is defined in the network analysis layer.

trimPolygonDistanceUnits - If polygons are being trimmed, specifies

the units of the trimPolygonDistance. The default is defined in the network analysis layer.

returnFacilities - If true, facilities will be returned with the

analysis results. Default is false.

returnBarriers - If true, barriers will be returned with the analysis

results. Default is false.

returnPolylineBarriers - If true, polyline barriers will be returned

with the analysis results. Default is false.

returnPolygonBarriers - If true, polygon barriers will be returned

with the analysis results. Default is false.

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

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

impedanceAttributeName - The network attribute name to be used as the

impedance attribute in analysis. The default is as defined in the network analysis layer.

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

restrictUTurns - 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

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

outputGeometryPrecisionUnits - 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

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

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

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

travelDirection - Options for traveling to or from the facility. The

default is defined in the network analysis layer. Values: esriNATravelDirectionFromFacility |

esriNATravelDirectionToFacility

returnZ - 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, the process is run asynchronously.

The default is False. If True, a NAJob is returned instead of the results.

ignoreInvalidLocations - If true, the solver will ignore invalid

locations. Otherwise, it will raise an error. Default is true.

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

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. Inputs:

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.

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.

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

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

attributeParameterValues - A set of attribute parameter values that

can be parameterized to determine which network elements can be used by a vehicle.

returnDirections - If true, directions will be generated and returned

with the analysis results. Default is false.

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

directionsOutputType - Defines content, verbosity of returned

directions. The default is esriDOTStandard. Values: esriDOTComplete | esriDOTCompleteNoEvents | esriDOTInstructionsOnly | esriDOTStandard | esriDOTSummaryOnly

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

directionsLengthUnits - 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

directionsTimeAttributeName - The name of network attribute to use for

the drive time when computing directions. The default is as defined in the network layer.

returnCFRoutes - If true, closest facilities routes will be returned

with the analysis results. Default is true.

returnFacilities - If true, facilities will be returned with the

analysis results. Default is false.

returnIncidents - If true, incidents will be returned with the

analysis results. Default is false.

returnBarriers - If true, barriers will be returned with the analysis

results. Default is false.

returnPolylineBarriers - If true, polyline barriers will be returned

with the analysis results. Default is false.

returnPolygonBarriers - If true, polygon barriers will be returned with

the analysis results. Default is false.

outputLines - 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

defaultCutoff - The default cutoff value to stop traversing. defaultTargetFacilityCount - The default number of facilities to find. travelDirection - Options for traveling to or from the facility.

The default is defined in the network layer. Values: esriNATravelDirectionFromFacility | esriNATravelDirectionToFacility

outSR - The spatial reference of the geometries returned with the

analysis results.

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

impedanceAttributeName - The network attribute name to be used as the

impedance attribute in analysis. The default is as defined in the network layer.

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

restrictUTurns - Specifies how U-Turns should be restricted in the

analysis. The default is as defined in the network layer. Values: esriNFSBAllowBacktrack | esriNFSBAtDeadEndsOnly | esriNFSBNoBacktrack | esriNFSBAtDeadEndsAndIntersections

useHierarchy - If true, the hierarchy attribute for the network should

be used in analysis. The default is as defined in the network layer.

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

outputGeometryPrecisionUnits - 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

timeOfDay - Arrival or departure date and time. Values: specified by

number of milliseconds since midnight Jan 1st, 1970, UTC.

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

timeOfDayUsage - Defines the way timeOfDay value is used. The default

is as defined in the network layer. Values: esriNATimeOfDayUseAsStartTime | esriNATimeOfDayUseAsEndTime

returnZ - 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, the process is run asynchronously.

The default is False. If True, a NAJob is returned instead of the results.

ignoreInvalidLocations - If true, the solver will ignore invalid

locations. Otherwise, it will raise an error. Default is true.

## 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

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

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.

 Argument 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, the result will be a SolveJob object and results will be returned asynchronously.
Returns

Dictionary or NAJob when future=True