Wish list: spatial queries with arcpy.da

5741
6
01-04-2012 06:42 AM
MarkCederholm
Occasional Contributor III
I'd like to see da support spatial queries (i.e. using a geometry class, since not all geodatabases support spatial SQL).
Tags (2)
6 Replies
JasonPardy
New Contributor
Hi Mark,

There are currently no plans for the data access (da) module to support spatial queries. However, for file geodatabases, personal geodatabases, shapefiles, etc., you can use the Select Layer By Location tool.

In 10.1 final, you will be able to use a new tool named Make Query Layer which allows you create a query layer from a DBMS table based on an input SQL select statement. The SQL can include a spatial query. This layer can then be used as input to GP tools and supported by the da module. Here is an example of creating a query layer with a SQL spatial query and using it in a tool or in searchcursor.

arcpy.MakeQueryLayer_management(r'Database Connections\Connection to pardy.sde', 'CMarkets', """SELECT c.mkt_id, c.shape, c.names FROM cola_markets c WHERE SDO_OVERLAPS(c.shape, SDO_GEOMETRY(2003, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1003,3), SDO_ORDINATE_ARRAY(4,6, 8,8))) = 'TRUE'""", "MKTID")
arcpy.GetCount_managment("CMarkets")
rows = arcpy.da.SearchCursor("CMarkets", "NAMES")



Jason
0 Kudos
Venkata_RaoTammineni
Occasional Contributor

good one. very useful.

0 Kudos
curtvprice
MVP Esteemed Contributor

I recently had the chance to experiment with the methods exposed off the geometry object. I was working with file geodatabase and I found these operators to be very fast, especially when compared with using tools like Select Layer By Location.

0 Kudos
DanPatterson_Retired
MVP Emeritus
This would be a welcome and useful addition
0 Kudos
stevegourley
Occasional Contributor II

This would be very useful.

0 Kudos
FridjofSchmidt
Occasional Contributor

I'm surprised this still isn't supported, since the 10.2 documentation states: "The records returned by SearchCursor can be constrained to match attribute criteria or spatial criteria." But how to constrain the records to match spatial criteria?