SolverInsertCursor

概要

A write cursor for a solver class, specific to an input type, that can be used to add rows directly to the input.

ディスカッション

Instances of this class are not created directly. Instead, they are created by calling the insertCursor method on one of the solver classes.

手法の概要

手法説明
insertRow (row)

Insert a row into a network analysis solver input using a cursor.

手法

insertRow (row)
パラメーター説明データ タイプ
row

The row to insert, represented as either a list or a tuple. The length of the list and the ordering and datatypes of the list items must match the list of field names specified in the field_names parameter of the insertCursor method used to instantiate the cursor.

List

コードのサンプル

SolverInsertCursor example

Use the insertCursor method and a SolverInsertCursor object to set inputs for an analysis.

# 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()