[GIS] Select Layer by Location – Arcpy – Why are the inputs being interpreted as invalid

arcgis-10.1arcpyerror-000368python-toolbox

I am working on a tool in a python toolbox and am totally confused about what is going on and causing my select by location operation to fail (Error 000368).

I am trying to select the features in one layer that are completely within a specific polygon.
Here is the line where the error is occuring:

for (index,item) in enumerate(TempIDs):         
    lyrBoundaries.definitionQuery = "[" + parameters[1].valueAsText + "]" + " = " + "'" + str(item) + "'"

    for (index2,item2) in enumerate(Spec_Layers):
        currentLayer = arcpy.mapping.Layer(str(item2))

        arcpy.SelectLayerByLocation_management(currentLayer,"WITHIN",lyrBoundaries)

        arcpy.CalculateField_management(currentLayer,parameters[3].valueAsText,hopper,"VB","#")

The error is occurring in the arcpy.SelectLayerByLocation_management() line. The text of the error message I'm getting is: (edited to remove the actual text of the path)

    Executing: SelectLayerByLocation "[FULL PATH OF currentLayer]" COMPLETELY_WITHIN GPL0 "0 Unknown" NEW_SELECTION
Start Time: Fri Mar 01 10:29:29 2013
Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.

My question is really: Why is lyrBoundaries showing up as GPL0 and not as the path of the layer? Beyond that, any tips or hints about why the inputs are being interpreted as invalid?

Best Answer

I realized that my problem was coming from the extra step of trying to dynamically recreate a layer for every entry in Spec_Layers. This value was being set from a multivalue input in the tool, which returns a list of objects which are already instantiated as Layer objects (so, no need to make a layer out of a layer).

This is working for me nicely: (parameters[2].values is the list of Layer objects returned from the list of Layers chosen in the tool dialog box)

for (index,item) in enumerate(TempIDs):

lyrBoundaries.definitionQuery = "[" + parameters[1].valueAsText + "]" + " = " + "'" + str(item) + "'"

messages.addMessage("Associating Data for: " + str(lyrBoundaries.definitionQuery))

for (index2,item2) in enumerate(parameters[2].values):

    #Select all of the features in the current layer that are completely within the current Site Boundary
    arcpy.SelectLayerByLocation_management(item2,"WITHIN",lyrBoundaries)

    #Set hopper equal to the current value of TempID
    hopper = '"' + str(item) + '"'
    arcpy.CalculateField_management(item2,parameters[3].valueAsText,hopper,"VB","#")
Related Question