English

How To: Leverage st_geometry operators with ArcObjects

Summary

Instructions provided describe how to use ArcObjects to leverage st_geometry operators.

There are many advantages to using st_geometry operators. The example provided demonstrates how to define a feature cursor and query filter that will execute the spatial relational operator on the database server utilizing the functionality of the specified spatial relational operator.

Procedure

The following Visual Basic code example demonstrates how to use a IQueryDef object and its properties with a spatial relational operator. Using an IQueryDef object requires defining the tables involved in the query: in this case, states and lakes, the subfields, and the WHERE clause. The WHERE clause string sets the st_geometry operator predicate filter. In the example below, the st_contains operator will return all lakes contained by the specified state name, which equals Oregon.

Note:
The st_geometry operator arguments must be fully qualified, because there is no ability to set a table alias when defining the tables involved in the query.


Code:
Dim pCursor As ICursor
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pRow As IRow
Dim pCnt As Integer
Dim pQueryDef As IQueryDef

Set pFeatureWorkspace = pWorkspace

Set pQueryDef = pFeatureWorkspace.CreateQueryDef
pQueryDef.Tables = "tb.states, tb.lakes"
pQueryDef.SubFields = "lakes.name"
pQueryDef.WhereClause = "states.name = 'Oregon' AND sde.st_contains(states.shape, lakes.shape) = 1"

Set pCursor = pQueryDef.Evaluate
Set pRow = pCursor.NextRow
pCnt = 0

While Not pRow Is Nothing
pCnt = pCnt + 1
Set pRow = pCursor.NextRow
Wend