1

I'm trying to use SelectLayerByLocation_managment in a script and keep getting the following error:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
ERROR 000732: Selecting Features: Dataset pnrsLyr does not exist or is not supported
Failed to execute (SelectLayerByLocation).

I made both feature classes into layers. When I run the same syntax in the python command window in arcmap it seems to work fine.

Here's the script:

import arcpy

cities = r"C:\RS_Data\Python\Geog485\Lesson3\Lesson3PracticeExercises\Lesson3PracticeExerciseA\Washington.gdb\CityBoundaries"
pnrs = r"C:\RS_Data\Python\Geog485\Lesson3\Lesson3PracticeExercises\Lesson3PracticeExerciseA\Washington.gdb\ParkAndRide"

citiesLyr = arcpy.MakeFeatureLayer_management(cities)
pnrsLyr = arcpy.MakeFeatureLayer_management(pnrs)
print "made feature layers"

nameField = "HasParkAndRide"

selection = arcpy.SelectLayerByLocation_management("citiesLyr","INTERSECT","pnrsLyr")
6

The Make Feature Layer tool needs two parameter values, and you are only supplying one.

MakeFeatureLayer_management (in_features, out_layer, {where_clause}, {workspace}, {field_info})

Try replacing:

citiesLyr = arcpy.MakeFeatureLayer_management(cities)
pnrsLyr = arcpy.MakeFeatureLayer_management(pnrs)
selection = arcpy.SelectLayerByLocation_management("citiesLyr","INTERSECT","pnrsLyr")

with:

arcpy.MakeFeatureLayer_management(cities,"Cities Layer")
arcpy.MakeFeatureLayer_management(pnrs,"PnR Layer")
selection = arcpy.SelectLayerByLocation_management("Cities Layer","INTERSECT","PnR Layer")

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.