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
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 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.
| 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) |
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
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")
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")
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)