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

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)

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.

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.

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.

returnZ - If true, Z values will be included in saPolygons and saPolylines

geometry if the network dataset is Z-aware.

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.

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

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.

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

directionsLanguage - The language to be used when computing directions.

The default is as defined in the network layer. 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.

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.

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

List of route layers in this network dataset

property service_area_layers

List of service area layers in this network dataset