I want to get the polyline features intersecting with a polygon geometry and having a particular field values in ArcPy standalone script.

There is another link for similar subject but it is not for standalone script. Does ArcPy have a spatial search function for geometry?

Does ArcPy have a similar option for SearchCursor like Spatialfilter with whereclause, searchGeometry and relation?

  • 1
    I'm not aware of an arcpy equivalent to the arcobjects ispatialfilter with a where clause. I would do the spatial selection first then run a search cursor on the selection.
    – Hornbydd
    Oct 30, 2019 at 17:04
  • Hi Hornbydd, I got the solution doing similarly as you suggested. But I made a featurelayer before doing spatial selection.
    – Venkat
    Oct 31, 2019 at 10:28

2 Answers 2


Just create layers using arcpy.management.MakeFeatureLayer(). You can add an SQL attribute filter to each function. These are very fast because they don't actually copy the data. Then you can use the function arcpy.Management.SelectByLocation() There are endless combinations you can use by adding or subtracting layer sets. Each function can use the previous layer. If the attributes are too complex for an SQL query then consider using a separate query and use an IN sql query with a list of key or OBJECTIDS. I use a SearchCursor inside a list comprehension that is converted to a tuple string. This can be used to create an expression line this

select_lay = arcpy.management.SelectByLocation('lay1', lay2, 'select_lay', 'NEW_SELECTION')
tuple = tuple([row[0] for row in arcpy.da.SearchCursor('select_lay', [key'])])
SQL_expr = """key IN {}""".format(tuple)
lay_2 = arcpy.management.MakeFeatureLayer('a_fc', ['field1'],SQL_expr)

Got the solution by doing similarly as suggested under "MakeFeatureLayer example 2 (stand-alone script)" in https://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-feature-layer.htm

The below is the arcgis code sample:

import arcpy
arcpy.env.overwriteOutput = True
arcpy.SelectLayerByLocation_management("cities_lyr", "INTERSECT", "c:/data/mexico.gdb/chihuahua", "", "NEW_SELECTION")
arcpy.SelectLayerByAttribute_management("cities_lyr", "SUBSET_SELECTION", "POPULATION > 10000")
arcpy.CopyFeatures_management("cities_lyr", "c:/data/mexico.gdb/chihuahua_10000plus")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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