Hi,
I am new to python and arcpy, I have a script I am trying to get to work. It fails at the select layer by location. If I take out the select by location the script runs fine and the field calculates works. I feel like I am missing something simple but I just don't know.
import arcpy # Set the workspace environment arcpy.env.workspace = r"G:\GIS\ESRI\Staging\Survey123\Testing\New File Geodatabase.gdb" print arcpy.ListFeatureClasses() print("this is a list of feature classes") # Select by location arcpy.SelectLayerByLocation_management("propertypnts", "INTERSECT", "retailpt2", "", "NEW_SELECTION") print("I have selected the features") # Field Calculate arcpy.CalculateField_management('propertypnts', "CompleteY_N", '!CompleteY_N!.replace("Not Completed","Completed")', "Python_9.3") print("Calculation done")
This is the error I get.
Traceback (most recent call last):
File "G:/GIS/ESRI/Staging/Survey123/Testing/SelectCalculate.py", line 8, in <module>
arcpy.SelectLayerByLocation_management("propertypnts", "INTERSECT", "retailpt2", "", "NEW_SELECTION")
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 7891, in SelectLayerByLocation
raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation)
#Python #arcpy
Solved! Go to Solution.
You need to use the make featurelayer tool to expose them as layer objects that can feed into the select by location tool. Have a look at the help file.
try dropping the last 2 parameters ( ie "", "NEW_SELECTION").
Hi Dan,
Thank You for your reply. Unfortunately, I get the same error as before even if I drop the last 2 parameters. No idea what to do now.
The code snippet you provided isn't self contained, i.e., it relies on additional code we cannot see to be complete. For example, where are you defining or making the "propertypnts" and "retailpt2" ?
That is a good question, they are in my geodatabase from my workspace. How do I define them?
You need to use the make featurelayer tool to expose them as layer objects that can feed into the select by location tool. Have a look at the help file.
Thank you! it worked!
Assuming "they" are feature classes, you need to use Make Feature Layer—Help | ArcGIS Desktop to define them as layers. See the code sample on the documentation for the general workflow.
Thank you, it worked!
Please mark one of our answers correct. Since Duncan beat me to the punchline, maybe mark his correct and mine helpful.