SolverInsertCursor

描述

特定于输入类型的求解程序类写入游标,可用于直接将行添加到输出。

讨论

此类实例不是直接创建的, 而是通过在一个求解程序类上调用 insertCursor 方法进行创建。

方法概述

方法说明
insertRow (row)

使用游标在网络分析求解器输入中插入一行。

方法

insertRow (row)
参数说明数据类型
row

要插入的行将以列表或组的形式表示。列表长度以及列表项的排序和数据类型必须与用于实例化游标的 insertCursor 方法 field_names 参数中指定的字段名称列表相匹配。

List

代码示例

SolverInsertCursor 示例

使用 insertCursor 方法和 SolverInsertCursor 对象来设置分析的输入。

# An example showing how to use the insertCursor() method to set inputs for an analysis
import arcpy
arcpy.CheckOutExtension("network")

nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
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
# Set input stops using insertCursor()
fields = ["Name", "RouteName", "SHAPE@XY"]
with route.insertCursor(arcpy.nax.RouteInputDataType.Stops, fields) as cur:
    cur.insertRow(["Stop 1", "Route 1", (-117.10191118199998, 32.634351493000054)])
    cur.insertRow(["Stop 2", "Route 1", (-116.97970607599996, 32.56210221400005)])
    cur.insertRow(["Stop 1", "Route 2", (-116.97141447099995, 32.654230331000065)])
    cur.insertRow(["Stop 2", "Route 2", (-117.00762504, 32.70097640100005)])
# Solve the analysis
result = route.solve()
SolverInsertCursor 示例 2

使用 insertCursor 方法和 SolverInsertCursor 对象来设置分析的输入。使用网络数据源的 URL 以及 PointGeometry 对象作为 SHAPE@ 令牌的输入。

# An example showing how to use the insertCursor() method to set inputs for an analysis
# Use ArcGIS Online as the network data source and PointGeometry objects as inputs
import arcpy

sr_wgs84 = arcpy.SpatialReference(4326)

# Instantiate a Route solver object using ArcGIS Online as the network data source
route = arcpy.nax.Route("https://www.arcgis.com/")

# Input data with latitude and longitude values specified in WGS84 coordinates
input_data = [
    ["Stop 1", "Route 1", -117.10191118199998, 32.634351493000054],
    ["Stop 2", "Route 1", -116.97970607599996, 32.56210221400005],
    ["Stop 1", "Route 2", -116.97141447099995, 32.654230331000065],
    ["Stop 2", "Route 2", -117.00762504, 32.70097640100005]
]

# Set input stops using insertCursor()
fields = ["Name", "RouteName", "SHAPE@"]
with route.insertCursor(arcpy.nax.RouteInputDataType.Stops, fields) as cur:
    for input_pt in input_data:
        # Construct a PointGeometry object for the point using the correct spatial reference
        pt_geom = arcpy.PointGeometry(arcpy.Point(input_pt[2], input_pt[3]), sr_wgs84)
        # Insert the data using its shape
        cur.insertRow([input_pt[0], input_pt[1], pt_geom])

# Solve the analysis
result = route.solve()
print(result.solveSucceeded)