0

I've seen a lot of questions asked and answered about trouble with the Select Layer By Location tool. Most ask about invalid input errors and the answer generally is to make sure to use layers (as apposed to feature classes). My problem is that I keep getting an error that some value is not Boolean, which I find strange since none of the inputs require boolean values.

I have two input files. Input1 is a shapefile of building footprints. Input2 is a shapefile of various shaped polygons. What I want to do is iterate through the polygons in Input2 and use each polygon to select the building footprint polygons in Input1 to do some work on them. I can't get past the Select By Location tool error to complete the work. Here is my code example:

with arcpy.da.SearchCursor("Input2","ID") as cursor:
  for row in cursor:
    value = str(row[0])
    field = "ID"
    exp = field + "=" + value
    arcpy.SelectLayerByAttribute_management("Input2","NEW_SELECTION",exp)
    arcpy.SelectLayerByLocation_management("Input1","WITHIN","Input2")
    ...do work on selected building polygons

I have the two inputs active in my arcpy map so they should be interpreted as layers. This is proven true since the Select Layer By Attribute tool works. I put the code into the python window, run it, and get this error message:

...in SelectLayerByLocation Execute Error: Failed to execute. Parameters are not valid. ERROR 000840: The value is not Boolean. Failed to execute (SelectLayerByLocation).

I gave the beginning of the script for context, but I've tried running the Select Layer By Location tool by itself in the python window and still get that message. When I use the Select Layer By Location tool from the tool box, I have no problem and it works. I've tried right clicking on the result, Copying As Python Snippet, pasting into the python window, and running, but I get the boolean error. I've tried using the Make Feature Layer tool in the python script (even though I shouldn't have to) with the same result. I've tried restarting.

  • It is possible that cursor conflicts with selection. First read input2 to table using TableToNumpyArray and iterate through it. Even better is changing the definition query of input2 as you go – FelixIP Mar 30 '16 at 21:40
1

This is the syntax from ESRI help:

SelectLayerByLocation_management (in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type}, {invert_spatial_relationship})

I think you should add the selection_type="ADD_TO_SELECTION" parameter to the spatial selection. That is what I have had to do when I'm doing two selections one right after the other like this.

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.