Map service QueryFeatureCount2 method

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

QueryFeatureCount2(string MapName, LayerDescription LayerDescription, QueryFilter QueryFilter)

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.

Return Value

An integer value indicating the number of features that meet the selection criteria. A SOAP exception will be thrown when the SQL expression in the query filter is invalid.

Remarks

Definitions applied to the LayerDescription input parameter will filter the returned feature count.

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;

                  }

            }

      }

}

LayerDescription[] layerdescs = mapdesc.LayerDescriptions;

LayerDescription activelayerdesc = null;

foreach (LayerDescription layerdesc in layerdescs)

{

      if (layerdesc.LayerID == layerid)

      {

            activelayerdesc = layerdesc;

            break;

      }

}

activelayerdesc.DefinitionExpression = "POP_CNTRY > 50000000";

EnvelopeN envelope = new EnvelopeN();

envelope.XMin = 0.0;

envelope.YMin = 0.0;

envelope.XMax = 180.0;

envelope.YMax = 90.0;

SpatialFilter spatialfilter = new SpatialFilter();

spatialfilter.FilterGeometry = envelope;

spatialfilter.GeometryFieldName = geometryfieldname;

spatialfilter.SpatialRel= esriSpatialRelEnum.esriSpatialRelIntersects;

int featurecount = mapservice.QueryFeatureCount2(mapname, activelayerdesc, spatialfilter);

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

 

activelayerdesc.DefinitionExpression = "POP_CNTRY > 50000000"

 

Dim envelope As EnvelopeN = New EnvelopeN()

envelope.XMin = 0.0

envelope.YMin = 0.0

envelope.XMax = 180.0

envelope.YMax = 90.0

 

Dim spatialfilter As SpatialFilter = New SpatialFilter()

spatialfilter.FilterGeometry = envelope

spatialfilter.GeometryFieldName = geomeTryfieldname

spatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects

 

Dim featurecount As Integer = mapservice.QueryFeatureCount2(mapname, activelayerdesc, spatialfilter)

10/23/2013