Résumé
A write cursor for a solver class, specific to an input type, that can be used to add rows directly to the input.
Discussion
Instances of this class are not created directly. Instead, they are created by calling the insertCursor method on one of the solver classes.
Vue d’ensemble des méthodes
Méthode | Explication |
insertRow (row) | Insert a row into a network analysis solver input using a cursor. |
Méthodes
insertRow (row)
Paramètre | Explication | Type de données |
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 |
Exemple de code
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()
Vous avez un commentaire à formuler concernant cette rubrique ?