Map service QueryFeatureData method

Queries and returns a record set of features (geometry and attributes) that meet the query filter selection criteria for the specified layer ID.

QueryFeatureData(string MapName, int LayerID, QueryFilter)

Parameter

Description

MapName

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

LayerID

The layer id of the layer to query.

QueryFilter

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

Return Value

A RecordSet that contains an array of fields and records. All fields will be returned. In addition, an FID field is included and defines a unique integer id for each feature. A SOAP exception will be thrown when the SQL expression in the query filter is invalid.

Remarks

To determine which SQL query parameters can be used with a layer, use the GetSQLSyntaxInfo method.

The query filter will override any layer definition queries defined in the map service or defined via the LayerDescription.DefintionExpression property. To apply both query filters, the layer definition query expression and the new query filter will need to be combined for use with this method.

The number of records returned from a call to this method may be restricted by the map service. The default maximum value for the number of results returned is 500. If 600 records are matched, only the first 500 results will be returned. The maximum number of results cannot be changed via the ArcGIS Server SOAP API. The map service itself must be configured to return more results, if necessary. Note that the QueryFeatureCount and QueryFeatureIDs methods are not restricted by this limitation. As a result, you can determine the count and the feature ids of features that meet the query filter criteria. To iterate through blocks of results, use the QueryFilter.WhereClause to define a constraint based on a set of feature ids. For example, define a query filter with the where clause "CITYNAME = 'Washington'". Call the QueryFeatureIDs method to return a set of feature ids that match the query filter. The feature id is a unique integer id for each feature. They are stored in the FID field for each feature layer and maintained by the map service. Before calling this method to return a record set, select a block of feature ids to constrain the existing query filter. For example, append the clause "AND FID IN (213, 228)" so only the features that have feature ids in this collection will be returned. In this manner you can iterate through any size result set, as long as the block size is less than the maximum number of records a map service can return. In this example, the block size is two (two feature ids are included).

Examples

C#

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;

int layerid = 0;

string geometryfieldname = string.Empty;

foreach (MapLayerInfo layerinfo in maplayerinfos)

{

      if (layerinfo.Name == "countries")

      {

            layerid = layerinfo.LayerID;

            Field[] fields = layerinfo.Fields.FieldArray;

            foreach (Field field in fields)

            {

                  if (field.Type == esriFieldType.esriFieldTypeGeometry)

                  }

                        geometryfieldname = field.Name;

                        break;

                  }

            }

      }

}

 

QueryFilter queryfilter = new QueryFilter();

queryfilter.WhereClause = "CNTRY_NAME LIKE '%United%'";

RecordSet recordset = null;

 

try

{

      recordset = mapservice.QueryFeatureData(mapname, layerid, queryfilter);

}

catch (Exception ex)

}

      // Improper format of where clause will cause exception

}

 

if (recordset != null)

{

      string fieldsoutput = string.Empty;

      foreach (Field field in recordset.Fields.FieldArray)

      {

            fieldsoutput += field.Name + "\t";

            foreach (Record record in recordset.Records)

            {

                  string valuesoutput = string.Empty;

                  object[] values = record.Values;

                  int v = 0;

                  foreach (Field field in recordset.Fields.FieldArray)

                  {

                        valuesoutput += values[v].ToString() + "\t";

                        v++;

                  }

            }

      }

}

VB.NET

Dim mapservice As MapService_MapServer = New MapService_MapServer()

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer"

 

Dim mapname As String = mapservice.GetDefaultMapName()

Dim mapinfo As MapServerInfo = mapservice.GetServerInfo(mapname)

Dim mapdesc As MapDescription = mapinfo.DefaultMapDescription

Dim maplayerinfos() As MapLayerInfo = mapinfo.MapLayerInfos

 

Dim layerid As Integer = 0

Dim geomeTryfieldname As String = String.Empty

Dim layerinfo As MapLayerInfo

 

For Each layerinfo In maplayerinfos

      If layerinfo.Name = "countries" Then

            layerid = layerinfo.LayerID

            Dim fields() As Field = layerinfo.Fields.FieldArray

            Dim field As Field

 

            For Each field In fields

                  If field.Type = esriFieldType.esriFieldTypeGeometry Then

                        geomeTryfieldname = field.Name

                        Exit For

                  End If

            Next

      End If

Next

 

Dim queryfilter As QueryFilter = New QueryFilter()

queryfilter.WhereClause = "CNTRY_NAME LIKE '%United%'"

Dim recordset As RecordSet = Nothing

 

Try

      recordset = mapservice.QueryFeatureData(mapname, layerid, queryfilter)

Catch ex As Exception

' Improper format of where clause will cause exception

End Try

 

If Not recordset Is Nothing Then

      Dim fieldsoutput As String = String.Empty

      Dim field As Field

 

      For Each field In recordset.Fields.FieldArray

            fieldsoutput += field.Name + vbTab

      Next

 

      Dim record As Record

      For Each record In recordset.Records

            Dim valuesoutput As String = String.Empty

            Dim values() As Object = record.Values

            Dim v As Integer = 0

            Dim field2 As Field

            For Each field2 In recordset.Fields.FieldArray

                  valuesoutput += values(v).ToString() + vbTab

                  v = v + 1

            Next

      Next

End If

Java

String serviceURL = "http://localhost:6080/arcgis/services/MapService/MapServer";

MapServerBindingStub mapService = new MapServerBindingStub(serviceURL);

 

String mapName = mapService.getDefaultMapName();

MapServerInfo mapInfo = mapService.getServerInfo(mapName);

MapLayerInfo[] mapLayerInfos = mapInfo.getMapLayerInfos();

int layerID = 0;

 

for (MapLayerInfo layerInfo : mapLayerInfos)

{

if (layerInfo.getName().equals("States"))

{

         layerID = layerInfo.getLayerID();

}

}

 

QueryFilter queryFilter = new QueryFilter();

queryFilter.setWhereClause("STATE_NAME LIKE '%Ca%'");

 

RecordSet recordSet = null; 

recordSet = mapService.queryFeatureData(mapName, layerID, queryFilter);

 

Field[] fields = recordSet.getFields().getFieldArray();

System.out.println("Field Names...");

 

for(Field field : fields)

{

      System.out.println(field.getAliasName());

}

10/23/2013