ArcObjects Library Reference (Carto)  

IMapServer2.QueryFeatureData Method

Returns a record set of features that meet the query filter selection criteria for the specified layer.

[Visual Basic .NET]
Public Function QueryFeatureData ( _
    ByVal MapName As String, _
    ByVal LayerID As Integer, _
    ByVal Filter As IQueryFilter _
) As IRecordSet
[C#]
public IRecordSet QueryFeatureData (
    string MapName,
    int LayerID,
    IQueryFilter Filter
);
[C++]
HRESULT QueryFeatureData(
  BSTR MapName,
  long LayerID,
  IQueryFilter* Filter,
  IRecordSet** recordSet
);
[C++]

Parameters

MapName [in]   MapName is a parameter of type BSTR LayerID [in]   LayerID is a parameter of type long Filter [in]

  Filter is a parameter of type IQueryFilter

recordSet [out, retval]

  recordSet is a parameter of type IRecordSet

Product Availability

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

Remarks

QueryFeatureData returns the records of map features that match the parameters of a given query filter. QueryFeatureData returns a RecordSet .

QueryFeatureData requires a number of input parameters. These include: a Name, LayerID, and a QueryFilter. The QueryFilter can be an attribute query (SQL espression), a spatial query, a combination of both or null.

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 databases help.

It can be set to null or Nothing to retrieve all data (which is also limited by MaxRecordCount)

If geometry is not desired in the output RecordSet, IQuerFilters SubFields must be defined without Shape field. When SubFields is empty or includes Shape, IRecordSet will include the fields "shape_length" and "shape_area". If the desired spatial reference of the output geometry is different than the original one, OutputSpatialReference should be used. Otherwise geometry is returned in the same spatial reference system as the DefaultMapDescription by default. When SubFields is not defined or = *, it returns all visible fields. Invisible or invalid field names or field aliases must not be included in SubFields string or it will return an error.  Please note ObjectID field is always returned regardless of whether it is in the SubFields or not. Only expection is when DISTINCT is used.

SearchShape 

Geometry set in ISpatialFilter should meet the following criteria:

Results

QueryFeatureData honors field visibility set in the source map document. Field aliases, set in the source map document, are honored only when working with the MapServer WSDL or accessing a MapServer object through an AGSServerConnection (LAN or internet), but not honored for DCOM connection. However, the RecordSet does NOT honor any field formatting set in the source map.

Geometry is always returned in the same spatial reference system as the DefaultMapDescription, even though the source data of a layer may be in a different coordinate system, unless OutputSpatialReference is explicitly set to another coordinate system by the user (for SOAP/WSDL, both OutputSpatialReference & SpatialReferenceFieldName properties must be set). To get the coordinate system, IField::GeometryDef should be used.

In some cases, may be for performance reasons, you may want to limit or adjust the geometry being returned in the record set result. You cannot adjust returned geometry using QueryFeatureData. You will need to use QueryFeatureData2 in order to do this.

In order to control the amount of information MapServer needs to process for a query, a maximum number of records can be set. This value is contained in the MaxRecordCount property on IMapServerInit2. The default value for this property is 500. If 600 features match a given query only the first 500 results will be returned. You will be unable to access the remaining 100 records. To be able to access these records the MaxRecordCount would need to be increased to 600. MaxRecordCount can also be changed by modifying the MaxRecordCount XML tag in the MapServer's configuration file.

Miscellaneous

There are two key differences between Find and QueryFeatureData. 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