描述
提供 NAClassFieldMap 对象的字典,用于映射网络分析输入类的属性字段名称,或设置该属性的默认值。字典关键字是网络分析类属性名称,值为 NAClassFieldMap 对象。
讨论
可以通过在网络分析求解程序类对象上使用 fieldMappings 方法获取 NAClassFieldMappings 对象,并且此对象可以用作 load 方法的 field_mappings 参数输入。NAClassFieldMappings 对象中所包含的 NAClassFieldMap 对象提供获取或设置网络分析类各属性的默认值以及对与属性关联的映射字段名称的访问权。
代码示例
以下脚本显示了如何在起点-目的地成本矩阵分析中使用 NAClassFieldMappings 和 NAClassFieldMap 对象来控制加载行为。
# 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))