先来看看ITopologicalOperator的成员:截图来自帮助文档:
简要介绍下各个成员的汉语翻译:
1、Boundary,边界,获取一个Geometry的边界;
用法:
(1)多边形Polygon的边界获取的是Polyline
(2)Polyline获得的是IPiontColletion点集;(3)点没有边界
2、Buffer,缓冲区,可以为点、线、面做缓冲区,参数为缓冲区范围的大小,大于0向外做缓冲区,小于0向内做缓冲区;
用法:
3、Clip,叠加裁剪,从源图层中裁剪掉分割图层后的图形;参数类型为IEnvelope类型
用法:
4、Cut,分割,将一个Geometry分割为两部分。
用法:
5、Difference,区别,保留下源图层与操作图层中不同的部分。
用法:
6、Intersect,相交,求两个图层相交,返回IGeometry对象
用法:esriGeometryDimension枚举值 参数决定了返回的数据类型(点,线,面)
7、IsSimple,是否拓扑闭合
参与空间拓扑运算的几何形体,必须是拓扑上简单的(topologically simple),否则会产生esriGeometryError536错误。
当几何形体自上次验证之后并未发生变化,那么IsKnowSimple属性返回True;而IsSimple才是实际上验证几何形体是不是拓扑上简单的。因此在使用IsSimple之前检验IsKnownSimple是更有效的,特别是在循环里,如下代码:
IEnumGeometry pEnumGeom;
pEnumGeom = pGeometryBag as IEnumGeometry;
ITopologicalOperator pTopoOp;
pTopoOp = pEnumGeom.Next() as ITopologicalOperator;
while ( pTopoOp != null)
{
//首先验证IsKnownSimple因为它速度更快
//在枚举特别大的时候这样更节约时间
if (!( pTopoOp.IsKnownSimple))
{
if (!( pTopoOp.IsSimple))
pTopoOp.Simplify();
}
pTopoOp = pEnumGeom.Next()as ITopologicalOperator;
}
用法:
ITopologicalOperator pTopologBoundary = pSourceGeometry as ITopologicalOperator;
bool bIsSimple = pTopologBoundary.IsSimple;
8、Simplify,使一个Geometry拓扑闭合。Simplify方法可以让一个几何对象变得在拓扑上一致,例如在一个PointCollection中,它可以让所有的重合点(即两个点拥有相同坐标值)被移除(出发拥有不同的属性);对于SegmentCollection,它将移除重合的线段,而相交的线段会变成非相交的线段(即在相交点处产生一个顶点);对于Polygon而言,所有相交的环将被移除,所有的内外的方向将被修正,未封闭的环将被封闭
用法:
ITopologicalOperator pTopologBoundary = pSourceGeometry as ITopologicalOperator;
pTopologBoundary.Simplify();
9、Union,使Geometry组合起来
用法:
IGeometry pSourceGeometry = null, pUnionGeometry = null;
ITopologicalOperator pTopologBoundary = pSourceGeometry as ITopologicalOperator;
IGeometry pUnionGeo=pTopologBoundary.Union(pUnionGeometry);
10、开发实例——缓冲区查询
pActiveView = axMapControl1.ActiveView;
pMap = axMapControl1.Map;
IFeatureLayer pFeatureLayer = pMap.get_Layer(1) as IFeatureLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
//鼠标点击Map的点
IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
//对点对象做缓冲区运算
ITopologicalOperator pTopo;
pTopo = pPoint as ITopologicalOperator;
IGeometry pBuffer;
pBuffer = pTopo.Buffer(4);
IGeometry pGeometry = pBuffer.Envelope;
//创建空间过滤器
ISpatialFilter pSpatialFilter;
pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pGeometry;
//绑定空间过滤关系
switch (pFeatureClass.ShapeType)
{
case esriGeometryType.esriGeometryPoint:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
break;
case esriGeometryType.esriGeometryPolyline:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
break;
case esriGeometryType.esriGeometryPolygon:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
}
IFeatureSelection pFeatureSelection;
pFeatureSelection = pFeatureLayer as IFeatureSelection;
pFeatureSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
ISelectionSet pFeatSet;
pFeatSet = pFeatureSelection.SelectionSet;
ICursor pCursor;
pFeatSet.Search(null, true, out pCursor);
IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;
IFeature pFeature = pFeatureCursor.NextFeature();
//遍历所有符合要求的要素,将它们加入要素选择集中
while (pFeature != null)
{
//将当前的图层加入当前图层的要素选择集
pMap.SelectFeature(pFeatureLayer, pFeature);
pFeature = pFeatureCursor.NextFeature();
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);