Résumé
Provides the ability to map field names or set default values for the properties of a network analysis input class. The properties of the network analysis class are used as inputs by the solvers while performing the network analyses.
Discussion
The NAClassFieldMap object cannot be instantiated by itself. It is obtained by instantiating an NAClassFieldMappings object, which returns a collection of NAClassFieldMap objects as a Python dictionary. The dictionary keys are the network analysis class property names, and the values are the NAClassFieldMap objects.
Propriétés
Propriété | Explication | Type de données |
defaultValue (Lecture/écriture) | Provides the ability to get or set the default value for the property represented by the NAClassFieldMap object. The value can be specified as a string representation of the value or as a value of the data type for the property. For example, the Curb Approach property can have default value specified as number 1 or as a string "1". The default value cannot be set for the Locations property in the Line Barriers and Polygon Barriers sublayer as they require BLOB values. If both mappedFieldName and defaultValue properties are specified for a property, the default value is used only if the feature attribute value corresponding to the mapped field has a null value. | Variant |
mappedFieldName (Lecture/écriture) | Provides the ability to get or set the field name from an input feature class or table that is used to derive the value for the property. If the feature attribute value corresponding to the mapped field has a null value, the value specified for the defaultValue property is used. | String |
propertyName (Lecture seule) | The name of the property for which a default value or a mapped field name is specified using the NAClassFieldMap object. | String |
Exemple de code
The following script shows how to use the NAClassFieldMappings and NAClassFieldMap objects to control load behavior in an origin destination cost matrix analysis.
# An example showing how to perform origin destination cost matrix analysis using inputs from feature classes.
import arcpy
arcpy.CheckOutExtension("network")
nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_origins = "C:/data/io.gdb/Origins"
input_destinations = "C:/data/io.gdb/Destinations"
output_lines = "C:/data/io.gdb/ODCostMatrixLines"
# Create a network dataset layer and get the desired travel mode for analysis
arcpy.na.MakeNetworkDatasetLayer(nds, nd_layer_name)
nd_travel_modes = arcpy.na.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["Driving Time"]
# Pre-calculate network location fields on the inputs to speed up analysis later
search_tolerance = "5000 Meters"
search_criteria = [["Streets", "SHAPE"], ["Streets_ND_Junctions", "NONE"]]
arcpy.nax.CalculateLocations(input_origins, nds, search_tolerance, search_criteria, travel_mode=travel_mode)
arcpy.nax.CalculateLocations(input_destinations, nds, search_tolerance, search_criteria, travel_mode=travel_mode)
# Instantiate a OriginDestinationCostMatrix solver object
odcm = arcpy.nax.OriginDestinationCostMatrix(nd_layer_name)
# Set properties
odcm.travelMode = travel_mode
odcm.lineShapeType = arcpy.nax.LineShapeType.NoLine
# Load inputs using field mappings, including the pre-calculated location fields
field_mappings_origins = odcm.fieldMappings(arcpy.nax.OriginDestinationCostMatrixInputDataType.Origins, True)
# Map the "Nombre" field in the input data to the "Name" property of the Origins class
field_mappings_origins["Name"].mappedFieldName = "Nombre"
# If the "Nombre" field is blank, set the default name to "Origen"
field_mappings_origins["Name"].defaultValue = "Origen"
odcm.load(arcpy.nax.OriginDestinationCostMatrixInputDataType.Origins, input_origins, field_mappings_origins)
# Load destinations
field_mappings_destinations = odcm.fieldMappings(arcpy.nax.OriginDestinationCostMatrixInputDataType.Destinations, True)
odcm.load(arcpy.nax.OriginDestinationCostMatrixInputDataType.Destinations, input_destinations, field_mappings_destinations)
# Solve the analysis
result = odcm.solve()
# Export the results to a feature class
if result.solveSucceeded:
result.export(arcpy.nax.OriginDestinationCostMatrixOutputDataType.Lines, output_lines)
else:
print("Solved failed")
print(result.solverMessages(arcpy.nax.MessageSeverity.All))
Vous avez un commentaire à formuler concernant cette rubrique ?