Map service QueryRowIDs method
Queries and returns a set of object ids that meet the query filter selection criteria for the specified layer or table description.
The name of the map (data frame) that contains the layer associated with the MapTableDescription parameter.
Used to set the definition expression to a layer or a standalone table.
An attribute or spatial query that defines the selection criteria for the layer or standalone table associated with the MapTableDescription parameter.
The function returns an array of integers (int[ ]) unlike QueryFeatureIDs or QueryFeatureIDs2. Each integer represents a unique identifier for each feature (FID) or row in the layer or table queried. The map service assigns FIDs to each feature in every feature layer it contains. A SOAP exception will be thrown if the SQL expression in the query filter is invalid.
The QueryFilter can be an attribute query (SQL expression), 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.
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 shapefiles or File GeoDatabases, the syntax is <FieldName> = date 'YYYY-MM-DD'; for Access-based Personal GeoDatabases the syntax is #YYYY-MM-DD#. For SDE databases, check with the specific database's help.
Geometry is only required for spatial query since a table does not contain geometry. If a spatial filter is used for a standalone table, the Geometry set in SpatialFilter.FilterGeometry is ignored. Spatial filter geometry should meet the following criteria:
- It should have the Spatial Reference System defined. In cases where it is not defined, the coordinate system is assumed to be in DataFrame's coordinate system.
- It must be one of the high-level geometries i.e. Point, Multipoint, Polyline, Polygon or Multipatch. Low-level geometry e.g. BezierCurve, CircularCurve must be wrapped into a high-level geometry.
- It must be topologically correct. For more information, see Remarks on Polygon.
A DefinitionExpression can be set on a layer or a standalone table in order to limit layer features or rows available for display or query. This expression can 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 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.
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 all sale region features that fall within the North region and are managed by Bob.
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 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'".
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 all sale region features with sales over 1000 and are managed by Bob. QueryData honors the DefinitionExpression set in LayerDescription.
Page through Result
Results from QueryRowIDs can be used to page through a result. When a query is expected to return a lot of rows and showing all those records on a single page is not desirable, you may use the following steps to page through your result and get records for a selected subset on demand:
There are two key differences between Find and this method:
- 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.