4

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?

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Mar 14, 2013 at 15:54

1 Answer 1

2

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.

answered Mar 14, 2013 at 16:20
5
  • 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. Commented 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. Commented Mar 14, 2013 at 18:43
  • @nmpeterson Ha! Very true! Still, it can be an easy way to get started. Commented 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? Commented 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" Commented Mar 14, 2013 at 19:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.