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.

Last Published: August 25, 2014 ArcGIS for Desktop
Bug ID Number NIM071958
SubmittedAugust 24, 2011
Last ModifiedJune 5, 2024
Applies toArcGIS for Desktop
Version found10.0
StatusDuplicate

Additional Information

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)

Steps to Reproduce

Bug ID: NIM071958

Software:

  • ArcGIS for Desktop

Get notified when the status of a bug changes

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options