Is there a simple way to count number of features returned by IMapServer3 object

356
2
04-07-2020 02:21 AM
chrisweaves
New Contributor II

Using the arcobjects SDK (10.7.1) I am simply trying to count the number of features returned by a feature service query, here is some sample code:

    IMapServer3 ms = (IMapServer3) this.mapServerDataAccess;

    ...

    // query for relevant features using spatial filter
    QueryResult queryResult = (QueryResult) ms.queryData(mapName,
        getTableDescription(mapServerInfo, layerId),
        spatialFilter, qResultOptions);
    RecordSet rs = (RecordSet) queryResult.getObject();

I can count the number of features returned by getting a cursor and iterating through the cursor items incrementing a counter along the way but this is extremely slow and when working with layers with 2+ million points this is not feasable.  Is there a way of getting the count of the number of features in the returned RecordSet?  I couldn't see anything obvious.

Appreciate your help.

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

If you use a IRecordSet2 class, it has the Table property. You should be able to use the ITable's RowCount method.

0 Kudos
chrisweaves
New Contributor II

Thanks Ken, I'll give that a try!!

0 Kudos