Mar 6, 2012

How to find feature count that intersect an envelope in Geodatabase + C#

In our previous post, we discussed about connecting the File GeoDB and returning the Workspace.

Now will see how to find feature count that intersect an envelope in the File GeoDB

// The method FileGdbWorkspaceFromPropertySet definition is present in our previous post

IWorkspace featureWorkspace = FileGdbWorkspaceFromPropertySet(gdbPath);
        IFeatureWorkspace fws = (IFeatureWorkspace)featureWorkspace;

// Method that Gets Features Count From a FeatureClass

private static int GetCountFromFeatureClass(IFeatureWorkspace fws, string parcelName, IEnvelope envelope)
        // Open the feature classes used by the queries.
        IFeatureClass parcelsFeatureClass = fws.OpenFeatureClass(parcelName);      

        //// Create the spatial filter. Note that the SubFields property specifies that only
        //// the Shape field is retrieved, since the features' attributes aren't being inspected.
        ISpatialFilter spatialFilter = new SpatialFilterClass();
        spatialFilter.Geometry = envelope;
        spatialFilter.GeometryField = parcelsFeatureClass.ShapeFieldName;
        spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
        spatialFilter.SubFields = "Shape";

        // Use IFeatureClass.FeatureCount to get a parcel count.
        return parcelsFeatureClass.FeatureCount(spatialFilter);


No comments: