kjulistened

How to perform spatial query in arcengine using C#?

Discussion created by kjulistened on Oct 20, 2013
Latest reply on Oct 21, 2013 by kjulistened
public ESRI.ArcGIS.Geodatabase.IFeatureCursor PerformSpatialQuery(ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass, ESRI.ArcGIS.Geometry.IGeometry searchGeometry, ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum spatialRelation, System.String whereClause) {
            // create a spatial query filter
            ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();

            // specify the geometry to query with
            spatialFilter.Geometry = searchGeometry;

            // specify what the geometry field is called on the Feature Class that we will be querying against
            System.String nameOfShapeField = featureClass.ShapeFieldName;
            spatialFilter.GeometryField = nameOfShapeField;

            // specify the type of spatial operation to use
            spatialFilter.SpatialRel = spatialRelation;

            // create the where statement
            spatialFilter.WhereClause = whereClause;

            // perform the query and use a cursor to hold the results
            ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
            queryFilter = (ESRI.ArcGIS.Geodatabase.IQueryFilter)spatialFilter;
            ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);

            return featureCursor;
        }

As the help document gives the code above,how to fire the function? Can you give me an example?Or somebody give me some ideal to perform the spatial query?Thans very much,For I really do not know what to do.

Outcomes