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
.
-
1You 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.Jay Guarneri– Jay Guarneri2013年03月14日 18:28:44 +00:00Commented 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– nmpeterson2013年03月14日 18:43:25 +00:00Commented Mar 14, 2013 at 18:43
-
@nmpeterson Ha! Very true! Still, it can be an easy way to get started.Jay Guarneri– Jay Guarneri2013年03月14日 18:45:17 +00:00Commented Mar 14, 2013 at 18:45
-
1thanks @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– mikeLdub2013年03月14日 18:49:50 +00:00Commented Mar 14, 2013 at 18:49
-
1After 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"Jay Guarneri– Jay Guarneri2013年03月14日 19:34:46 +00:00Commented Mar 14, 2013 at 19:34