描述
查找成本表面上起点和终点之间的最短路径。
使用方法
输入起点和输入终点参数值必须在输入成本表面参数的范围内。表面范围之外的点将返回空输出。
使用多个点作为输入起点值将显著增加处理时间。
使用多个点作为输入终点值可能会生成两个以上的输出线要素。
输入成本表面参数中的“无数据”值将被视作障碍,所生成的路径将绕开这些区域。如果无法在成本表面的“无数据”像元周围找到路径,则可能无法求解,因此必须采取其他步骤来修改成本表面。
在输入成本表面参数值采用投影坐标系(例如通用横轴墨卡托 (UTM))的情况下运行工具。
新的 StartID 和 DestID 字段将添加到输出路径要素类参数中。这两个字段表示线行驶的起点和终点。
起点和终点将复制到输出位置,并包含输出路径要素类值的名称,且在名称后追加 _start 和 _end。
语法
arcpy.intelligence.LeastCostPath(in_cost_surface, in_start_point, in_end_point, out_path_feature_class, {handle_zeros})
参数 | 说明 | 数据类型 |
in_cost_surface | 用于确定从起点行驶到终点的成本的输入栅格。无法跨越“无数据”值。 | Raster Layer |
in_start_point | 输入起点要素。多个起点将显著增加处理时间。 | Feature Set |
in_end_point | 输入终点要素。多个终点将增加输出线的数量,因为生成的路径会分支为独立的路径。 | Feature Set |
out_path_feature_class | 输出路径要素类。 | Feature Class |
handle_zeros (可选) | 指定输入成本表面参数(Python 中的 in_cost_surface 参数)中零值的处理方式。
| String |
派生输出
名称 | 说明 | 数据类型 |
out_start_point | 符号化的起点。 | 要素类 |
out_end_point | 符号化的终点。 | 要素类 |
代码示例
以下 Python 窗口脚本演示了如何在即时模式下使用 LeastCostPath 函数。
import arcpy
import os
arcpy.LeastCostPath_intelligence(r"c:\workspace\terrain.gdb\mob_cost_surf",
r"c:\workspace\startinglocation.shp",
r"c:\workspace\endinglocation.shp",
os.path.join(arcpy.env.scratchWorkspace, "bestpath"),
"SMALL_POSITIVE")
以下 Python 脚本演示了如何在独立脚本中使用 LeastCostPath 函数。
# Name: LeastCostPath_Example2.py
# Description: Generate the least cost path between an input and output point
# based on a cost surface.
# Import system modules
import arcpy
import os
# Set local variables
in_cost_surface = r"c:\workspace\terrain.gdb\mob_cost_surf"
in_start_point = r"c:\workspace\startinglocation.shp"
in_end_point = r"c:\workspace\endinglocation.shp"
out_path_feature_class = os.path.join(arcpy.env.scratchWorkspace, "bestpath")
handle_zeros = "SMALL_POSITIVE"
# Execute LeastCostPath
arcpy.LeastCostPath_intelligence(in_cost_surface, in_start_point,
in_end_point, out_path_feature_class,
handle_zeros)
# Report status
if arcpy.Exists(out_path_feature_class):
print("Path segments {}".format(arcpy.GetCount_management(out_path_feature_class)[0]))
else:
print("Empty output")
环境
此工具不使用任何地理处理环境。
许可信息
- Basic: 需要 Spatial Analyst
- Standard: 需要 Spatial Analyst
- Advanced: 需要 Spatial Analyst