laptop and a wrench

Bogue

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.

Dernière publication: August 25, 2014 ArcGIS for Desktop
Numéro d’ID de bogue NIM071958
EnvoiAugust 24, 2011
Dernière modificationJune 5, 2024
S’applique àArcGIS for Desktop
Version trouvée10.0
StatutDuplicate

Informations supplémentaires

NIM071321

Solution de contournement

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)

Étapes pour reproduire

ID de bogue: NIM071958

Logiciel:

  • ArcGIS for Desktop

Recevoir une notification lorsque le statut d’un bogue change

Télécharger l’application Esri Support

En savoir plus sur ce sujet

Obtenir de l’aide auprès des experts ArcGIS

Contacter le support technique

Télécharger l’application Esri Support

Accéder aux options de téléchargement