How to perform spatial query in arcengine using C#?

892
2
10-20-2013 07:41 AM
kju
by
New Contributor III
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.
0 Kudos
2 Replies
AlexanderGray
Occasional Contributor III
Performing a spatial query is usually a means to an end.  Without knowing what is the goal of performing the spatial query, the answer is to run the code you have specifying all the input parameters.  That will perform a spatial query.
0 Kudos
kju
by
New Contributor III
Performing a spatial query is usually a means to an end.  Without knowing what is the goal of performing the spatial query, the answer is to run the code you have specifying all the input parameters.  That will perform a spatial query.

Thanks for your response but now I now what to perform,Before posting the question,I just do not know how to use the Function above,may be I just do not what the params mean.I got it.Thanks any way.
0 Kudos