Map Service QueryRowCount method

Queries and returns the number of features from a table or a layer that meet the query filter selection criteria for the specified layer or table description.

 

QueryRowCount(string MapName, MapTableDescription MapTableDescription, QueryFilter QueryFilter)

 

Parameter

Description

MapName

The name of the map (data frame) that contains the layer associated with the MapTableDescription parameter.

MapTableDescription

Used to set the definition expression to a layer or a standalone table.

QueryFilter

An attribute or spatial query that defines the selection criteria for the layer or standalone table associated with the MapTableDescription parameter.

 

Return Value

 

An integer value indicating the number of features that meet the selection criteria. A SOAP exception will be thrown when the SQL expression in the query filter is invalid.

 

Remarks

 

The QueryFilter can be an attribute query (SQL espression), a spatial query, or a combination of both.

 

MapTableDescription is an identifier class implemented by LayerDescription and StandaloneTableDescription classes.

LayerDescription for a layer can be obtained from MapServerInfo.DefaultMapDescription while StandaloneTableDescription can be obtained using MapServerInfo.StandaloneTableDescriptions properties.

 

Query Filters

 

QueryFilter provides the ability to query based on attribute filter (SQL expression) a spatial filter, or a combination of both.

 

Attribute Filters:

 

 

Spatial Filters:

 

These never apply to standalone tables since they contain no geometry does not contain geometry. If a spatial filter is used for a standalone table, the geometry set in SpatialFilter.FilterGeometry is ignored. The geometry in a spatial filter should meet the following criteria:

 

Definition Expressions

 

A 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 or StandaloneTableDescription will override any definition query set in the source map. This method honors the 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 DefinitionExpression 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. This method 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 definition 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. This method honors the DefinitionExpression set in LayerDescription.

 

Miscellaneous

 

The maximum record count set on the Service (GetServiceConfigurationInfo.MaxRecordCount) does not affect QueryRowIDs or this method.

 

There are two key differences between Find and this method:

 

  1. The first is that Find can work on multiple layers while the query methods work with a single layer.

  2. 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.