Map service QueryFeatureCount method

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

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

The value returned is not restricted by limitations on the maximum number of results returned by a map service.

The methods QueryFeatureData, QueryHyperlinks, Find and Identify are restricted in the maximum number of results they can return. Currently, no method is available to return the maximum result count. To confirm that your application code has not encountered the limit, use this method to return the total result count and compare it to the number of results from the restricted methods. If the result from this method is greater, you have surpassed the result limit. See the QueryFeatureIDs method discussion for information on working with result sets that exceed the map service limit.

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;

                  }

            }

      }

}

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;

spatialfilter.WhereClause = "POP_CNTRY > 50000000";

int featurecount = mapservice.QueryFeatureCount(mapname, layerid, 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 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

spatialfilter.WhereClause = "POP_CNTRY > 50000000"

 

Dim featurecount As Integer = mapservice.QueryFeatureCount(mapname, layerid, spatialfilter)

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;

String geometryFieldName = "";

 

for (MapLayerInfo layerInfo : mapLayerInfos)

{

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

      {

            layerID = layerInfo.getLayerID();

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

            for (Field field : fields)

            {

                  if (field.getType() == EsriFieldType.esriFieldTypeGeometry)

                  {

                        geometryFieldName = field.getName();

                        break;

                  }

            }

      }

}

 

EnvelopeN envelope = new EnvelopeN();

envelope.setXMin(-180.0);

envelope.setYMin(0.0);

envelope.setXMax(180.0);

envelope.setYMax(90.0);

 

SpatialFilter spatialFilter = new SpatialFilter();

spatialFilter.setFilterGeometry(envelope);

spatialFilter.setGeometryFieldName(geometryFieldName);

spatialFilter.setSpatialRel(EsriSpatialRelEnum.esriSpatialRelIntersects);

 

//'T***F****' - Does not touch the boundary and interiors intersect  

spatialFilter.setSpatialRelDescription("T***F****");

 

spatialFilter.setWhereClause("POP1990 > 550043");

spatialFilter.setSearchOrder(EsriSearchOrder.esriSearchOrderAttribute);

 

int featureCount = mapService.queryFeatureCount(mapName, layerID, spatialFilter);

System.out.println("Feature Count: " + featureCount);

11/8/2016