Map service QueryFeatureData2 method

Queries and returns a record set of features that meet the query filter selection criteria for the specified layer description.

QueryFeatureData2(string MapName, LayerDescription LayerDescription, QueryFilter QueryFilter, QueryResultOptions QueryResultOptions)

Parameter

Description

MapName

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

LayerDescription

The LayerDescription object of the layer to query.

QueryFilter

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

QueryResultOptions

Use to define the output Format of a query result and a GeoTransformation to apply to the results.

Return Value

The QueryResultOptions.Format property, an esriQueryResultFormat constant, defines the result type. The result can be returned in two formats: KML and RecordSet.

When KML is the desired output, it is passed back as a URL when the Format property of the QueryResultOptions parameter is "esriQueryResultKMLAsURL" or as a MIME object when the Format property of the QueryResultOptions parameter is "esriQueryResultKMLAsMime". The file the URL points to or Mime is returned in compressed KMZ format.

When esriQueryResultRecordSetAsObject is selected as the Format in QueryResultOptions , the function returns RecordSet.

Examples

C#

MapService_MapServer mapservice = new MapService_MapServer();

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

 

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

 

MapDescription mapdesc = mapinfo.DefaultMapDescription;

MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;

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;

                  }

            }

      }

}

 

LayerDescription[] layerdescs = mapdesc.LayerDescriptions;

LayerDescription activelayerdesc = null;

 

foreach (LayerDescription layerdesc in layerdescs)

{

      if (layerdesc.LayerID == layerid)

      {

            activelayerdesc = layerdesc;

            break;

      }

}

 

//Probably defined by a call to QueryFeatureIDs

activelayerdesc.DefinitionExpression = "FID IN (214, 228, 235, 245)";

 

QueryFilter queryfilter = new QueryFilter();

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

QueryResultOptions queryresultoptions = new QueryResultOptions();

queryresultoptions.Format = esriQueryResultFormat.esriQueryResultRecordSetAsObject;

 

QueryResult queryresult = null;

try

{

      queryresult = mapservice.QueryFeatureData2(mapname, activelayerdesc, queryfilter, queryresultoptions);

}

catch (Exception ex)

{

      //Improper format of where clause will cause exception

}

 

RecordSet recordset = (RecordSet)queryresult.Object;

 

queryresultoptions.Format = esriQueryResultFormat.esriQueryResultKMLAsURL;

 

try

{

      queryresult = mapservice.QueryFeatureData2(mapname, activelayerdesc, queryfilter, queryresultoptions);

}

catch (Exception ex)

}

      // Improper format of where clause will cause exception

}

 

string kmlurl = queryresult.URL;

VB.NET

class=codesample>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 layerdescs() As LayerDescription = mapdesc.LayerDescriptions

Dim activelayerdesc As LayerDescription = Nothing

Dim layerdesc As LayerDescription

 

For Each layerdesc In layerdescs

      If layerdesc.LayerID = layerid Then

            activelayerdesc = layerdesc

            Exit For

      End If

Next

 

' Probably defined by a call to QueryFeatureIDs

activelayerdesc.DefinitionExpression = "FID IN (214, 228, 235, 245)"

Dim queryfilter As QueryFilter = New QueryFilter()

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

Dim queryresultoptions As QueryResultOptions = New QueryResultOptions()

queryresultoptions.Format = esriQueryResultFormat.esriQueryResultRecordSetAsObject

Dim queryresult As QueryResult = Nothing

 

Try

      queryresult = mapservice.QueryFeatureData2(mapname, activelayerdesc, queryfilter,queryresultoptions)

Catch ex As Exception

      ' Improper format of where clause will cause exception

End Try

 

Dim recordset As RecordSet = CType(queryresult.Object, RecordSet)

      queryresultoptions.Format = esriQueryResultFormat.esriQueryResultKMLAsURL

 

Try

      queryresult = mapservice.QueryFeatureData2(mapname, activelayerdesc, queryfilter, queryresultoptions)

Catch ex As Exception

      ' Improper format of where clause will cause exception

End Try

 

Dim kmlurl As String = queryresult.URL

11/8/2016