IFeatureSelection.SelectFeatures
官方解释:Selects features based upon the specifed criteria and combination method.
译文:根据指定的标准和组合方法选择要素。
有人这样解释:已知一个要素图层和我们的选择条件,寻找出符合要求的要素并闪烁显示
指定的标准,即为ISpatialFilter,那我们要考虑ISpatialFilter.Geometry的属性会对结果产生什么影响?
这个Geometry是否应该是合并一整个图层的要素,还是单独来一个一个判定?
如果按照上面的解释,应该是单独判定。
即为:不断改变ISpatialFilter.Geometry,进而改变ISpatialFilter
问题:对esriSpatialRelEnum的理解有问题
esriSpatialRelWithin Description: Query Geometry is Within Target Geometry.
译文:within 查询包含在目标Geometry内的Geometry。
Remarks:Returns a feature if its shape wholly contains the search geometry. Valid for all shape type combinations.
译文:返回一个要素,它的形状包含了这个搜索使用的Geometry。
这里Description与Remarks产生了分歧,或者我的理解出了问题。
但测试结果符合Remarks的解释。
-
//根据要查询的坐标构造一个点
-
IPoint targetPoint = new PointClass();
-
targetPoint.PutCoords(x, y);
-
//构造空间过滤器
-
ISpatialFilter spatialFilter = new SpatialFilterClass();
-
spatialFilter.Geometry = targetPoint;
-
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;//查询的是包含关系
-
//在要素类上用空间过滤器进行查询即可
-
IFeatureCursor cursor = riverGridFeatureClass.Search(spatialFilter, false);
由以上代码可以看出:Within查询的是包含SpatialFilter.Geometry的Geometry。
这也就意味着,如果你用AE来写ArcMap中的空间查找,其中的
contain the source layer feature 即:目标要素包含源图层要素选项
对应的过滤关系为
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;
are within the source layer feature 即:目标要素被源图层要素包含选项
对应的过滤关系为
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
注意contain对应的Within、within对应的Contains