I keep on getting an error on Select by location that the file cannot be found and the inputs are invalid, but I can't figure out what I'm doing incorrectly. I realize some of my variables unnecessarilly repeat themselves, which I plan to clean up, but it still doesn't explain why SelectByLocation isn't working.

# Import arcpy module
import arcpy

#Set Geoprocessing Environments
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = "C:/PATH HERE/Testing"
arcpy.env.workspace = "C:/PATH HERE/ArcGIS/gdb.mdb"

# Parameters.
PRISM = arcpy.GetParameterAsText(0)

#Unchanging Variables and Workspaces
workspace = "C:/PATH HERE/gdb.mdb"
scratchWorkspace = "C:/PATH HERE/Testing"
PRISM_pts = scratchWorkspace + "/PRISM_pts.shp"
Pts_Lyr = scratchWorkspace + "/Pts_Lyr.lyr"
Map_Layer = scratchWorkspace + "/Map_Layer.lyr"
Prism_Lyr = scratchWorkspace + "/Prism_Lyr.lyr"

# Process: Raster to Point
arcpy.RasterToPoint_conversion(PRISM, PRISM_pts, "Value")

#Process: Make a Feature Layer for the Rasters
arcpy.MakeFeatureLayer_management(PRISM_pts, Pts_Lyr)

#Process: Make a Feature Layer for the Map
arcpy.MakeFeatureLayer_management(Map, Map_Layer)

# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(Map_Layer, "INTERSECT", Pts_Lyr, "", "")

# Runtime error  Traceback (most recent call last):
# File "<string>", line 1, in <module>
# File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py",
# line 6618, in SelectLayerByLocation
# raise e ExecuteError: Failed to execute. Parameters are not valid.
# ERROR 000368: Invalid input data.
# ERROR 000732: Selecting Features:
# Dataset C:/PATH HERE/Testing/Pts_Lyr.lyr
# does not exist or is not supported
# Failed to execute (SelectLayerByLocation).
# =====================================

# Process: Spatial Join
arcpy.SpatialJoin_analysis(Map, Prism_Lyr, Spatial_Join_shp, "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "INTERSECT", "", "")

I don't quite understand why ArcGIS can't find the layer by location file, since it just created it. Am I missing a step?

  • You don't have to put your "Map_Layer.lyr" in the scratch workspace - you can just do Map_Layer = "Map_Layer.lyr" and it will work - basically it just puts it in memory for the duration of the current python script. I know this doesn't necessarily solve your problem, but just a tip. – dklassen Jul 4 '14 at 15:34
  • Thanks, I was a bit confused about what needed a location and what didn't. That'll help me clean up my code a bit. – Alex Jul 4 '14 at 15:35
  • Also you can simplify your MakeFeatureLayer statment, if the input features are in your current set arcpy workspace - then you can just go: arcpy.MakeFeatureLayer_management(PRISM_pts, Pts_Lyr). You don't need to specify the rest of the arguments. – dklassen Jul 4 '14 at 15:37
  • I didn't know that either. Thank you! – Alex Jul 4 '14 at 15:40
  • I would suggest cleaning up your code, then reposting your question, as it is difficult to read your code and find an error with all the repetition. – dklassen Jul 4 '14 at 15:43

The help state, regarding Make Feature Layer, that:

the layer that is created by the tool is temporary and will not persist after the session ends

Simply change the following variables...

Pts_Lyr = scratchWorkspace + "/Pts_Lyr.lyr"
Map_Layer = scratchWorkspace + "/Map_Layer.lyr"
Prism_Lyr = scratchWorkspace + "/Prism_Lyr.lyr"


Pts_Lyr = "Pts_Lyr"
Map_Layer = "Map_Layer"
Prism_Lyr = "Prism_Lyr"

You can also simply use the string value itself to reference the feature layer in memory. If you wish to save the temporary layer to disk, use Save Layer to File.

| improve this answer | |

It looks like the issue is with the previous step: MakeFeatureLayer_management. For the in_features parameter you are passing Map variable which has been set to:


This doesn't look like a valid feature class.

MakeFeatureLayer_management (in_features, out_layer, {where_clause}, {workspace}, {field_info})
| improve this answer | |
  • What constitutes for a valid feature class then? I thought any shapefile could be made into a layer (sorry if this sounds terribly ignorant of me, I'm fairly new to ArcGIS and python). – Alex Jul 5 '14 at 4:48
  • Shape file is a valid feature class. In that case, your path should be like: "c:/path/to/shapeName.shp" – Matej Jul 5 '14 at 15:58
  • It does, I just didn't want to include the path name in this because it includes my last name and the like. The ending for PRISM is .bil and for Map is .shp – Alex Jul 5 '14 at 18:15
  • in that case, you can fix it to set out_layer to a variable that points to memory, like: Map_Layer = "in_memory/map_layer". – Matej Jul 6 '14 at 22:09

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.