Route
汇总
此 ArcPy 类用于执行路径分析。
讨论
路径分析可用于计算沿某一网络一系列停靠点之间的最短路径。
语法
Route(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 |
|
allowSaveRouteData (读取和写入) |
指定是否将生成路径数据。 如果分析引用网络数据集,则默认设置为 |
Boolean |
|
directionsDistanceUnits (读取和写入) |
报告输出转弯方向的行驶距离时要使用的单位。 将返回该属性并将其设置为 注:此属性不支持 注:此属性会影响 |
Object |
|
directionsLanguage (读取和写入) |
将显示输出转弯方向文本的语言。 返回该属性并将表示受支持方向语言的两个或五个字符的语言代码之一设置为字符串。 可从 此属性仅在 |
String |
|
directionsStyle (读取和写入) |
要用于输出转弯方向文本的样式。 将返回该属性并将其设置为 默认值为 注:此属性会影响 |
Object |
|
distanceUnits (读取和写入) |
报告分析输出中的行驶距离时要使用的单位。 无论网络数据集中成本属性的单位如何,输出都将转换为此属性中设置的单位并以该单位进行报告。 将返回该属性并将其设置为 注意:当分析使用服务作为其网络数据源时, |
Object |
|
findBestSequence (读取和写入) |
值为 |
Boolean |
|
ignoreInvalidLocations (读取和写入) |
指定是否忽略无效的输入位置。 值为 旧版本:如果路径服务基于的门户运行的 ArcGIS Enterprise 版本低于 10.9,则这些服务将始终忽略无效的输入位置。 如果将 |
Boolean |
|
networkDataSource (只读) |
网络数据集的完整目录路径或用于分析的服务的 URL。 |
String |
|
overrides (读取和写入) |
注:此属性仅限内部使用。 |
String |
|
preserveFirstStop (读取和写入) |
如果由于 |
Boolean |
|
preserveLastStop (读取和写入) |
如果由于 |
Boolean |
|
returnDirections (读取和写入) |
指定是否将生成转弯方向。 值为 |
Boolean |
|
returnRouteEdges (读取和写入) |
指定是否将返回路径边。 路径边是单独的路径段,用于指示已遍历的网络边。 值为 |
Boolean |
|
returnRouteJunctions (读取和写入) |
指定是否返回路径遍历的网络交汇点。 值为 |
Boolean |
|
returnRouteTurns (读取和写入) |
指定是否返回路径遍历的网络转弯。 值为 |
Boolean |
|
returnToStart (读取和写入) |
值为 |
Boolean |
|
routeShapeType (读取和写入) |
为表示输出路径而生成的形状类型。 路径沿网络计算;但是,您可以使用不反映网络路径的形状来表示它们。 将返回该属性并将其设置为 默认值为 |
Object |
|
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 |
|
timeZoneForTimeWindows (读取和写入) |
指示输入停靠点的时间窗口中所指定的时间是否解释为输入位置的本地时间或协调世界时间 (UTC)。 将返回该属性并将其设置为 |
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()
使用在 Route 对象上设置的属性和已加载的输入执行路径分析。
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
|
代码示例
使用输入停靠点的要素类执行路径分析。
# An example showing how to perform route analysis using a feature class for input stops.
import arcpy
nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_stops = "C:/data/io.gdb/Stops"
output_routes = "C:/data/io.gdb/Routes"
# 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 Route solver object
route = arcpy.nax.Route(nd_layer_name)
# Set properties
route.timeUnits = arcpy.nax.TimeUnits.Minutes
route.travelMode = travel_mode
route.routeShapeType = arcpy.nax.RouteShapeType.TrueShapeWithMeasures
# Load inputs
route.load(arcpy.nax.RouteInputDataType.Stops, input_stops)
# Solve the analysis
result = route.solve()
# Export the results to a feature class
if result.solveSucceeded:
result.export(arcpy.nax.RouteOutputDataType.Routes, output_routes)
else:
print("Solved failed")
print(result.solverMessages(arcpy.nax.MessageSeverity.All))