I am trying to run the Spatial Join function through the Python shell in ArcGIS 10. When you do the point-and-click method of spatial join, you are given a tool window with an option that asks "How do you want the attributes to be summarized?" However, the Python syntax doesn't show a parameter for this option.

How do I control the attribute summarization through Python? Why is there no parameter for this?

1 Answer 1


The optional field_mapping parameter is what you're looking for. The page you linked to links to "Mapping input fields to output fields", which will get you started. The mergeRule property of the FieldMap objects is the one that controls which type of statistic/summary to calculate.

Basically you have to create a single FieldMappings object, which is a collection of individual FieldMap objects, each with its own mergeRule.

  • 1
    You can sometimes have an easier go of setting up the field mappings if you put it together using the Spatial Join GUI tool, then run it and export it as a python snippet. Mar 14, 2013 at 18:28
  • 1
    @JayGuarneri that's true, if you don't mind your field_mapping parameter being specified as a (typically long and somewhat unweildy/confusing) string, rather than a FieldMappings object.
    – nmpeterson
    Mar 14, 2013 at 18:43
  • @nmpeterson Ha! Very true! Still, it can be an easy way to get started. Mar 14, 2013 at 18:45
  • 1
    thanks @JayGuarneri, this was a good exercise for me since I have to adapt the script to multiple datasets, but how can you export the code from the GUI?
    – mikeLdub
    Mar 14, 2013 at 18:49
  • 1
    After you run the code, go to the results window and right click on the Spatial Join you just ran, and select "Copy as Python Snippet" Mar 14, 2013 at 19:34

Your Answer

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

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