ArcObjects Library Reference  (GeoDatabase)    

IQueryFilter Interface

Provides access to members that filter data based on attribute values and or relationships.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description

IQueryFilter filters data based on an attribute query. A string defining a where clause is required. An optional list of columns may be included to specify the column values to be retrieved. If no columns are specified, all values will be returned.

When To Use

When you need to filter data based on attribute values or the relationships between attributes.

Members

Description
Method AddField Appends a single field name to the list of sub-fields.
Read/write property OutputSpatialReference The spatial reference in which to output geometry for a given field.
Read/write property SubFields The comma delimited list of field names for the filter.
Read/write property WhereClause The where clause for the filter.

CoClasses that implement IQueryFilter

CoClasses and Classes Description
QueryFilter ESRI Query Filter Object.
SMQueryFilter (SMRouter) SMQueryFilter Class
SpatialFilter ESRI Spatial Filter Object.
TemporalQueryFilter (esriTrackingAnalyst) Controls properties for the temporal query filter.

Remarks

Unlike the QueryDef object, QuerFilter objects are supported across all workspace types, including shapefiles and coverages.

Note on ORDER BY and returning sorted data: To add ORDER BY and GROUP BY clauses to the attribute query the IQueryFilterDefinition::PostfixClause property can be used prior to creating the cursor.

[C#]

    public void IQueryFilter__(IFeatureClass featureClass)
    {
        IQueryFilter queryFilter = new QueryFilterClass();

        //Setting the SubFields and WhereClause:
        //if you are updating the geometry you must include the shapefield in the subfields.
        queryFilter.SubFields = "STATE_NAME,POPULATION";
        queryFilter.WhereClause = "STATE_NAME = 'California'";

        //Using a query filter to search a feature class:
        IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);
    }

[Visual Basic 6.0]

The following code excerpts show how to get a reference to an IQueryFilter interface, set the values of the SubFields and WhereClause properties. The last code fragment shows how to establish a cursor for data retrieval using the query filter.

Getting a reference:

Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter 

Setting the SubFields and WhereClause:

pQueryFilter.SubFields =   "STATE_NAME,POPULATION" 
pQueryFilter.WhereClause = "STATE_NAME = 'California'" 

Using a query filter to search a feature class:

Dim pFeatureCursor As IFeatureCursor
Set pFeatureCursor = pFeatureClass.Search(pQueryFilter, False)

See Also

IQueryDef Interface | ISpatialFilter Interface | esriSpatialRelEnum Constants

Example

IQueryFilter Example

 


Feedback Send feedback on this page