Select to view content in your preferred language

rowCount of FeatureCursor and SpatialFilter

4060
2
07-15-2010 01:33 PM
LeoDonahue
Deactivated User
ArcGIS Server - ArcObjects Java 9.3.1

I want to get the number of rows in the IFeatureCursor, after appying a ISpatialFilter to a IFeatureClass

Can I get the row count without the need for rowcountFeatureLayer, then assigning it the ifeatLayer? I feel like this is an uneeded step, but I can't seem to figure out an easier way.

private FeatureLayer rowcountFeatureLayer;
private MapServer ms;
 
... a bunch of other stuff...
 
public void checkLayer(IFeature ifeat, IFeatureLayer ifeatLayer, IFeatureClass ifeatClass, IFeatureCursor ifeatCursor, ISpatialFilter ispatFilter, String mapName, int layerID) {
 
        try{
 
            ifeatLayer = (IFeatureLayer) ms.getLayer(mapName, layerID);
            ifeatClass = ifeatLayer.getFeatureClass();
 
            // Create a SpatialFilter from the server context, and set its geometry and spatial relation.
            ispatFilter = (SpatialFilter) context.createObject(SpatialFilter.getClsid());
            ispatFilter.setGeometryByRef(parcelPolygon);
            ispatFilter.setGeometryField(ifeatClass.getShapeFieldName());
            ispatFilter.setSpatialRel(spatialRelation);
 
            // Apply the spatial filter to the FeatureClass and assign that to a FeatureCursor object
            ifeatCursor = ifeatClass.search(ispatFilter, true);
            int fieldCount = ifeatCursor.getFields().getFieldCount();
 
            // Create a Feature from the server context
            ifeat = (Feature) context.createObject(Feature.getClsid());
 
            // Determine how many rows in this FeatureLayer were returned by the spatial filter.
            rowcountFeatureLayer = (FeatureLayer)ifeatLayer;
            int rowcount = rowcountFeatureLayer.rowCount(ispatFilter);
            System.out.println("Row Count: " + rowcount);
 
            ifeat = ifeatCursor.nextFeature();
 
... other stuff
0 Kudos
2 Replies
JamesCrandall
MVP Alum
Why not apply .SelectFeatures on an IFeatureSelection with your ISpatialFilter as a parameter?

(Here is a snip from one of my procedures that is NOT complete but might help):

Dim inLyr As IFeatureLayer
Dim FeatSel As IFeatureSelection = inLyr

Dim pSpatialFilter As ISpatialFilter
Dim pField As String = "Shape"

Dim pFCursor As IFeatureCursor
PolySel.SelectionSet.Search(Nothing, False, pFCursor)

pFCursor = Nothing
PolySel.SelectionSet.Search(Nothing, False, pFCursor)
pPoly = pFCursor.NextFeature

pSpatialFilter = New SpatialFilter
   With pSpatialFilter
    .Geometry = pPoly.ShapeCopy
    .OutputSpatialReference(SearchLayer.FeatureClass.ShapeFieldName) = pPoly.Shape.SpatialReference
    .GeometryField = SearchLayer.FeatureClass.ShapeFieldName
    .SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
   End With

'perform the selection on the layers
FeatSel.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, False)
Dim ct As Integer = FeatSel.SelectionSet.Count
0 Kudos
LeoDonahue
Deactivated User
Why not apply .SelectFeatures on an IFeatureSelection with your ISpatialFilter as a parameter?

Dim inLyr As IFeatureLayer
Dim FeatSel As IFeatureSelection = inLyr
 
'perform the selection on the layers
FeatSel.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, False)
Dim ct As Integer = FeatSel.SelectionSet.Count


Thanks James for your code example,

Where I am calling rowCount on a FeatureLayer, you are calling selectFeatures on IFeatureSelection. Either way, we are both using a second object to get the count.

In your case, you assign inLyr (which is an IFeatureLayer) to a FeatureSelection and call count from ISelectionSet.
In my case, I assign an IFeatureLayer to a FeatureLayer (rowcountFeatureLayer) and then get the rowCount() from FeatureLayer.

I guess what we have is good enough, since rowcountFeatureLayer is my first concrete class variable, everything else has been an Interface in my code.

Since I'm not manipulating any tables, getting the rowCount on a FeatureLayer based on a IQueryFilter is ok, I guess?
0 Kudos