2

Using ArcMap 10.3, I would like to Select By Location multiple layers using ArcPy. The error message states line 7 is not correct. I can't find the error though. "Water_Body_Boundary" is my source layer.

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
bldgLayer = "Water_Body_Boundary"
layers = arcpy.mapping.ListLayers(mxd)
for layer in layers:
    if layer.name != bldgLayer:
        arcpy.SelectLayerByLocation_management(layer, "WITHIN", bldgLayer)

The error message:

Runtime error Traceback (most recent call last): File "", line 7, in File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 7359, in SelectLayerByLocation raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Feature Layer. ERROR 000840: The value is not a Raster Catalog Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByLocation)

3

As @BERA suggested you'll need to reference a feature layer in the select layer by location method, use this statement before the select statement:

for layer in layers:
    if layer.name != bldgLayer:
        arcpy.MakeFeatureLayer_management(layer, "featureLayer")
        arcpy.SelectLayerByLocation_management("featureLayer", "WITHIN", bldgLayer)
|improve this answer|||||

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.