NAClassFieldMap

摘要

用于映射网络分析输入类的属性字段名称,或设置该属性的默认值。 执行网络分析时,求解程序会将网络分析类的属性用作输入。

说明

NAClassFieldMap 对象自身无法实例化。 可通过实例化 NAClassFieldMappings 对象来实现该对象的实例化,这会返回一组 NAClassFieldMap 对象作为字典。 字典关键字是网络分析类属性名称,值为 NAClassFieldMap 对象。

属性

属性说明数据类型
defaultValue
(可读写)

用于获取或设置 NAClassFieldMap 对象表示的属性的默认值。该值可指定为值的字符串表示或属性数据类型的值。例如,可以将“路边通道”属性的默认值指定为数字 1 或字符串 "1"。不能为“线障碍”和“面障碍”子图层中的“位置”属性设置默认值,因为它们需要 BLOB 值。如果为某个属性指定了 mappedFieldNamedefaultValue 属性,则仅当与映射字段对应的要素属性值为空值时,才使用默认值。

Variant
mappedFieldName
(可读写)

用于获取或设置输入要素类或表的字段名称,该名称用于获取属性值。如果与映射字段对应的要素属性值为空值,则使用为 defaultValue 属性指定的值。

String
propertyName
(只读)

属性名称,使用 NAClassFieldMap 对象为其指定默认值或映射字段名称。

String

代码示例

以下脚本显示了如何在起点-目的地成本矩阵分析中使用 NAClassFieldMappingsNAClassFieldMap 对象来控制加载行为。

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