arcpy.da.SearchCursor filter by location

1296
4
09-21-2022 10:54 PM
Status: Implemented
Labels (1)
rkraujutis
New Contributor II

"arcpy.da.Search" cursor does not accept "arcpy.Polygon" to be used for spatial filtering of features in large feature class.

For spatial filters, currently, you have to use "arcpy.management.SelectLayerByLocation", but for large datasets it creates large overheads, because:
- it creates temparay tables in database session
- it creates temporary indexes in database session
- it downloads matched features shape and oid fields from database
- it does not accept attribute filter, so it also downloads a lot of redundant data
- it uploads matched oid fields to database session

After all, you we can use "arcpy.da.Search", which appends filter with matching oids in database session.

This approach leads to many database operations. My idea is - just allow to pass "overlap_type", "select_features", "search_distance", "invert_spatial_relationship" parameters to "arcpy.da.Search" cursor and let database do filtering in one pass with attribute and spatial filters.

4 Comments
DannyMcVey
Status changed to: Under Consideration
 
DuncanHornby

I've always thought it was cumbersome to be forced to call the select layer by location tool when you wanted to do a spatial query. In ArcObjects you can feed in a QueryFilter or a SpatialFIlter into a search method which is a slicker approach.

I think this idea would be an important improvement to arcpy. I often generate say a polygon and wish to know which geometries it is intersecting without the need for creating an selection across a layer. Such a cursor would close the gap between ArcObjects rich capabilities and arcpy.

I can appreciate if ESRI are reticent to fiddling around with the existing cursor so to add another option to the table directly relevant to this idea I would be happy if ESRI made a new cursor that was just for spatial querying, so SearchCursor is for querying data by attributes and a "SpatialSearchCursor" would be the new cursor as suggested by @rkraujutis.

 

HannesZiegler
Status changed to: In Product Plan

We're working on this!  This status does not guarantee that the functionality will be in the next release, but development work has begun. Release cycles vary by product so make sure to check the product life cycle information to get an idea of when to expect the next release.  

HannesZiegler
Status changed to: Implemented

This idea has been implemented in ArcGIS Pro 3.2. The arcpy.da.SearchCursor now has a spatial_filter parameter which accepts ArcPy Geometry objects. The spatial search can be further controlled with the spatial_relationship and search_order parameters.

Please see the What's New documentation for more new features in Pro 3.2. Additionally, we have also posted a Your Ideas in ArcGIS Pro 3.2 blog and video, take a look if interested!