Make OD Cost Matrix Layer (Network Analyst)

Summary

Makes an origin–destination (OD) cost matrix network analysis layer and sets its analysis properties. An OD cost matrix analysis layer is useful for representing a matrix of costs going from a set of origin locations to a set of destination locations.

Usage

Syntax

MakeODCostMatrixLayer_na (in_network_dataset, out_network_analysis_layer, impedance_attribute, {default_cutoff}, {default_number_destinations_to_find}, {accumulate_attribute_name}, {UTurn_policy}, {restriction_attribute_name}, {hierarchy}, {hierarchy_settings}, {output_path_shape})
ParameterExplanationData Type
in_network_dataset

The network dataset on which the OD cost matrix analysis will be performed.

Network Dataset Layer
out_network_analysis_layer

Name of the OD cost matrix network analysis layer to create.

String
impedance_attribute

The cost attribute to be used as impedance in the analysis.

String
default_cutoff
(Optional)

Default impedance value at which to cut off searching for destinations for a given origin. If the accumulated impedance becomes higher than the cutoff value, the traversal stops. The default can be overridden by specifying the cutoff value on the origins.

Double
default_number_destinations_to_find
(Optional)

Default number of destinations to find for each origin. The default can be overridden by specifying a value for the TargetDestinationCount property on the origins.

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

  • ALLOW_UTURNSU-turns are permitted at junctions with any number of adjacent edges.
  • NO_UTURNSU-turns are prohibited at all junctions. Note, however, that U-turns are still permitted at network locations even when this setting is chosen; however, you can set the individual network locations' CurbApproach property to prohibit U-turns.
  • ALLOW_DEAD_ENDS_ONLYU-turns are prohibited at all junctions, except those that have only one adjacent edge (a dead end).
  • ALLOW_DEAD_ENDS_AND_INTERSECTIONS_ONLYU-turns are prohibited at junctions where exactly two adjacent edges meet but are permitted at intersections (any junction with three or more adjacent edges) or dead ends. (junctions with exactly one adjacent edge)
String
restriction_attribute_name
[restriction_attribute_name,...]
(Optional)

List of restriction attributes to apply during the analysis.

String
hierarchy
(Optional)
  • USE_HIERARCHY Use the hierarchy attribute for the analysis. Using a hierarchy results in the solver preferring higher-order edges to lower-order edges. Hierarchical solves are faster, and they can be used to simulate the preference of a driver who chooses to travel on freeways over local roads when possible—even if that means a longer trip. This option is valid only if the input network dataset has a hierarchy attribute.
  • NO_HIERARCHYDo not use the hierarchy attribute for the analysis. Not using a hierarchy yields an exact route for the network dataset.

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)

LegacyLegacy:

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)
  • NO_LINESNo shape will be generated for the output routes. This is useful when you have large number of origins and destinations and are interested only in the OD cost matrix table (and not the output line shapes).
  • STRAIGHT_LINESThe output route shape will be a single straight line between each of the origin-destination pairs.

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

Code Sample

MakeODCostMatrixLayer example 1 (Python window)

Execute the tool using only the required parameters

import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/Paris.gdb"
arcpy.MakeODCostMatrixLayer_na("Transportation/ParisNet","DrivetimeCosts",
                               "Drivetime")
MakeODCostMatrixLayer example 2 (Python window)

Execute the tool using all parameters

import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/Paris.gdb"
arcpy.MakeODCostMatrixLayer_na("Transportation/ParisNet","DrivetimeCosts",
                               "Drivetime",10,20,["Meters","Drivetime"],
                               "NO_UTURNS",["Oneway"],"USE_HIERARCHY","",
                               "NO_LINES")
MakeODCostMatrixLayer example 3 (workflow)

The following stand-alone Python script demonstrates how the MakeODCostMatrixLayer tool can be used to create an origin-destination cost matrix for delivery of goods from the warehouses to all stores within a 10-minute drive time.

# Name: MakeODCostMatrixLayer_Workflow.py
# Description: Create an origin-destination cost matrix for delivery of goods 
#              from the warehouses to all stores within a 10-minute drive time 
#              and save the results to a layer file on disk. Such a matrix can   
#              be used as an input for logistics, delivery and routing analyses.
# 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/Paris.gdb"
    env.overwriteOutput = True
    
    #Set local variables
    inNetworkDataset = "Transportation/ParisMultimodal_ND"
    outNALayer = "WarehouseToStoreDrivetimeMatrix"
    impedanceAttribute = "Drivetime"
    accumulateAttributeName = ["Meters"]
    inOrgins = "Analysis/Warehouses"
    inDestinations = "Analysis/Stores"
    fieldMappings = "Name NOM #"
    outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr"
    
    #Create a new OD Cost matrix layer. We wish to find all stores within a 10 
    #minute cutoff. Apart from finding the drive time to the stores, we also 
    #want to find the total distance. So we will accumulate the "Meters" 
    #impedance attribute.
    arcpy.MakeODCostMatrixLayer_na(inNetworkDataset, outNALayer, 
                                   impedanceAttribute, 10, "",
                                   accumulateAttributeName)
    
    #Load the warehouse locations as origins using a default field map that maps
    #the Name property using a name field from warehouse features.
    arcpy.AddLocations_na(outNALayer, "Origins", inOrgins, "","1000 Meters")
    
    #Load the store locations as destinations mapping the NOM field from stores
    #features as Name property
    arcpy.AddLocations_na(outNALayer, "Destinations", inDestinations, 
                          fieldMappings,"1000 Meters")
    
    #Solve the OD cost matrix layer
    arcpy.Solve_na(outNALayer)
    
    #Save the solved OD cost matrix 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)

Environments

Related Topics

Licensing Information

ArcView: Requires Network Analyst
ArcEditor: Requires Network Analyst
ArcInfo: Requires Network Analyst

Published 6/7/2010