Summary
Creates an origin-destination (OD) cost matrix from multiple origins to multiple destinations. An OD cost matrix is a table that contains the travel time and travel distance from each origin to each destination. Additionally, it ranks the destinations that each origin connects to in ascending order based on the minimum time or distance required to travel from that origin to each destination. The best path on the street network is discovered for each origin-destination pair, and the travel times and travel distances are stored as attributes of the output lines. Even though the lines are straight for performance reasons, they always store the travel time and travel distance along the street network, not straight-line distance.
Usage
Finds and measures the least-cost paths along the network from multiple origins to multiple destinations.
The tool dialog box groups the various optional parameters into the following six categories to make it easier for you to manage them:
- Advanced Analysis
- Barriers
- Custom Travel Mode
- Network Dataset
- Network Locations
- Output
- Service Capabilities
Syntax
GenerateOriginDestinationCostMatrix(Origins, Destinations, Network_Dataset, Output_Geodatabase, Output_Origin_Destination_Lines_Name, Output_Origins_Name, Output_Destinations_Name, {Travel_Mode}, {Time_Units}, {Distance_Units}, {Number_of_Destinations_to_Find}, {Cutoff}, {Time_of_Day}, {Time_Zone_for_Time_of_Day}, {Point_Barriers}, {Line_Barriers}, {Polygon_Barriers}, {Impedance_Attribute}, {Impedance_Attribute_Units}, {Time_Attribute}, {Time_Attribute_Units}, {Distance_Attribute}, {Distance_Attribute_Units}, {UTurn_Policy}, {Use_Hierarchy_in_Analysis}, {Restrictions}, {Attribute_Parameter_Values}, {Accumulate_Attributes}, {Maximum_Snap_Tolerance}, {Feature_Locator_WHERE_Clause}, {Origin_Destination_Line_Shape}, {Maximum_Features_Affected_by_Point_Barriers}, {Maximum_Features_Affected_by_Line_Barriers}, {Maximum_Features_Affected_by_Polygon_Barriers}, Maximum_Origins, Maximum_Destinations, {Force_Hierarchy_Beyond_Distance}, {Save_Output_Network_Analysis_Layer}, {Overrides})
Parameter | Explanation | Data Type |
Origins | Specify locations that function as starting points in generating the paths to destinations. Up to 200 origins can be added. When specifying the origins, you can set properties for each one, such as its name or the number of destinations to find from the origin, by using attributes. The origins can be specified with the following attributes: Name—The name of the origin. The name can be a unique identifier for the origin. The name is included in the output lines (as the OriginName field) and in the output origins (as the Namefield) and can be used to join additional information from the tool outputs to the attributes of your origins. If the name is not specified, a unique name prefixed with Location is automatically generated in the output origins. An autogenerated origin name is not included in the output lines. TargetDestinationCount—The maximum number of destinations that must be found for the origin. If a value is not specified, the value from the Number of Destinations to Find parameter is used. Cutoff—Specify the travel time or travel distance value at which to stop searching for destinations from the origin. Any destination beyond the cutoff value will not be considered. The value needs to be in the units specified by the Time Unitsparameter if the impedance attribute in your travel mode is time based or in the units specified by the Distance Units parameter if the impedance attribute in your travel mode is distance based. If a value is not specified, the value from the Cutoff parameter is used. CurbApproach—Specify the direction a vehicle may depart from the origin. The field value is specified as one of the following integers (use the numeric code, not the name in parentheses):
The CurbApproach property is designed to work with both kinds of national driving standards: right-hand traffic (United States) and left-hand traffic (United Kingdom). First, consider a stop on the left side of a vehicle. It is always on the left side regardless of whether the vehicle travels on the left or right half of the road. What may change with national driving standards is your decision to approach a stop from one of two directions, that is, so it ends up on the right or left side of the vehicle. For example, if you want to arrive at a stop and not have a lane of traffic between the vehicle and the stop, you would choose Right side of vehicle (1) in the United States but Left side of vehicle (2) in the United Kingdom. | Feature Set |
Destinations | Specify locations that function as ending points in generating the paths from origins. Up to 200 destinations can be added. When specifying the destinations, you can set properties for each one, such as its name, by using attributes. The destinations can be specified with the following attributes: Name—The name of the destination. The name can be a unique identifier for the destination. The name is included in the output lines (as the DestinationName field) and in the output destinations (as the Name field) and can be used to join additional information from the tool outputs to the attributes of your destinations. If the name is not specified, a unique name prefixed with Location is automatically generated in the output destinations. An autogenerated destination name is not included in the output lines. CurbApproach—Specifies the direction a vehicle may arrive at the destination. The field value is specified as one of the following integers (use the numeric code, not the name in parentheses):
The CurbApproach property is designed to work with both kinds of national driving standards: right-hand traffic (United States) and left-hand traffic (United Kingdom). First, consider a stop on the left side of a vehicle. It is always on the left side regardless of whether the vehicle travels on the left or right half of the road. What may change with national driving standards is your decision to approach a stop from one of two directions, that is, so it ends up on the right or left side of the vehicle. For example, if you want to arrive at a stop and not have a lane of traffic between the vehicle and the stop, you would choose Right side of vehicle (1) in the United States but Left side of vehicle (2) in the United Kingdom. | Feature Set |
Network_Dataset | The network dataset on which the analysis will be performed. Network datasets most often represent street networks but may represent other kinds of transportation networks as well. The network dataset needs at least one time-based and one distance-based cost attribute. | Network Dataset Layer |
Output_Geodatabase | The output workspace. This workspace must already exist. | Workspace |
Output_Origin_Destination_Lines_Name | The name of the output feature class that stores the lines connecting the origin and destination points. Output from Generate Origin Destination Cost Matrix describes the schema of this output feature class. | String |
Output_Origins_Name | The name of the output feature class containing origin points. Output from Generate Origin Destination Cost Matrix describes the schema of this output feature class. | String |
Output_Destinations_Name | The name of the output feature class containing destination points. Output from Generate Origin Destination Cost Matrix describes the schema of this output feature class. | String |
Travel_Mode (Optional) | Choose the mode of transportation for the analysis. CUSTOM is always a choice. For other travel mode names to appear, they must be present in the network dataset specified in the Network_Dataset parameter. (The arcpy.na.GetTravelModes function provides a dictionary of the travel mode objects configured on a network dataset, and the name property returns the name of a travel mode object.) A travel mode is defined on a network dataset and provides override values for parameters that, together, model car, truck, pedestrian, or other modes of travel. By choosing a travel mode here, you don't need to provide values for the following parameters, which are overridden by values specified in the network dataset:
| String |
Time_Units (Optional) | Specify the units that should be used to measure and report the total travel time between each origin-destination pair. The choices include the following:
| String |
Distance_Units (Optional) | Specify the units that should be used to measure and report the total travel distance between each origin-destination pair. The choices include the following:
| String |
Number_of_Destinations_to_Find (Optional) | Specify the maximum number of destinations to find per origin. If a value for this parameter is not specified, the output matrix includes travel costs from each origin to every destination. Individual origins can have their own values (specified as the TargetDestinationCount field) that override the Number of Destinations to Find parameter value. | Long |
Cutoff (Optional) | Specify the travel time or travel distance value at which to stop searching for destinations from a given origin. Any destination beyond the cutoff value will not be considered. Individual origins can have their own values (specified as the Cutoff field) that override the Cutoff parameter value. The value needs to be in the units specified by the Time Unitsparameter if the impedance attribute of your travel mode is time based or in the units specified by the Distance Units parameter if the impedance attribute of your travel mode is distance based. If a value is not specified, the tool will not enforce any travel time or travel distance limit when searching for destinations. | Double |
Time_of_Day (Optional) |
Specifies the time and date at which the routes should begin. If your network dataset contains live or historical traffic data, specifying a time of day results in more accurate estimation of travel time between stops because the travel times account for the traffic conditions that are applicable for that date and time. The Time Zone for Time of Day parameter specifies whether this time and date refer to UTC or the time zone in which the stop is located. The tool ignores this parameter when Measurement Units isn't set to a time-based unit. | Date |
Time_Zone_for_Time_of_Day (Optional) |
Specifies the time zone of the Time of Day parameter.
| String |
Point_Barriers (Optional) | Specifies point barriers, which are split into two types: restriction and added cost point barriers. They temporarily restrict traversal across or add impedance to points on the network. The point barriers are defined by a feature set, and the attribute values you specify for the point features determine whether they are restriction or added cost barriers. The fields in the attribute table are listed and described below. ObjectID: The system-managed ID field. Shape: The geometry field indicating the geographic location of the network analysis object. Name: The name of the barrier. BarrierType: Specifies whether the barrier restricts travel completely or adds cost when traveling through it. There are two options:
Use the value 0 for Restriction and 2 for Added Cost. Additional_Time: Indicates how much travel time is added when the barrier is traversed. This field is applicable only for added-cost barriers and only if the measurement units are time based. This field value must be greater than or equal to zero, and its units are the same as those specified in the Measurement Units parameter. Additional_Distance: Indicates how much distance is added when the barrier is traversed. This field is applicable only for added-cost barriers and only if the measurement units are distance based. The field value must be greater than or equal to zero, and its units are the same as those specified in the Measurement Units parameter. | Feature Set |
Line_Barriers (Optional) |
Specifies line barriers, which temporarily restrict traversal across them. The line barriers are defined by a feature set. The fields in the attribute table are listed and described below. ObjectID: The system-managed ID field. Shape: The geometry field indicating the geographic location of the network analysis object. Name: The name of the barrier. | Feature Set |
Polygon_Barriers (Optional) | Specifies polygon barriers, which are split into two types: restriction and scaled cost polygon barriers. They temporarily restrict traversal or scale impedance on the parts of the network they cover. The polygon barriers are defined by a feature set, and the attribute values you specify for the polygon features determine whether they are restriction or scaled cost barriers. The fields in the attribute table are listed and described below. ObjectID: The system-managed ID field. Shape: The geometry field indicating the geographic location of the network analysis object. Name: The name of the barrier. BarrierType: Specifies whether the barrier restricts travel completely or scales the cost of traveling through it. There are two options:
Use the value 0 for Restriction and 1 for Scaled Cost. ScaledTimeFactor: This is the factor by which the travel time of the streets intersected by the barrier is multiplied. This field is applicable only for scaled-cost barriers and only if the measurement units are time based. The field value must be greater than zero. ScaledDistanceFactor: This is the factor by which the distance of the streets intersected by the barrier is multiplied. This attribute is applicable only for scaled-cost barriers and only if the measurement units are distance based. The attribute value must be greater than zero. | Feature Set |
Impedance_Attribute (Optional) | The cost attribute to be used as impedance in the analysis. | String |
Impedance_Attribute_Units (Optional) | The units of the network impedance attribute specified by the Impedance Attribute parameter. This is merely an informational parameter that cannot be changed without directly editing the network dataset. It is also unnecessary to change since the unit conversions between measurement units and the cost attribute are handled for you. The value of this parameter is overridden when Travel Mode is set to any value other than Custom. | String |
Time_Attribute (Optional) | Defines the network cost attribute to use when the measurement units value is a time unit. The tool performs the necessary time-unit conversion when the measurement units value differs from the units of the cost attribute defined here. In other words, the time units of the default cutoff and the network cost attribute don't need to be the same. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than Custom. | String |
Time_Attribute_Units (Optional) | The units of the time attribute. You can explicitly set the time attribute units, but it is recommended to pass nothing or "#" and let the solver determine the units. The value of this parameter is overridden when Travel_Mode is set to any value other than CUSTOM. | String |
Distance_Attribute (Optional) | Defines the network cost attribute to use when the measurement units value is a distance unit. The tool performs the necessary distance-unit conversion when the measurement units value differs from the units of the cost attribute defined here. In other words, the measurement units and the distance units of the network cost attribute don't need to be the same. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than Custom. | String |
Distance_Attribute_Units (Optional) | The units of the distance attribute. You can explicitly set the distance attribute units, but it is recommended to pass nothing or "#" and let the solver determine the units. The value of this parameter is overridden when Travel_Mode is set to any value other than CUSTOM. | String |
UTurn_Policy (Optional) |
The U-Turn policy at junctions. Allowing U-turns implies the solver can turn around at a junction and double back on the same street. Given that junctions represent street intersections and dead ends, different vehicles may be able to turn around at some junctions but not at others—it depends on whether the junction represents an intersection or dead end. To accommodate, the U-turn policy parameter is implicitly specified by how many edges, or streets, connect to the junction, which is known as junction valency. The acceptable values for this parameter are listed below; each is followed by a description of its meaning in terms of junction valency.
The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than custom. | String |
Use_Hierarchy_in_Analysis (Optional) | Specify whether hierarchy should be used when finding the shortest routes between points.
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. You can use the Force_Hierarchy_Beyond_Distance parameter to force the solve to use hierarchy even if Use_Hierarchy_in_Analysis is set to False. This parameter is ignored unless Travel_Mode is set to CUSTOM. When modeling a custom walking mode, it is recommended to turn off hierarchy since the hierarchy is designed for motorized vehicles. | Boolean |
Restrictions [restriction,...] (Optional) | Indicates which network restriction attributes are respected during solve time. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than custom. | String |
Attribute_Parameter_Values (Optional) | Specifies the parameter values for network attributes that have parameters. The record set has two columns that work together to uniquely identify parameters and another column that specifies the parameter value. The value of this parameter is overridden when Travel Mode (Travel_Mode in Python) is set to any value other than custom. The attribute parameter values record set has associated attributes. The fields in the attribute table are listed below and described. ObjectID: The system-managed ID field. AttributeName: The name of the network attribute whose attribute parameter is set by the table row. ParameterName: The name of the attribute parameter whose value is set by the table row. (Object type parameters cannot be updated using this tool.) ParameterValue: The value you want for the attribute parameter. If a value is not specified, the attribute parameter is set to null. | Record Set |
Accumulate_Attributes [attribute,...] (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 Time Attribute (Time_Attribute in Python) or Distance Attribute (Distance_Attribute in Python) parameter to calculate the shortest paths. For each cost attribute that is accumulated, a Total_[attribute] field is added to the routes that are output by the solver. | String |
Maximum_Snap_Tolerance (Optional) | The maximum snap tolerance is the furthest distance that Network Analyst searches when locating or relocating a point onto the network. The search looks for suitable edges or junctions and snaps the point to the nearest one. If a suitable location isn't found within the maximum snap tolerance, the object is marked as unlocated. | Linear unit |
Feature_Locator_WHERE_Clause (Optional) | An SQL expression used to select a subset of source features that limits on which network elements stops can be located. The syntax for this parameter consists of two parts: the first is the source feature class name (followed by a space) and the second is the SQL expression. To write an SQL expression for two or more source feature classes, separate them with a semicolon. To ensure facilities are not located on limited-access highways, for example, write an SQL expression like the following to exclude those source features: "Streets" "FUNC_CLASS not in('1', '2')". Note that barriers ignore the feature locator WHERE clause when loading. | String |
Origin_Destination_Line_Shape (Optional) | The resulting lines of an OD cost matrix can be represented with either straight-line geometry or no geometry at all. In both cases, the route is always computed along the street network by minimizing the travel time or the travel distance, never using the straight-line distance between origins and destinations.
| String |
Maximum_Features_Affected_by_Point_Barriers (Optional) | Limits how many features can be affected by point barriers. A null value indicates there is no limit. | Long |
Maximum_Features_Affected_by_Line_Barriers (Optional) |
Limits how many features can be affected by line barriers. A null value indicates there is no limit. | Long |
Maximum_Features_Affected_by_Polygon_Barriers (Optional) |
Limits how many features can be affected by polygon barriers. A null value indicates there is no limit. | Long |
Maximum_Origins | Limits how many origins can be added to the origin destination cost matrix analysis. This parameter helps you govern the amount of processing that occurs when solving. For example, you could assign a low value to this parameter for a free version of the service you are creating and use a higher value for a paid-subscription version of the service. A null value indicates there is no limit. | Long |
Maximum_Destinations | Limits how many destinations can be added to the origin destination cost matrix analysis. This parameter helps you govern the amount of processing that occurs when solving. For example, you could assign a low value to this parameter for a free version of the service you are creating and use a higher value for a paid-subscription version of the service. A null value indicates there is no limit. | Long |
Force_Hierarchy_Beyond_Distance (Optional) | Specifies the distance after which the solver will force hierarchy when finding routes, even if hierarchy is not enabled. The units of this parameter are the same as those shown in the Distance Attribute Units parameter. Finding routes between stops that are far away while using the network's hierarchy tends to incur much less processing than finding the same routes without using the hierarchy. This parameter helps you govern the amount of processing that occurs when solving. A null value indicates that the hierarchy will never be enforced and the value of the Use Hierarchy in Analysis parameter will always be honored. If the input network dataset does not support hierarchy, specifying a value for this parameter will result in an error. A null value should be used in this case. This parameter is disabled unless the network dataset includes a hierarchy attribute. | Double |
Save_Output_Network_Analysis_Layer (Optional) |
In either case, feature classes containing the results are returned. However, a server administrator may want to choose to output a network analysis layer as well so the setup and results of the tool can be debugged using the Network Analyst controls in the ArcGIS Desktop environment. This can make the debugging process much easier. In ArcGIS Desktop, the default output location for the network analysis layer is in the scratch folder. You can determine the location of the scratch folder by evaluating the value of arcpy.env.scratchFolder geoprocessing environment. The output network analysis layer is stored as an LYR file whose name begins with _ags_gpna and is followed by an alphanumeric GUID. | Boolean |
Overrides (Optional) | Specify additional settings that can influence the behavior of the solver when finding solutions for the network analysis problems. The value for this parameter needs to be specified in JavaScript Object Notation (JSON). For example, a valid value is of the following form: {"overrideSetting1" : "value1", "overrideSetting2" : "value2"}. The override setting name is always enclosed in double quotation marks. The values can be either a number, Boolean, or a string. The default value for this parameter is no value, which indicates not to override any solver settings. Overrides are advanced settings that should be used only after careful analysis of the results obtained before and after applying the settings. A list of supported override settings for each solver and their acceptable values can be obtained by contacting Esri Technical Support. | string |
Derived Output
Name | Explanation | Data Type |
Solve_Succeeded | Determines if the service was able to successfully generate the origin-destination cost matrix. | Boolean |
Output_Origin_Destination_Lines | The resulting routes from the origins to the destinations. | Feature Set |
Output_Origins | The origins that participated in the analysis. | Feature Set |
Output_Destinations | The destinations that participated in the analysis. | Feature Set |
Output_Network_Analysis_Layer | Network analysis layer with properties as configured in the tool parameters that can be used for further analysis or debugging in the map. | File |
Code sample
GenerateOriginDestinationCostMatrix example 1 (Python window)
Execute the tool using the required parameters.
origins = arcpy.FeatureSet()
origins.load("Warehouses")
destinations = arcpy.FeatureSet()
destinations.load("Stores")
arcpy.na.GenerateOriginDestinationCostMAtrix(origins, destinations, "ParisMultimodal_ND")
GenerateOriginDestinationCostMatrix example 2 (stand-alone script)
The following Python script demonstrates how to use the tool through a stand-alone script.
# Name: GenerateOriginDestinationCostMatrix_Workflow.py
# Description: Find and measure the least-cost paths along the network from multiple
# origins to multiple destinations.
# Requirements: Network Analyst Extension
#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:/arcgis/ArcTutor/Network Analyst/Tutorial/Paris.gdb'
env.overwriteOutput = True
#Set local variables
inOrigins = 'Analysis/Warehouses'
inDestinations = 'Analysis/Stores'
inNetworkDataset = 'Transportation/ParisMultimodal_ND'
outGeodatabase = 'C:/arcgis/ArcTutor/Network Analyst/Tutorial/Output.gdb'
# Run GenerateODCostMatrix
arcpy.na.GenerateOriginDestinationCostMatrix(inOrigins, inDestinations, inNetworkDataset, outGeodatabase,
Cutoff=10, Origin_Destination_Line_Shape='STRAIGHT_LINES')
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
Licensing information
- Basic: Requires Network Analyst
- Standard: Requires Network Analyst
- Advanced: Requires Network Analyst