I performed a task ArcMap 10.1, using the Spatial Join tool in the toolbox. Then, from the Results widows, right-click and select Copy As Python Snippet
. This will be the basis for a script that will loop over a series of input / output combinations to automate the repetitive steps a user would otherwise perform manually.
The script contains a large field mapping. I'm not performing any field mappings so, in my mind, I don't really need it. Is there a way to remove the field mapping section and tell arcpy to just use the same names? That's what the code is doing but I'm looking for a cleaner way. Plus, my iterations will not contain the same fields but they will not have any field mapping either. I tried removing the field mapping section and replacing it with ""
but that didn't work.
Update 2 - One solution, and I'm holding out hope for something more elegant, iterate the feature classes used for each spatial join and build the field mappings in code.
Update 1 - Added script. The error is "arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid."
when I replace the field mappings with ""
. The error occurs on the line beginning with "INTERSECT",
.
arcpy.SpatialJoin_analysis("XXX-TargetFeatures-XXX",
"C:/.../localFileGeodatabase.gdb/XXX-JoinFeatures-XXX",
"C:/.../localFileGeodatabase.gdb/XXX-OutputFeatureClass-XXX",
"JOIN_ONE_TO_MANY",
"KEEP_COMMON",
"""Field01 "Field01" true true false 4 Long 0 0 ,First,#,C:/.../localFileGeodatabase.gdb/XXX-TargetFeatures-XXX,Field01,-1,-1;
Field02 "Field02" true true false 4 Long 0 0 ,First,#,C:/.../localFileGeodatabase.gdb/XXX-TargetFeatures-XXX,Field02,-1,-1;
Field03 "Field03" true true false 2 Text 0 0 ,First,#,C:/.../localFileGeodatabase.gdb/XXX-TargetFeatures-XXX,Field03,-1,-1;
.
.
.
Field120_1 "Field120" true true false 2 Text 0 0 ,First,#,C:/.../localFileGeodatabase.gdb/XXX-TargetFeatures-XXX,Field120,-1,-1""",
"INTERSECT", "2000 Feet", "
No comments:
Post a Comment