描述
特定于输入类型的求解程序类写入游标,可用于直接将行添加到输出。
讨论
此类实例不是直接创建的, 而是通过在一个求解程序类上调用 insertCursor 方法进行创建。
方法概述
方法 | 说明 |
insertRow (row) | 使用游标在网络分析求解器输入中插入一行。 |
方法
insertRow (row)
参数 | 说明 | 数据类型 |
row | 要插入的行将以列表或组的形式表示。列表长度以及列表项的排序和数据类型必须与用于实例化游标的 insertCursor 方法 field_names 参数中指定的字段名称列表相匹配。 | List |
代码示例
使用 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()