欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

判断A图层完全包含B图层的要素--(1)空间查询之esriSpatialRelEnum.esriSpatialRelContains(包含)

程序员文章站 2022-06-12 16:48:23
...

查询源图层包含目标图层的整体思路:
1、打开工作空间→
2、获取源featureclass/目标featureclass→
3、定义一个空间查询过滤器,设置查询条件:esriSpatialRelEnum.esriSpatialRelContains→
4、遍历源featureclss的feature,与目标featureclass进行查询,每次查询得到的结果是一个FeatureCursor,将所有的FeatureCursor存储起来(List)
5、通过List得到所有的Geometry记录,然后将这些Geometry记录输出

//1、连接工作空间
...ESRI.ArcGIS.Geodatabase.IWorkspace xWorkspace =...
//2、获取源图层和目标图层
...ESRI.ArcGIS.Geodatabase.IFeatureClass xFeatureClass1 = ...//源图层(FeatureClass)
...ESRI.ArcGIS.Geodatabase.IFeatureClass xFeatureClass2 =...//目标图层(FeatureClass)
//3、定义查询
ESRI.ArcGIS.Geodatabase.ISpatialFilter xSpatialFilter = new SpatialFilterClass
            {
                SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelContains//查询条件
            };//定义一个空间查询过滤器
            
//4、遍历Feature
List<IFeatureCursor> listFeatureCursor = new List<IFeatureCursor>();//存储每次查询到的结果
IFeatureCursor xFeatureCursor1 = xFeatureClass1.Search(null, false);//xFeatureClass1的cursor
IFeature xFeature1 = xFeatureCursor1.NextFeature();
while (xFeature1 != null)
            {
                //遍历xFeatureClass1的每个Feature,然后和xFeatureClass2进行查询,查询得到两个要素数据集之间满足查询条件的结果
                IFeatureCursor xFeatureCursor = null;//xFeatureClass1和xFeatureClass2查询之后结果的cursor
                IGeometry xGeometry1 = xFeature1.Shape;
                xSpatialFilter.Geometry = xGeometry1;
                xFeatureCursor = xFeatureClass2.Search(xSpatialFilter, false);//在xFeatureClass2中根据查询条件进行查询
                listFeatureCursor.Add(xFeatureCursor);
                xFeature1 = xFeatureCursor1.NextFeature();
            }
//释放游标      System.Runtime.InteropServices.Marshal.ReleaseComObject(xFeatureCursor1);
//5、得到所有的Geomery
List<IGeometry> listGeometry = new List<IGeometry>();//存储查询得到的所有Geometry
for (int i = 0; i < listFeatureCursor.Count; i++)
            {
                IFeatureCursor xFeatureCursor = listFeatureCursor[i];
                IFeature xFeature = xFeatureCursor.NextFeature();
                while(xFeature!=null)
                {
                    IGeometry xGeometry = xFeature.Shape;
                    listGeometry.Add(xGeometry);
                    xFeature = xFeatureCursor.NextFeature();
                }
                
            }
//6、最后可以根据需要将Geometry按照指定格式输出
...
相关标签: AE二次开发