问题:判断A图层要素是否在B图层范围内
解决方法:
/// <summary>
/// 检查图斑在城镇村范围内
/// </summary>
/// <returns></returns>
private bool CheckerFeatureIn(IFeature feature,IFeatureClass featureClass)
{
//判断是否在城镇村等用地内
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = feature.Shape as IGeometry;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelOverlaps;//esriSpatialRelWithin 在内部 esriSpatialRelOverlaps 空间覆盖 esriSpatialRelContains 包含
pSpatialFilter.GeometryField = featureClass.ShapeFieldName;
IFeatureCursor pCursor = featureClass.Search(pSpatialFilter, false);
IFeature feature2 = pCursor.NextFeature();
if(feature2!=null)
{
IGeometry pResultGeometry = feature2.ShapeCopy; //用作空间查询的多边形
ITopologicalOperator pTopo = feature2.ShapeCopy as ITopologicalOperator;
while (feature2 != null)//找到覆盖它的图斑
{
pResultGeometry = pTopo.Union(feature2.Shape);
pTopo = pResultGeometry as ITopologicalOperator;
feature2 = pCursor.NextFeature();
}
//判断包含关系
IRelationalOperator pRelOperator = pResultGeometry as IRelationalOperator;
if (pRelOperator.Contains(feature.Shape))
{
return true;
}
}
pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = feature.Shape as IGeometry;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;//esriSpatialRelWithin 在内部 esriSpatialRelOverlaps 空间覆盖 esriSpatialRelContains 包含
pSpatialFilter.GeometryField = featureClass.ShapeFieldName;
pCursor = featureClass.Search(pSpatialFilter, false);
feature2 = pCursor.NextFeature();
if (feature2 != null)//找到包含它的图斑
{
int a= feature.OID;
return true;
}
return false;
}