TransWikia.com

SelectLayerByLocation_management gives ERROR 000368: Invalid input data?

Geographic Information Systems Asked by geoJshaun on April 11, 2021

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_DataPythonGeog485Lesson3Lesson3PracticeExercisesLesson3PracticeExerciseAWashington.gdbCityBoundaries"
pnrs = r"C:RS_DataPythonGeog485Lesson3Lesson3PracticeExercisesLesson3PracticeExerciseAWashington.gdbParkAndRide"

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

nameField = "HasParkAndRide"

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

One Answer

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")

Correct answer by PolyGeo on April 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP