ISpatialFilter接口详细介绍–附代码

ISpatialFilter是一个包含空间和属性限制的QueryFilter。因此可以使用SpatialFilter来限制从要素类中获得的要素集。ISpatialFilter继承IQueryFilter接口,因此可以指定一个whereclause、返回的colunms或者指定输出图形的空间参考。
使用spatial filter执行空间查询,常将其作为IFeatureClass::Search、IFeatureClass::Select或feature layers上相似方法的参数。
需要Geometry,GeometryField和SpatialRel属性。
Geometry是源图形,根据与其的关系执行空间选择。GeometryField是图形字段名,将其中的图形与源图形比较。SpatialRel属性将一个esriSpatialRelEnum传入来指定空间关系。
使用esriSearchOrder指定SearchOrder。当指定属性查询后,该属性将指定先执行那一部分查询,该属性仅对SDE数据源有效。
SaptialRelDescription是个字符串,可代替SpatialRel属性定义额外的空间关系。这种情况下,SpatialRel参数必须设置成esriSpatialRelRelation。
esriGeometry提供其他方式执行空间查询。
成员
除了IQueryFilter的成员外,又增加了自己的成员
FilterOwnsGeometry,Geometry,GeometryEx,GeometryField,SearchOrder,SpatialRel,SpatialRelDescription,
ISpatialFilter.SpatialRelDescription属性
该要素描述了查询的图形和返回的图形之间的关系。该字符串中有9个字符,可以是’F’,’T’或’*’;例如,TT*FFT***表示包含。
SpatialRelDescription表示两个形状之间任何可能的空间关系。

ISpatialFilter Example

[C#]
第一种类型:
NOTE:要用到ISpatialFilter的三个方法Geometry,GeometryField和SpatialRel。
public void ISpatialFilter_(IFeatureClass featureClass)
{
       //Create a point to use for the search;
       ESRI.ArcGIS.Geometry.IPoint point=new ESRI.ArcGIS.Geometry.PointClass();
       point.PutCoords(-117.946,35.823);
       //Getting a reference;
       ISpatialFilter spatialFilter=new SpatialFilterClass();
       //Setting the Geometry,GeometryField and SpatialRel parameters;   
       spatialFilter.Geometry=point;
       spatialFilter.GeometryField=featureClass.ShapeFieldName;
       spatialFilter.SpatialRel=esriSpatialRelEnum.esriSpatialRelIntersects;
       //Execute the spatiafilter;
       IFeatureCursor featureCursor=featureClass.Search(spatialFilter,false);

}
第二种类型
IGeometry pGeometry = m_MapControl.TrackPolygon() as IGeometry;<br data-filtered="filtered">
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();<br data-filtered="filtered">
                pSpatialFilter.Geometry = pGeometry;<br data-filtered="filtered">
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;<br data-filtered="filtered">
<br data-filtered="filtered">
                for (int i = 0; i < pListLayer.Count; i++)<br data-filtered="filtered">
                {<br data-filtered="filtered">
                    IFeatureClass pFeatureClass = pListLayer[i].FeatureClass;<br data-filtered="filtered">
                    IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);<br data-filtered="filtered">
                    IFeature pFeature = pFeatureCursor.NextFeature();<br data-filtered="filtered">
                    //int Index = m_Feature.Fields.FindField("STANO");<br data-filtered="filtered">
                    while (pFeature != null)<br data-filtered="filtered">
                    {<br data-filtered="filtered">
                        m_Feature = pFeature;<br data-filtered="filtered">
                        int Index = m_Feature.Fields.FindField("STANO");<br data-filtered="filtered">
                        pDictionary.Add(m_Feature.get_Value(Index).ToString(), pListLayer[i].Name);<br data-filtered="filtered">
                        pFeature = pFeatureCursor.NextFeature();<br data-filtered="filtered">
                    }<br data-filtered="filtered">
                }<br data-filtered="filtered">
<br data-filtered="filtered">
                int count = pDictionary.Count;

转载自:https://blog.csdn.net/Prince999999/article/details/79257619

You may also like...