1

I am trying to perform a spatial query using Python in ArcGIS, here is my code:

enter image description here

I'm getting the following error:

Traceback (most recent call last): File "C:\Users\acarr\Documents_PYTHON SCRIPTS\2016SCRIM\02_SPATIAL_QUERY.py", line 19, in arcpy.SelectLayerByLocation_management(ExpNod + "/MERGED_NODES.shp","WITHIN_A_DISTANCE",SCRIMNet,SelDist + " Meters","NEW_SELECTION") File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6812, in SelectLayerByLocation raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000368: Invalid input data. Failed to execute (SelectLayerByLocation).

I'm guessing this is due to the layers not actually being in ArcMap itself. How would I resolve this?

1
  • 3
    could you please paste the code directly in here instead of providing a photo? This is much more readable. Feb 29, 2016 at 11:36

1 Answer 1

6

If you read the syntax section of the select by location tool you will see that it takes Feature Layers as inputs. A string which is a path to a shapefile is not a Feature Layer object. If you think about it how can you represent a selection of polygons with nothing more that a full path string to some file? A Feature Layer has this ability, it is called a selection set. So you need to turn your inputs to the select layer by location tool into Layer objects and you do that with the MakeFeatureLayer tool. You are doing this for PmsNet yet you do nothing with it in your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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