漏洞
漏洞 ID 编号 | BUG-000156786 |
---|---|
已提交 | March 21, 2023 |
上次修改时间 | April 29, 2025 |
适用范围 | ArcGIS Pro |
找到的版本 | 3.1 |
操作系统 | Windows OS |
操作系统版本 | N/A |
修正版本 | 3.3 |
状态 | As Designed |
In the user-provided code sample to reproduce the issue, the fieldsMappings.addTable(layer) object is creating the field mapping with all of the input fields, which is backwards; the target feature class table must first be added to the fieldMappings object before the input, so that the input fields automatically matches to the field names from the target when the names are the same. This matches the Append tool behavior in the Geoprocessing pane, where the field map loads all of the fields from the target, and users can map source fields from the input to those target fields. The code below works for the reproduced case provided for ArcGIS Pro 3.1:
## Start sample code import sys, os, arcpy input = os.path.join(arcpy.env.scriptWorkspace,'gpsdata.gdb\\points_source') target = os.path.join(arcpy.env.scriptWorkspace,'gpsdata.gdb\\points_destination') fieldMappings = arcpy.FieldMappings() # Add all fields from target layer fieldMappings.addTable(target) # Add all fields from input layer, which will automatically match to field names from the target when the names are the same fieldMappings.addTable(input) arcpy.AddMessage(f"initial fieldmap = {fieldMappings.exportToString()}") # Loop through all fields in the field map, and clean out the input fields from the target, so each field map only has an input from the input layer, which matches the behavior of the Append tool UI for fmi in range(fieldMappings.fieldCount): fm = fieldMappings.getFieldMap(fmi) for targetfield_index in range(fm.inputFieldCount): intable = fm.getInputTableName(targetfield_index) if intable == arcpy.Describe(target).catalogPath: fm.removeInputField(targetfield_index) fieldMappings.replaceFieldMap(fmi, fm) break # find the existing guid field in the target layer guid_field_index = fieldMappings.findFieldMapIndex("GUIDCopy") guid_fieldmap = fieldMappings.getFieldMap(guid_field_index) # add the input globalID field to the guid fieldmap guid_fieldmap.addInputField(input, "GlobalID") fieldMappings.replaceFieldMap(guid_field_index, guid_fieldmap) arcpy.AddMessage(f"final fieldmap = {fieldMappings.exportToString()}") arcpy.Append_management(input, target, "NO_TEST", fieldMappings) ## End sample code
漏洞 ID: BUG-000156786
软件:
获取来自 ArcGIS 专家的帮助
下载 Esri 支持应用程序