This document is archived and information here might be outdated.  Recommended version.


IMapServer2.QueryFeatureCount2 Method (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference (Carto)  

IMapServer2.QueryFeatureCount2 Method

Returns the count of the features that meet the query filter selection criteria for the specified layer.

[Visual Basic .NET]
Public Function QueryFeatureCount2 ( _
    ByVal MapName As String, _
    ByVal pLayerDescription As ILayerDescription, _
    ByVal Filter As IQueryFilter _
) As Integer
[C#]
public int QueryFeatureCount2 (
    string MapName,
    ILayerDescription pLayerDescription,
    IQueryFilter Filter
);
[C++]
HRESULT QueryFeatureCount2(
  BSTR MapName,
  ILayerDescription* pLayerDescription,
  IQueryFilter* Filter,
  long* Count
);
[C++]

Parameters MapName [in] MapName is a parameter of type BSTR pLayerDescription [in]
pLayerDescription is a parameter of type ILayerDescription Filter [in]
Filter is a parameter of type IQueryFilter Count [out, retval] Count is a parameter of type long

Product Availability

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

Remarks

QueryFeatureCount2 returns the number of map features that match the parameters of a given query filter.

QueryFeatureCount2 requires a number of input parameters. These include: a MapName, LayerDescription and a QueryFilter. The QueryFilter can be an attribute query (SQL espression), a spatial query, or a combination of both.

QueryFilter 

QueryFilter provides the ability to query based on attribute filter (SQL expression) a spatial filter, or a combination of both. Attribute filters take any valid ‘non-GIS data specific’ SQL statement. For example, CNTRY_CODE=‘BD’ or POPULATION=12345. Syntax for querying date fields depend on the underlying data. If you are working with Shapefile or File GeoDatabase data the syntax is <FieldName>=date ‘YYYY-MM-DD’; for Access-based Personal GeoDatabase the sytax is #YYYY-MM-DD#. For SDE database, check with the specific database’s help.

SearchShape 

Geometry set in ISpatialFilter should meet the following criteria:

DefinitionExpressions

DefinitionExpression can be set on a layer in order to limit layer features available for display or query. This expression can be also be set in the source map document as a definition query. Any DefinitionExpression set in the LayerDescription will override any definition query set in the source map. MapServer QueryFeatureCount2 honors DefinitionExpression.

Let's look at some examples. You have a layer in your map that represents sales regions. The layer includes fields REGIONS, SALES and MANAGER.

Example #1: In the source map the layer has a definition query, "REGION='North'". No DefintionExpression is specified in LayerDescription. Your QueryFilter where clause is "MANAGER='Bob'". The result will be a count of all sale region features that fall within the North region and are managed by Bob.

Example #2: In the source map the layer has a definition query, "REGION='North'". You apply a DefinitionExpression in LayerDescription as "SALES > 1000". Your QueryFilter where clause is "MANAGER='Bob'". The result will be a count of all sale region features with sales over 1000 and are managed by Bob. QueryFeatureCount2 honors the DefinitionExpression set in LayerDescription. The DefinitionExpression overrides the definition query set in the source map. If you wish to include the layer's original defintion query, "REGION='North'" in your final query, you must include this in your QueryFilter, ""MANAGER='Bob' AND "REGION='North'".

Example #3: In the source map the layer has no definition query. You apply a DefinitionExpression in LayerDescription as "SALES > 1000". Your QueryFilter where clause is "MANAGER='Bob'". The result will be a count of all sale region features with sales over 1000 and are managed by Bob. QueryFeatureCount2 honors the DefinitionExpression set in LayerDescription.

Miscellaneous

MaxRecordCount does not affect QueryFeatureCount or QueryFeatureCount2.

There are two key differences between Find and QueryFeatureCount2. The first is that Find can work on multiple layers while the query methods work with a single layer. The second is that Find only works with a search string. The query methods use a queryFilter as a parameter. This allows the query to be based on either an attribute filter (SQL expression) or a spatial filter.

See Also

IMapServer2 Interface