Map service QueryFeatureIDs method

Queries and returns a set of feature ids that meet the query filter selection criteria for the specified layer ID.

QueryFeatureIDs(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

An FIDSet that contains an array of integers. Each integer represents a unique identifier for each feature (FID) in the layer 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.

Remarks

The array of integers contained by the FIDSet returned from this method is accessible via the FIDSet.FIDArray property. It is not restricted by limitations on the maximum number of results returned by a map service. The integer array can be used to define selected features in a layer for display in a map (LayerDescription.SelectionFeatures) or the extent of selected features (FeatureExtent.FeatureIDs).

Although the methods QueryFeatureData, QueryHyperlinks, Find and Identify are all restricted in the number of records they can return, this method offers a means to iterate through any number of results. Before calling a restricted query method, use this method to return a set of feature ids that match the query filter. 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 (213 and 228) 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).

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.

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;

 

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%'";

 

FIDSet fidset = null;

try

{

      fidset = mapservice.QueryFeatureIDs(mapname, layerid, queryfilter);

}

catch (Exception ex)

{

      // Improper format of where clause will cause exception

}

 

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

 

foreach (LayerDescription layerdesc in layerdescriptions)

{

      if (layerdesc.LayerID == layerid)

      {

            layerdesc.SelectionFeatures = fidset.FIDArray;

      }

}

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 fidset As FIDSet = Nothing

 

Try

      fidset = mapservice.QueryFeatureIDs(mapname, layerid, queryfilter)

Catch ex As Exception

      ' Improper format of where clause will cause exception

End Try

 

Dim layerdescriptions() As LayerDescription = mapdesc.LayerDescriptions

Dim layerdesc As LayerDescription

 

For Each layerdesc In layerdescriptions

      If layerdesc.LayerID = layerid Then

            layerdesc.SelectionFeatures = fidset.FIDArray

      End If

Next

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%'");

 

FIDSet fidSet = mapService.queryFeatureIDs(mapName, layerID, queryFilter);

 

int[] fids = fidSet.getFIDArray();

for(int fid : fids)

{

      System.out.println("FID: " + fid);

}

2/28/2020