OriginDestinationCostMatrix
汇总
此 ArcPy 类用于执行起点 - 目的地成本矩阵分析。
讨论
通过起点 - 目的地成本矩阵分析,您可以计算一组起点和一组目的地之间沿网络的行驶时间或距离。
语法
OriginDestinationCostMatrix(in_network)
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
in_network |
The network dataset or service that will be used for the network analysis. The argument can be specified using one of the following:
To use a network dataset, the network must have at least one travel mode. To use a portal URL, you must be signed in to the portal with an account that has routing privileges. Learn how to sign in to a portal in Python Learn more about network analysis using routing services When using ArcGIS Online or an ArcGIS Enterprise portal whose routing services are configured usingArcGIS Online as the Learn more about credit consumption and analysis limits in network analysis |
String |
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
accumulateAttributeNames (读取和写入) |
分析过程中要累积的成本属性列表。 这些累积属性仅供参考;求解程序仅使用求解分析时指定的出行模式所使用的成本属性。 默认值为空列表。 如果网络数据源为不支持累积属性的 ArcGIS Online 或 ArcGIS Enterprise 门户,设置此属性时会返回一条错误。 |
String |
|
allowAutoRelocate (读取和写入) |
指定是否可以在求解时自动重定位具有现有网络位置字段的输入,以确保分析的位置字段有效并且可路由。 如果值为 即使值为 默认值为 此属性会影响所有输入类型的定位。 要更改单个输入类型的此属性,请使用 如果网络数据源是 ArcGIS Online、不支持使用网络位置字段的 ArcGIS Enterprise 门户或运行版本低于 11.0 的 ArcGIS Enterprise 的门户,则设置此属性会返回错误。 |
Boolean |
|
allowSaveLayerFile (读取和写入) |
指定是否允许在结果对象上使用 |
Boolean |
|
defaultDestinationCount (读取和写入) |
要为每个起点查找的最大目的地数目。 默认为 可通过输入起点中的 |
Integer |
|
defaultImpedanceCutoff (读取和写入) |
停止从指定起点搜索目的地时所对应的阻抗值。 如果分析中所使用的出行模式使用基于时间的阻抗属性,则 通过输入起点中的 |
Double |
|
distanceUnits (读取和写入) |
报告分析输出中的行驶距离时要使用的单位。 无论网络数据集中成本属性的单位如何,输出都将转换为此属性中设置的单位并以该单位进行报告。 将返回该属性并将其设置为 注意:当分析使用服务作为其网络数据源时, |
Object |
|
ignoreInvalidLocations (读取和写入) |
指定是否忽略无效的输入位置。 值为 旧版本:如果路径服务基于的门户运行的 ArcGIS Enterprise 版本低于 10.9,则这些服务将始终忽略无效的输入位置。 如果将 |
Boolean |
|
lineShapeType (读取和写入) |
为表示分析输出而生成的线形状类型。 行驶时间和距离沿网络计算;但是,线性输出形状表示在分析中的输入点之间计算所得的连接,而不是通过网络的路径。 将返回该属性并将其设置为 |
Object |
|
networkDataSource (只读) |
网络数据集的完整目录路径或用于分析的服务的 URL。 |
String |
|
overrides (读取和写入) |
注:此属性仅限内部使用。 |
String |
|
searchQuery (读取和写入) |
旧版本:此属性已被 当在网络中定位输入时,此属性指定查询以将搜索范围限制在源要素类的要素子集内。 这在不想查找可能不适合网络位置的要素时很有用。 例如,如果您不想定位在高速公路坡道上,则可定义一个查询将其排除。 该属性值被指定为具有嵌套列表的列表,其中每个网络源具有一个条目。 每个内部列表由两个值组成,分别表示网络源的名称和用作该源的查询的 SQL 表达式。 空字符串 例如,值 如果列表中不包含网络源,则将其解释为无查询。 值 默认情况下,不对任何源使用查询。 有关 SQL 语法的详细信息,请参阅在 ArcGIS 中使用的查询表达式的 SQL 参考 。 如果网络数据源是 ArcGIS Online 或运行版本低于 11.0 的 ArcGIS Enterprise 的门户,则设置此属性会返回错误。 |
List |
|
searchSources (读取和写入) |
当在网络中定位输入时,此属性指定要使用的网络源列表和(可选)查询以将搜索限制为源要素类内的一部分要素。 默认值是在除系统交汇点之外的所有网络源上定位,并覆盖通过运行 融合网络 工具创建的交汇点。 默认情况下,不对任何源使用查询。 该属性值被指定为具有嵌套列表的列表,每个网络源最多具有一个条目。 每个内部列表由两个值组成,分别表示网络源的名称和用作该源的查询的 SQL 表达式。 网络源组件的可能值为参与网络的边源和交汇点源的字符串要素类名称。 列表中的源将用于定位,而不在列表中的源将不会用于定位。 查询在不想查找可能不适合网络位置的要素时很有用。 例如,如果您不想定位在高速公路坡道上,则可定义一个查询将其排除。 对于查询组件,请参阅 在 ArcGIS 中使用的查询表达式的 SQL 参考 获取正确表达式。 空字符串 例如,值 此属性会影响所有输入类型的定位。 要更改单个输入类型的此属性,请使用 如果网络数据源是 ArcGIS Online 或运行版本低于 11.0 的 ArcGIS Enterprise 的门户,则设置此属性会返回错误。 |
String |
|
searchTolerance (读取和写入) |
在网络上定位输入要素将使用的最大搜索距离。 返回该属性并将其设置为双精度,然后通过 此属性会影响所有输入类型的定位。 要更改单个输入类型的此属性,请使用 旧版本:如果网络数据源是运行版本低于 11.0 的 ArcGIS EnterpriseArcGIS Enterprise 的门户,则设置此属性会返回错误。 |
Double |
|
searchToleranceUnits (读取和写入) |
指定 此属性会影响所有输入类型的定位。 要更改单个输入类型的此属性,请使用 旧版本:如果网络数据源是运行版本低于 11.0 的 ArcGIS EnterpriseArcGIS Enterprise 的门户,则设置此属性会返回错误。 |
Object |
|
timeOfDay (读取和写入) |
要用于分析的日期和时间。 可以使用 可使用以下日期来指定一周中的每一天,而无需使用特定的日期:
例如,要指定路程从星期二 5:00 p.m. 开始,则请将参数值指定为 默认值为 如果分析的出行模式的阻抗属性没有与时间相关的属性(例如交通或公共交通),则该属性将不会产生影响。 |
DateTime |
|
timeUnits (读取和写入) |
指定报告分析输出中的行驶时间时要使用的单位。 无论网络数据集中成本属性的单位如何,输出都将转换为使用在此属性中设置的单位并以该单位进行报告。 将返回该属性并将其设置为 |
Object |
|
timeZone (读取和写入) |
指定 |
Object |
|
travelMode (读取和写入) |
要用于分析的出行模式。 将返回该值并将其设置为 |
Object |
方法
addFields(input_type, field_description[field_description,...])
将自定义字段添加到指定的输入类。 这些字段将包含在通过 fieldMappings 方法创建的字段映射字典中,也可与 insertCursor 方法配合使用。
| 名称 | 说明 | 数据类型 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
input_type |
The type of input to which the fields will be added. 使用 |
Object |
||||||||||||||||||||||||
|
field_description[field_description,...] |
The fields and their properties that will be added to the input class. The value will be constructed as a list of lists with each row containing the following items:
Available field types are as follows:
Only the field name and type are required. Use None as a place holder for any of the other parameters to accept the default or if the parameter does not apply to the specified field type. The method will return an error if the field already exists in the table or if any of the field properties are invalid. 旧版本:The |
TEXT |
count(input_type)
返回为输入类型添加的行数。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
用于计数的输入要素类型。 使用 |
Object |
返回值
| 数据类型 | 说明 |
|---|---|
|
Integer |
行数。 |
fieldMappings(input_type, {use_location_fields}, {list_candidate_fields[list_candidate_fields,...]})
生成将输入类型的字段名称映射到 arcpy.nax.NAClassFieldMap 对象的 NAClassFieldMappings 字典,以允许您将字段从输入数据映射到求解程序属性。 字典可用作 load 方法的 field_mappings 参数的输入。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
The type of input for which the field mappings will be returned. 使用 |
Object |
|
use_location_fields (可选) |
Specifies whether network location fields will be included in the returned field mappings dictionary. Network location fields describe the point on the network where an object is located. You can use network location fields to more precisely control how analysis inputs locate on the network and to save time when calling the Learn more about network location fields and how inputs are located on the network When this argument is set to (默认值为 False) |
Boolean |
|
list_candidate_fields[list_candidate_fields,...] (可选) |
Use this parameter to map additional, nondefault fields from the input data to the analysis inputs. For example, if the input feature class contains a field named Specify this parameter as a list of Learn more about best practices for setting up analysis inputs 旧版本:If the network data source is an ArcGIS Enterprise portal, the method will return an error if any of the fields specified are of a type that is not supported by the portal version. (默认值为 None) |
Field |
返回值
| 数据类型 | 说明 |
|---|---|
|
Dictionary |
|
fieldNames(input_type, {use_location_fields})
获取指定输入类型支持的字段名称列表。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
返回其支持的字段名称的输入类型。 使用 |
Object |
|
use_location_fields (可选) |
指示网络位置字段是否包含在返回的字段名称列表中。网络位置字段可描述网络中对象所在的点。您可以使用网络位置字段更精确地控制分析输入在网络上的定位方式,并且由于求解程序不必从输入的几何计算位置字段,因此在调用 当此参数设置为 (默认值为 False) |
Boolean |
返回值
| 数据类型 | 说明 |
|---|---|
|
String |
指定输入类型支持的字段名称列表。 |
insertCursor(input_type, field_names[field_names,...], {append})
在指定的输入类型上建立写入光标。 此游标可用于将行直接添加到输入。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
The type of input into which the cursor can be used to insert rows. 使用 |
Object |
|
field_names[field_names,...] |
A list of field names of the input type whose values you want to set when inserting rows using the cursor. You can get the names of the fields supported by an input type using the Learn more about the fields available for each input type In addition to regular fields, you can also set the geometry of the input using one of the following geometry tokens:
The |
String |
|
append (可选) |
Specifies whether the features being inserted will be appended to the existing set of features for the input type. A value of (默认值为 True) |
Boolean |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
可用于写入要素的 |
load(input_type, features, {field_mappings}, {append}, {max_features})
设置用于分析的输入要素。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
The type of input feature that will be loaded. 使用 |
Object |
|
features |
The input features that will be loaded. This parameter accepts the following input types:
For layer inputs, only selected features will be loaded. If a layer has a definition query, only the subset of features visible with the definition query will be loaded. The method also honors the Extent geoprocessing environment; only features in the specified extent will be loaded. |
String |
|
field_mappings (可选) |
An If no field mappings are specified, all fields from the input features that have the same name as the supported fields for the input type will be mapped. Learn more about the fields available for each input type (默认值为 None) |
Dictionary |
|
append (可选) |
Specifies whether the features being loaded will be appended to the existing set of features for the input type. A value of (默认值为 True) |
Boolean |
|
max_features (可选) |
The maximum number of features that can be loaded into the input type. This is useful if you are creating a tool or service and want an error returned if the size of the input exceeds the available resources. The If no value is provided, no limit will be enforced for the count of the input features. (默认值为 None) |
Integer |
setLocateSettingsOverrides(input_type, {search_sources[[Source, Expression],...]}, {allow_auto_relocate}, {search_tolerance}, {search_tolerance_units})
为指定输入类设置定位设置,并覆盖为分析指定的默认定位设置。 如果想要使用不同的规则定位不同的输入,这非常有用。 例如,在 OD 成本矩阵分析中,如果搜索查询不需要应用于输入目标和障碍,则可以使用仅应用于输入源的搜索查询。
可使用此方法覆盖指定输入类的 searchSources 、 allowAutoRelocate 、 searchTolerance 和 searchToleranceUnits 属性值。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
input_type |
The type of input for which to override default locate settings. 使用 |
Object |
|
search_sources[[Source, Expression],...] (可选) |
The list of network sources to be used when locating inputs of the designated type on the network, and, optionally, a query to restrict the search to a subset of the features within a source feature class. See the documentation for the Specifying a value for this parameter overrides the default If this parameter is not specified or is set to The method returns an error if this parameter is used and the network data source is ArcGIS Online. |
String |
|
allow_auto_relocate (可选) |
Specifies whether inputs of the designated type with existing network location fields can be automatically relocated at solve time to ensure valid, routable location fields for the analysis. If the value is Even if the value is Specifying a value for this parameter overrides the default If this parameter is not specified or is set to The method returns an error if the network data source is ArcGIS Online. The method returns an error if the network data source is an ArcGIS Enterprise portal that does not support using network location fields. |
Boolean |
|
search_tolerance (可选) |
The maximum search distance to use when locating inputs of the designated type on the network. Specifying a value for this parameter overrides the default If this parameter is not specified or is set to The units of this parameter value are set using the This parameter does not apply to line and polygon barriers; the method will return an error if this parameter is specified when the |
Double |
|
search_tolerance_units (可选) |
The units of the maximum search distance when locating inputs of the designated type of the network. The parameter is specified using a member of the Specifying a value for this parameter overrides the default If this parameter is not specified or is set to The value specified using the This parameter does not apply to line and polygon barriers; the method will return an error if this parameter is specified when the |
Double |
solve()
使用在 OriginDestinationCostMatrix 对象上设置的属性和已加载的输入执行起点 - 目的地成本矩阵分析。
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
|
代码示例
执行起点-目的地成本矩阵分析。
# An example showing how to perform origin destination cost matrix analysis using inputs from feature classes.
import arcpy
nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_origins = "C:/data/io.gdb/Origins"
input_destinations = "C:/data/io.gdb/Destinations"
output_lines = "C:/data/io.gdb/ODCostMatrixLines"
# Create a network dataset layer and get the desired travel mode for analysis
arcpy.nax.MakeNetworkDatasetLayer(nds, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["Driving Time"]
# Instantiate a OriginDestinationCostMatrix solver object
odcm = arcpy.nax.OriginDestinationCostMatrix(nd_layer_name)
# Set properties
odcm.travelMode = travel_mode
odcm.timeUnits = arcpy.nax.TimeUnits.Minutes
odcm.defaultImpedanceCutoff = 15
odcm.defaultDestinationCount = 5
odcm.lineShapeType = arcpy.nax.LineShapeType.NoLine
# Load inputs
odcm.load(arcpy.nax.OriginDestinationCostMatrixInputDataType.Origins, input_origins)
odcm.load(arcpy.nax.OriginDestinationCostMatrixInputDataType.Destinations, input_destinations)
# Solve the analysis
result = odcm.solve()
# Export the results to a feature class
if result.solveSucceeded:
result.export(arcpy.nax.OriginDestinationCostMatrixOutputDataType.Lines, output_lines)
else:
print("Solve failed")
print(result.solverMessages(arcpy.nax.MessageSeverity.All))