Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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","#")
share|improve this answer
add comment

I recommend that you create currentlayer using arcpy.MakeFeatureLayer instead of arcpy.mapping.Layer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.