IFeatureClassExtensions Class

This class contains extension methods that extend IFeatureClass::Search method, which allow the Search method to return a .NET enumerable object instead of an ArcObjects COM cursor.


Methods

NameDescription
IFeatureClass.Search()Returns all features in the feature class with the recycling cursor.
IFeatureClass.Search(String)Returns all features in the feature class matching the given where clause with the recycling cursor.
IFeatureClass.Search(String, Boolean)Returns all features in the feature class matching the given where clause. Recycling behavior can also be controlled.
IFeatureClass.Search(String, IGeometry)Search the Feature Class for features matching the given where-clause and intersecting the given geometry with recycling cursor.
IFeatureClass.Search(String, IGeometry, esriSpatialRelEnum)Search the Feature Class for features matching the given where clause and having the given relationship to the input geometry with recycling cursor.
IFeatureClass.Search(String, IGeometry, esriSpatialRelEnum, Boolean)Search the Feature Class for features matching the given where clause and having the given relationship to the input geometry.

IFeatureClass.Search() Method

Returns all features in the feature class with the recycling cursor. If you want to use non-recycling cursor, use IFeatureClass.Search(String, Boolean).

Use dark colors for code blocksCopy
1
public static IEnumerable<IFeature> Search(this IFeatureClass fc)

Note that the search is always performed with a recycling cursor meaning that individual IFeature objects should not be referenced after the next object has been returned from the enumerator. The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must call the Search() method again. This method automatically releases the cursor after the iteration.

Usage:

Use dark colors for code blocksCopy
1
2
3
4
5
    IEnumerable<IFeature> features = featureClass.Search();
    foreach (IFeature f in features)
    {
        // perform your operation
    }

IFeatureClass.Search(String) Method

Returns all features in the feature class matching the given where clause with the recycling cursor.

Use dark colors for code blocksCopy
1
public static IEnumerable<IFeature> Search(this IFeatureClass fc, string where)
ParameterDescription
whereWhere clause. See IQueryFilter.WhereClause for the usage of the where clause string.

Note that the search is always performed with a recycling cursor meaning that individual IFeature objects should not be referenced after the next object has been returned from the enumerator. The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must call the Search() method again. This method automatically releases the cursor after the iteration.

Usage:

Use dark colors for code blocksCopy
1
2
    IEnumerable<IFeature> features = featureClass.Search("CITY_NAME='Redlands'");
    int cnt = features.Count();

IFeatureClass.Search(String, Boolean) Method

Returns all features in the feature class matching the given where clause. Recycling behavior can also be controlled. See recycling and non-recycling cursor.

ParameterDescription
whereWhere clause. See IQueryFilter.WhereClause for the usage of the where clause string.
recyclingSee IFeatureClass.Search for the usage of the recycling parameter.

The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must call the Search() method again. This method automatically releases the cursor after the iteration.

Usage:

Use dark colors for code blocksCopy
1
2
3
    //Use non-recycling parameter
    IEnumerable<IFeature> features = featureClass.Search("CITY_NAME='Redlands'", false);
    int cnt = features.Count();

IFeatureClass.Search(String, IGeometry) Method

Search the Feature Class for features matching the given where-clause and intersecting the given geometry with recycling cursor.

Use dark colors for code blocksCopy
1
public static IEnumerable<IFeature> Search(this IFeatureClass fc, string where, IGeometry geometry)
ParameterDescription
whereWhere clause. See IQueryFilter.WhereClause for the usage of the where clause string.
geometryQuery geometry. See ISpatialFilter.Geometry for more details

Only high-level geometries, envelopes and geometry bags can be used. High-level geometries are polygons, polylines, points, and multipoints. Low-level geometries including paths, rings, arcs and curves, and lines can not be used. To test whether a geometry is applicable, see if it implements the IRelationalOperator interface; if it does, it can be used. See ISpatialFilter.Geometry for more details.

Note that the search is always performed with a recycling cursor meaning that individual IFeature objects should not be referenced after a new object has been returned from the enumerator. The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must call the Search() method again. This method automatically releases the cursor after the iteration.

IFeatureClass.Search(String, IGeometry, esriSpatialRelEnum) Method

Search the Feature Class for features matching the given where clause and having the given relationship to the input geometry with recycling cursor.

Use dark colors for code blocksCopy
1
public static IEnumerable<IFeature> Search(this IFeatureClass fc, string where, IGeometry geometry, esriSpatialRelEnum spatialRel)
ParameterDescription
whereWhere clause. See IQueryFilter.WhereClause for the usage of the where clause string.
geometryQuery geometry. See ISpatialFilter.Geometry for more details.
spatialRelQuery spatial relationships. See ISpatialFilter.SpatialRel for more information.

Note that the search is always performed with a recycling cursor meaning that individual IFeature objects should not be referenced after a new object has been returned from the enumerator. The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must call the Search() method again. This method automatically releases the cursor after the iteration.

IFeatureClass.Search(String, IGeometry, esriSpatialRelEnum, Boolean)

Search the Feature Class for features matching the given where clause and having the given relationship to the input geometry.

Use dark colors for code blocksCopy
1
public static IEnumerable<IFeature> Search(this IFeatureClass fc, string where, IGeometry geometry, esriSpatialRelEnum spatialRel, bool recycling)
ParameterDescription
whereWhere clause. See IQueryFilter.WhereClause for the usage of the where clause string.
geometryQuery geometry. See ISpatialFilter.Geometry for more details.
spatialRelQuery spatial relationships. See ISpatialFilter.SpatialRel for more information.
recyclingSee IFeatureClass.Search for the usage of the recycling parameter.

The enumerator returned is a forward-only cursor that can only be used once and cannot be reused. Only one iteration via a foreach style loop or LINQ query operator, such as Count(), Where(), etc., is allowed. To reuse the enumerator, you must call the Search() method again. This method automatically releases the cursor after the iteration.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.