Make Route Layer (Network Analyst)
Summary
Makes a route network analysis layer and sets its analysis properties. A route analysis layer is useful for determining the best route between a set of network locations based on a specified network cost.
Usage
-
After creating the analysis layer with this tool, you can add network analysis objects to it using the Add Locations tool, solve the analysis using the Solve tool, and save the results on disk using Save To Layer File tool.
-
When using this tool in geoprocessing models, if the model is run as a tool, the output network analysis layer must be made a model parameter. Otherwise the output layer is not added to the table of contents in ArcMap.
Syntax
Parameter | Explanation | Data Type |
in_network_dataset |
The network dataset on which the route analysis will be performed. | Network Dataset Layer |
out_network_analysis_layer |
Name of the route network analysis layer to create. | String |
impedance_attribute |
The cost attribute to be used as impedance in the analysis. | String |
find_best_order (Optional) |
| Boolean |
ordering_type (Optional) |
Specifies the ordering of stops when FIND_BEST_ORDER is used.
| String |
time_windows (Optional) |
Specifies if time windows will be used at the stops.
| Boolean |
accumulate_attribute_name [accumulate_attribute_name,...] (Optional) |
List of cost attributes to be accumulated during analysis. These accumulation attributes are purely for reference; the solver only uses the cost attribute specified by the Impedance attribute parameter to calculate the route. For each cost attribute that is accumulated, a Total_[Impedance] property is added to the routes that are output by the solver. | String |
UTurn_policy (Optional) |
Restrict or permit U-turns at junctions that could occur during network traversal between stops.
| String |
restriction_attribute_name [restriction_attribute_name,...] (Optional) |
List of restriction attributes to apply during the analysis. | String |
hierarchy (Optional) |
The parameter is not used if a hierarchy attribute is not defined on the network dataset used to perform the analysis. In such cases, use "#" as the parameter value. | Boolean |
hierarchy_settings (Optional) |
Legacy: Prior to version 10, this parameter allowed you to change the hierarchy ranges for your analysis from the default hierarchy ranges established in the network dataset. At version 10, this parameter is no longer supported and should be specified as an empty string. If you wish to change the hierarchy ranges for your analysis, update the default hierarchy ranges in the network dataset. | Network Analyst Hierarchy Settings |
output_path_shape (Optional) |
Specifies the shape type for the route features that are output by the analysis.
No matter which output shape type is chosen, the best route is always determined by the network impedance, never Euclidean distance. This means only the route shapes are different, not the underlying traversal of the network. | String |
start_date_time (Optional) |
Specifies a start date and time for the route. Route start time is mostly used to find routes based on the impedance attribute that varies with the time of the day. For example, a start time of 9 AM could be used to find a route that considers the rush hour traffic. The default value for this parameter is 8:00 AM. A date and time can be specified as 10/21/05 10:30 AM. If the route spans multiple days, and only the start time is specified, then the current date is used. Instead of using a particular date, a day of the week can be specified using the following dates.
After the solve, the start and end time of the route are populated in the output routes. These start and end times are also used when directions are generated. This option is only valid when a time based cost attribute has been specified as the impedance attribute. | Date |
Code Sample
Execute the tool using only the required parameters
import arcpy arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb" arcpy.MakeRouteLayer_na("Transportation/Streets_ND","WorkRoute","Minutes")
Execute the tool using all parameters
import arcpy arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb" arcpy.MakeRouteLayer_na("Transportation/Streets_ND","InspectionRoute","Minutes", "FIND_BEST_ORDER","PRESERVE_BOTH","USE_TIMEWINDOWS", ["Meters","Minutes"], "ALLOW_DEAD_ENDS_AND_INTERSECTIONS_ONLY",["Oneway"], "USE_HIERARCHY","","TRUE_LINES_WITH_MEASURES", "1/1/1900 9:00 AM")
The following stand-alone Python script demonstrates how the MakeRouteLayer tool can be used to find a best route to visit the geocoded stop locations.
# Name: MakeRouteLayer_Workflow.py # Description: Find a best route to visit the stop locations and save the # route to a layer file. The stop locations are geocoded from a # text file containing the addresses. # Requirements: Network Analyst Extension # Author: ESRI #Import system modules import arcpy from arcpy import env try: #Check out the Network Analyst extension license arcpy.CheckOutExtension("Network") #Set environment settings env.workspace = "C:/data/SanFrancisco.gdb" env.overwriteOutput = True #Set local variables inNetworkDataset = "Transportation/Streets_ND" outNALayer = "BestRoute" impedanceAttribute = "TravelTime" inAddressLocator = "SanFranciscoLocator" inAddressTable = "C:/data/StopAddresses.csv" inAddressFields = "Street Address VISIBLE NONE" fieldMappings = "Name Address #" outStops = "GeocodedStops" outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr" #Create a new Route layer. Once the route layer is created, it can be #referenced using its name. arcpy.MakeRouteLayer_na(inNetworkDataset, outNALayer, impedanceAttribute) #Geocode the stop locations from a csv file containing the addresses. #The Geocode Addresses tool can use a text or csv file as input table #as long as the first line in the file contains the field names. arcpy.GeocodeAddresses_geocoding(inAddressTable, inAddressLocator, inAddressFields, outStops) #Load the geocoded address locations as stop smapping the address field from #geocoded stop features as Name property. arcpy.AddLocations_na(outNALayer,"Stops", outStops, fieldMappings, "") #Solve the route layer, ignore any invalid locations such as those that #can not be geocoded arcpy.Solve_na(outNALayer,"SKIP") #Save the solved route layer as a layer file on disk with relative paths arcpy.SaveToLayerFile_management(outNALayer,outLayerFile,"RELATIVE") print "Script completed successfully" except Exception as e: # If an error occurred, print line number and error message import traceback, sys tb = sys.exc_info()[2] print "An error occured on line %i" % tb.tb_lineno print str(e)