3

I tried to select SC27060054 point object using polygon.
r"Project\project.DBO.Qo" is a point layer.

import arcpy

p1 = arcpy.Point(254426.380,  4664270.258)
p2 = arcpy.Point(254432.730,  4664270.258)
p3 = arcpy.Point(254432.730,  4664264.967)
p4 = arcpy.Point(254426.380,  4664264.967)

poly = arcpy.Polygon(arcpy.Array([p1, p2, p3, p4]))

arcpy.SelectLayerByLocation_management(r"Project\project.DBO.Qo", "CONTAINS", poly)
Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 7279, in SelectLayerByLocation
raise e ExecuteError: Failed to execute. Parameters are not valid. 
ERROR 000840: The value is not a Boolean. Failed to execute (SelectLayerByLocation).

desc = arcpy.Describe(r"Project\project.DBO.Qo")
print desc.shapeType
Point

enter image description here

  • "WITHIN" or "INTERSECT" must be in place "CONTAIN" in line : arcpy.SelectLayerByLocation_management(r"Project\project.DBO.Qo", "CONTAINS", poly), but this rises the same error. In ArcGIS Documentation we read : The features in the input feature layer will be selected based on their relationship to the features from this layer or feature class. So arcpy.Polygon is feature class, right ? – dimmed Sep 14 '18 at 12:16
3

For Select Layer by Location in_layer and select_features needs to be feature layers, for example created with MakeFeatureLayer (or by adding a feature class to ArcMap and execute code in the Python window using the name of the feature layer from table of contents). So both "Project\project.DBO.Qo" and poly need to be layers.

Try:

arcpy.MakeFeatureLayer_management("Project\project.DBO.Qo" , "Qolyr")
arcpy.CopyFeatures_management(poly, r"in_memory\poly") #You need a feature class to create a feature layer
arcpy.MakeFeatureLayer_management(r"in_memory\poly", "polylyr")

And then use "Qolyr" and "polylyr" in Select Layer by Location.

Also, if Qolyr is a Point layer it can never contain polygons:

CONTAINS —The features in the input layer will be selected if they contain a selecting feature.

You probably want intersect:

INTERSECT —The features in the input layer will be selected if they intersect a selecting feature. This is the default.

  • I've tried what you wrote, but same error ... arcpy.SelectLayerByLocation_management("Qolyr", "CONTAINS", "polylyr") – dimmed Sep 14 '18 at 8:28
  • @dimmed, if Qolyr are Points, they can never contain polygons. Try Another overlap type, for example INTERSECT, to see if this is what is causing the error – BERA Sep 14 '18 at 8:31
  • When I am trying to do arcpy.SelectLayerByLocation_management("Qolyr", "INTERSECT", "polylyr") equivalent "Select By Location ..." from graphical interface of ArcGIS works fine but not from Python console. Why ? – dimmed Sep 14 '18 at 9:16
  • @dimmed do you get an error or what do you mean by not working – BERA Sep 14 '18 at 9:49
  • I got same error – dimmed Sep 14 '18 at 9:54

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.