laptop and a wrench

Bug

The field mapping object fails to return the correct ouput in the Spatial Join tool if both inputs contain field names with the same name specified in the field mapping object.

Zuletzt veröffentlicht: August 25, 2014 ArcGIS for Desktop
Bug-ID-Nummer NIM071958
EingereichtAugust 24, 2011
Zuletzt geändertJune 5, 2024
Gilt fürArcGIS for Desktop
Gefunden in Version10.0
StatusDuplicate

Zusätzliche Informationen

NIM071321

Workaround

Create an in_memory copy of the input polygon feature class, delete the identical field used in the field mapping object, and then pass it into the spatial join.Code example below:# import modulesimport arcpy, os# Data: Specify location of test datahome = arcpy.GetParameterAsText(0) #r"<a href="file:C:/ArcGIS" target="_blank">C:\ArcGIS</a> Testing\Python Testing\957244 - Field Mapping"# Data: Local VariablespolygonFC = home + os.sep + "Polygons.shp" pointFC = home + os.sep + "Points.shp"idFieldName = "regID"scratchSJshape = "temp_sj.shp"scratchDirectory = home + os.sep + "Scratch" + os.sep# Process: Check if scratch folder exists and delete itif arcpy.Exists(scratchDirectory[:-1]): arcpy.Delete_management(scratchDirectory[:-1])# Process: Create scratch folderarcpy.CreateFolder_management(home, "Scratch") # Process: Create Field Mappings ObjectfieldMappings = arcpy.FieldMappings()index = fieldMappings.findFieldMapIndex(idFieldName)# Process: Populate Field Mapping ObjectnewFieldMap = arcpy.FieldMap()newFieldMap.addInputField(pointFC, idFieldName)newField = arcpy.Field()newField.type = "String"<a href="http://newField.name" target="_blank">newField.name</a> = "TestField"newField.aliasName = "TestField"newField.editable = 1newField.isNullable = 1newField.length = 250newFieldMap.mergeRule = "Join"newFieldMap.joinDelimiter = ", "newFieldMap.outputField = newFieldfieldMappings.addFieldMap(newFieldMap)# Process: Create polygon layer in memory and remove id fieldmemPoly = r"in_memory\polyFeature"arcpy.CopyFeatures_management(polygonFC, memPoly)arcpy.DeleteField_management(memPoly, idFieldName)# Process: Spatial join the point and polgon featuresarcpy.SpatialJoin_analysis(memPoly, pointFC, scratchDirectory + scratchSJshape, "JOIN_ONE_TO_ONE", "KEEP_ALL", fieldMappings, "INTERSECTS")# Process: Return output to model/displayarcpy.SetParameter(1, scratchDirectory + scratchSJshape)# Process: Delete in_memory featurearcpy.Delete_management(memPoly)

Schritte zur Reproduzierung

Bug-ID: NIM071958

Software:

  • ArcGIS for Desktop

Benachrichtigung erhalten, wenn sich der Status eines Bugs ändert

Esri Support App herunterladen

Weitere Informationen zu diesem Thema erkunden

Unterstützung durch ArcGIS-Experten anfordern

An den technischen Support wenden

Esri Support App herunterladen

Zu Download-Optionen wechseln