ArcObjects Library Reference  (GeoDatabase)    

ISpatialFilter Example


public IFeatureCursor GetStreetsInEnvelope(IFeatureClass featureClass)


  // Create the envelope and define its position.

  IEnvelope envelope = new EnvelopeClass();

  envelope.PutCoords(-84.4078, 33.7787, -84.3856, 33.7997);

  // Create the spatial filter and set its spatial constraints.

  ISpatialFilter spatialFilter = new SpatialFilterClass();

  spatialFilter.Geometry = envelope;

  spatialFilter.GeometryField = featureClass.ShapeFieldName;

  spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

  // Set the attribute constraints and subfields.

  // We want to exclude ramps, highways and interstates.

  spatialFilter.WhereClause = "NAME <> 'Ramp' AND PRE_TYPE NOT IN ('Hwy', 'I')";

  spatialFilter.SubFields = "NAME, TYPE";


  // Execute the query.

  IFeatureCursor featureCursor = featureClass.Search(spatialFilter, true);

  return featureCursor;


[Visual Basic 6.0, Visual Basic .NET, C++]
No example is available for Visual Basic 6.0, Visual Basic .NET, or C++. To view a C# example, click the Language Filter button Language Filter in the upper-left corner of the page.