ArcEngine的拓扑分析之ITopologicalOperator

先来看看ITopologicalOperator的成员:截图来自帮助文档:


简要介绍下各个成员的汉语翻译:

1、Boundary,边界,获取一个Geometry的边界;

用法:

[csharp]  view plain  copy
 print ?
  1. ITopologicalOperator pTopologBoundary = pGeo as ITopologicalOperator;  
  2. IGeometry pGeometry = pTopologBoundary.Boundary;  
(1)多边形Polygon的边界获取的是Polyline

(2)Polyline获得的是IPiontColletion点集;(3)点没有边界


2、Buffer,缓冲区,可以为点、线、面做缓冲区,参数为缓冲区范围的大小,大于0向外做缓冲区,小于0向内做缓冲区;

用法:

[csharp]  view plain  copy
 print ?
  1. ITopologicalOperator pTopologBoundary = pGeo as ITopologicalOperator;  
  2. Geometry pGeometry = pTopologBoundary.Buffer(2);  


3、Clip,叠加裁剪,从源图层中裁剪掉分割图层后的图形;参数类型为IEnvelope类型

用法:

[csharp]  view plain  copy
 print ?
  1. ITopologicalOperator pTopologBoundary = pSourceGeometry as ITopologicalOperator;  
  2. pTopologBoundary.Clip(pClipGeometry.Envelope as IEnvelope);  


4、Cut,分割,将一个Geometry分割为两部分。

用法:

[csharp]  view plain  copy
 print ?
  1. IGeometry pSourceGeometry = null, pClipGeometry = null;  
  2. IGeometry pLeftGeo,pRightGo;  
  3. IPolyline pPolyline=null;  
  4. ITopologicalOperator pTopologBoundary = pSourceGeometry as ITopologicalOperator;  
  5. pTopologBoundary.Cut(pPolyline, out pLeftGeo, out pRightGo);  

5、Difference,区别,保留下源图层与操作图层中不同的部分。

用法:

[csharp]  view plain  copy
 print ?
  1. IGeometry pSourceGeometry = null, pDifGeometry = null;  
  2. ITopologicalOperator pTopologBoundary = pSourceGeometry as ITopologicalOperator;  
  3. IGeometry pResultGeo= pTopologBoundary.Difference(pDifGeometry);  

6、Intersect,相交,求两个图层相交,返回IGeometry对象

用法:esriGeometryDimension枚举值 参数决定了返回的数据类型(点,线,面)

[csharp]  view plain  copy
 print ?
  1. ITopologicalOperator pTopological = (pSubFeature.Shape) as ITopologicalOperator;  
  2. IGeometry pGeoIntersect=pTopological.Intersect(pFeature.Shape, esriGeometryDimension.esriGeometry2Dimension);  

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);  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值