This is my first attempt to code in Python.
I have one polygon layer, A, that covers the UK and another set/group of layers that each cover sections of the UK, B. I want to select by location features of A contained entirely within B. As B is split into lots of separate sections (due to its size) I need to do this in a loop.
So far I have this code which I adapted from a similar question of Automating Select by Location in ArcGIS Desktop?:
# Import system modules import sys, string, os, arcgisscripting, arcpy # Create the Geoprocessor object gp = arcgisscripting.create() mxd = arcpy.mapping.MapDocument("CURRENT") df = mxd.activeDataFrame groupName = "WBBS_waterways" # Load required toolboxes... gp.AddToolbox("c:/program files (x86)/arcgis/desktop10.3/ArcToolbox/Toolboxes/Data Management Tools.tbx") # Script arguments... A = "//FILES/UNIXHome/Git/waterbirds_project/data/OS_waterways.shp" outfolder ="//FILES/UNIXHome/Git/waterbirds_project/data/" basename = "OS_just_rivers" allLayers = arcpy.mapping.ListLayers(mxd, groupName, df) for layer in(allLayers): print("A") D=layer.name # Process: Select Layer By Location... gp.SelectLayerByLocation_management(A, "COMPLETELY_WITHIN", D, "", "NEW_SELECTION") print("B") outname = outfolder + "\\" + basename + D print("C") #Process: Copy Features... gp.CopyFeatures_management(A, outname, "", "0", "0", "0")
And this is the error message I get:
Runtime error Traceback (most recent call last): File "<string>", line 28, in <module> ExecuteError: ERROR 000368: Invalid input data.
which I think means something is going wrong on this line: gp.SelectLayerByLocation_management(A, "COMPLETELY_WITHIN", D, "", "NEW_SELECTION"), it looks like python can't find layer D but I'm not sure how to make it recognise layer D.