2

I am attempting to iterate over all the feature classes in a folder and I'm getting the error 000368. The other solutions in on SE were not helpful to me unfortunately, so I'm posting a separate question. search_grids is a list of point feature classes and searches is a another point feature class.

The points never actually intersect with each other, but I'm using the Select by location tool to select points within a specified distance of each other. This isn't the reason for the error though as I was able to get this to work in the python window in ArcMap.

My code is the following

arcpy.env.workspace = r"C:\workspace"
search_grids = arcpy.ListFeatureClasses()
searches = r"C:\workspace\search"
for grid in search_grids:
    arcpy.management.SelectLayerByLocation(grid,"INTERSECT",searches,"97.5 meters","NEW_SELECTION","INVERT")
    arcpy.management.SelectLayerByLocation(grid,"INTERSECT",searches,"2.5 meters","ADD_TO_SELECTION","NOT_INVERT")

Why am I getting this error?

arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000368: Invalid input data. Failed to execute (SelectLayerByLocation)

7

SelectLayerByLocation requires a Layer to select features, you can't select features directly on a feature class, which is what your script is trying to do.

The reason it worked in ArcMap is because in ArcMap you were referencing the map layers rather than feature classes.

Add a MakeFeatureLayer and set your SelectLayerByLocation to select that.

for grid in search_grids:
    arcpy.MakeFeatureLayer_management(grid, 'grid_lyr')
    arcpy.management.SelectLayerByLocation('grid_lyr',"INTERSECT",searches,"97.5 meters","NEW_SELECTION","INVERT")
    arcpy.management.SelectLayerByLocation('grid_lyr',"INTERSECT",searches,"2.5 meters","ADD_TO_SELECTION","NOT_INVERT")

As you are looping, you will probably need to remove that feature layer before recreating it in the next loop. You can do this by adding an arcpy.Delete_management('grid_lyr') after whatever code you are adding after your select statements.

You may also be having trouble with searches as you don't appear to be referencing a feature class here - I would think this would either be a shapefile (ending with .shp) or a geodatabase feature class (inside a .mdb or .gdb). It looks like you are referencing just a folder C:\workspace\search

  • That explains it, Thank you. I want to run some additional tools in the loop including DeleteFeatures Near DeleteField AddField and several search and update cursors to calculate values in the attribute table. Will that be a problem if am working on a Layer as opposed to a feature class? Assuming it's not, I will want to save the gridlyr at the end of the loop. How would I do that? – GForce Jun 28 '16 at 20:31
  • 1
    The interaction in your script is with the Layer, however any modifications you make to the data (new fields, removed fields, changes to records) are on the feature class itself (same as if you edit within ArcMap). Your base feature class grid will be modified. – Midavalo Jun 28 '16 at 20:48
  • Excellent. Thank you. Is it a best practice to always create the layer when doing geo processing or only when using the SelectLayerByLocation and SelectLayerByAttribute tools? – GForce Jun 29 '16 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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