I'm trying to understand how to use FieldMap and FieldMappings. I know very little about objects plus I'm finding the explanations on ESRI website not very good and far from comprehensive. All I'm trying to do is to perform a spatial join between two polygon datasets and I need to bring over to the target feature class 2 fields from the join class and the merge rule should be 'First'.

Can anyone please explain how to do this?

All I have is this incomplete piece of code:

fm = arcpy.FieldMap()
fm.mergeRule = 'First'
arcpy.SpatialJoin_analysis('fl_London_Bldngs', 'fl_VS2_agl_polyg_1', fc_VS2_agl_polyg, join_operation = 'JOIN_ONE_TO_ONE', match_option = 'INTERSECT', join_type = 'KEEP_COMMON', field_mapping = .....)

NOTE: Several polygons from the join feature class can intersect with 1 target feature. Therefore the need to establish a rule to choose the first value of those intersecting features.

Could anyone recommend a site where all this is nicely explained?

1 Answer 1


I had this same issue when trying to build a field map, the best documentation I found is the esri Help. Though I agree it's not the greatest in this case.

There is an arcpy.FieldMappings() help page which is better than the Spatial Join help page.

Read through FieldMappings page carefully, pay particular attention to the script at the bottom. Then just try it, once you do it you will realize it is not actually as complicated as it looks. It really is a step by step thing. You can use the same steps from that page to do the field mappings for your spatial join, even though they are using a merge for the example. They do a few more things in the sample code for the spatial join page, but these are not required, and your code should still work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.