AE线要素编辑


1、高亮显示节点

[csharp]  view plain copy
  1. //高亮显示节点和端点  
  2.         public void HighLightNode()  
  3.         {  
  4.             //清空  
  5.             _mapCtrl.Map.ClearSelection();  
  6.             _mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, _mapCtrl.ActiveView.Extent);  
  7.             var pGraphicsContainer = _mapCtrl.Map as IGraphicsContainer;  
  8.             pGraphicsContainer.DeleteAllElements();  
  9.             _mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);  
  10.    
  11.             //增加  
  12.             ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();  
  13.             ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass  
  14.             {  
  15.                 Color = new RgbColorClass { Red = 255, Green = 0, Blue = 0 },  
  16.                 Width = 2,  
  17.                 Style = esriSimpleLineStyle.esriSLSSolid  
  18.             };  
  19.    
  20.             ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass  
  21.             {  
  22.                 Color =  
  23.                     new RgbColorClass { Red = 255, Green = 0, Blue = 0 },  
  24.                 Style = esriSimpleMarkerStyle.esriSMSCircle,  
  25.                 Size = 5  
  26.             };  
  27.             switch (currentFeature.Shape.GeometryType)  
  28.             {  
  29.                 case esriGeometryType.esriGeometryPoint:  
  30.                     //IMarkerElement pMarkerElement = new MarkerElementClass();  
  31.                     //pMarkerElement.Symbol = simpleMarkerSymbol;  
  32.                     //var pEla = pMarkerElement as IElement;  
  33.                     //pEla.Geometry = currentFeature.Shape;  
  34.                     //var pActiveView = _mapCtrl.ActiveView;  
  35.                     //var pGraphicsContainer = _mapCtrl.Map as IGraphicsContainer;  
  36.                     //pGraphicsContainer.AddElement(pEla, 0);  
  37.                     //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);  
  38.                     break;  
  39.                 case esriGeometryType.esriGeometryPolyline:  
  40.                     ILineElement pLineElement = new LineElementClass();  
  41.                     pLineElement.Symbol = simpleLineSymbol;  
  42.                     var pEla1 = pLineElement as IElement;  
  43.                     pEla1.Geometry = currentFeature.Shape;  
  44.                     var pActiveView1 = _mapCtrl.ActiveView;  
  45.                     var pGraphicsContainer1 = _mapCtrl.Map as IGraphicsContainer;  
  46.                     pGraphicsContainer1.AddElement(pEla1, 0);  
  47.                     pActiveView1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);  
  48.                     break;  
  49.                 case esriGeometryType.esriGeometryPolygon:  
  50.                     IPolygonElement pPolygonElement = new PolygonElementClass { Symbol = simpleFillSymbol };  
  51.                     var pEla2 = pPolygonElement as IElement;  
  52.                     pEla2.Geometry = currentFeature.Shape;  
  53.                     var pActiveView2 = _mapCtrl.ActiveView;  
  54.                     var pGraphicsContainer2 = _mapCtrl.Map as IGraphicsContainer;  
  55.                     pGraphicsContainer2.AddElement(pEla2, 0);  
  56.                     pActiveView2.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);  
  57.                     break;  
  58.             }  
  59.             //显示节点  
  60.             //step1:创建节点符号  
  61.             ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();  
  62.             pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;  
  63.             pVertexMarkerSymbol.Size = 3;  
  64.             pVertexMarkerSymbol.Angle = 0;  
  65.             IRgbColor rgbVertex = new RgbColorClass();  
  66.             rgbVertex.Green = 255;  
  67.             pVertexMarkerSymbol.Color = rgbVertex;  
  68.             ISimpleMarkerSymbol pEndPointMarkerSymbol = new SimpleMarkerSymbol();  
  69.             pEndPointMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;  
  70.             pEndPointMarkerSymbol.Size = 4;  
  71.             pEndPointMarkerSymbol.Angle = 0;  
  72.             IRgbColor rgbEndPoint = new RgbColorClass();  
  73.             rgbEndPoint.Red = 255;  
  74.             pEndPointMarkerSymbol.Color = rgbEndPoint;  
  75.    
  76.             //判D断要素的类型  
  77.             if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)  
  78.             {  
  79.                 IGeometryCollection pGeoColl;  
  80.                 ISegmentCollection pSegColl;  
  81.                 ISegment pSegment;  
  82.                 IPath path;  
  83.                 IPointCollection pEndPointCol;  
  84.                 IMultipoint pEndPoints;  
  85.                 IPoint pEndPoint;  
  86.                 pEndPoints = new MultipointClass();  
  87.                 pEndPointCol = pEndPoints as IPointCollection;  
  88.                 pGeoColl = currentFeature.Shape as IGeometryCollection;  
  89.                 for (int i = 0; i < pGeoColl.GeometryCount; i++)  
  90.                 {  
  91.                     pSegColl = pGeoColl.get_Geometry(i) as ISegmentCollection;  
  92.                     path = pGeoColl.get_Geometry(i) as IPath;  
  93.                     pEndPointCol.AddPoint(path.FromPoint);  
  94.                     pEndPointCol.AddPoint(path.ToPoint);  
  95.    
  96.                     for (int j = 0; j < pSegColl.SegmentCount; j++)  
  97.                     {  
  98.                         pSegment = pSegColl.get_Segment(j);  
  99.                         //show vertex  
  100.                         AddPointSymbolToMap(pSegment.FromPoint, pVertexMarkerSymbol);  
  101.                         AddPointSymbolToMap(pSegment.ToPoint, pVertexMarkerSymbol);  
  102.                     }  
  103.                 }  
  104.                 //show endpoint  
  105.                 for (int k = 0; k < pEndPointCol.PointCount; k++)  
  106.                 {  
  107.                     pEndPoint = pEndPointCol.get_Point(k);  
  108.                     AddPointSymbolToMap(pEndPoint, pEndPointMarkerSymbol);  
  109.                 }  
  110.              
  111.             }  
  112.             else if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)  
  113.             {  
  114.                 IPoint pEndPoint;  
  115.                 pEndPoint = currentFeature.Shape as IPoint;  
  116.                 AddPointSymbolToMap(pEndPoint, pEndPointMarkerSymbol);  
  117.             }  
  118.         }  

2、添加节点

[csharp]  view plain copy
  1. OnMouseDown事件:  
  2. IProximityOperator proximityOperator = ucDrawPanel.currentFeature.Shape as IProximityOperator;  
  3.                         ptInsert = proximityOperator.ReturnNearestPoint(pPt, esriSegmentExtension.esriNoExtension);  
  4.    
  5.                         //step1: 创建节点符号  
  6.                         ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();  
  7.                         pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;  
  8.                         pVertexMarkerSymbol.Size = 3;  
  9.                         pVertexMarkerSymbol.Angle = 0;  
  10.                         IRgbColor rgbVertex = new RgbColorClass();  
  11.                         rgbVertex.Green = 255;  
  12.                         pVertexMarkerSymbol.Color = rgbVertex;  
  13.                         //step2: 显示在地图上  
  14.                         IMarkerElement pMarkerElement = new MarkerElementClass();  
  15.                         pMarkerElement.Symbol = pVertexMarkerSymbol;  
  16.                         var pEla = pMarkerElement as IElement;  
  17.                         pEla.Geometry = ptInsert as IGeometry;  
  18.                         pGraphicContainer.AddElement(pEla, 0);  
  19.                         pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);  
  20.    
  21. OnMouseUp事件,添加一个节点,但不打断线:  
  22. // 注意:如果第三个参数createPart设为true,线会被打断,不可取  
  23.                             //线?splitAtPoint  
  24.                             bool isSplitted;  
  25.                             int newPartIndex;  
  26.                             int newSegmentIndex;  
  27.                             IPolyline polyline = ucDrawPanel.currentFeature.Shape as IPolyline;  
  28.                             //插入一点,newSegmentIndex记录插入点的相对线的节点位置  
  29.                             polyline.SplitAtPoint(ptInsert, truefalseout isSplitted, out newPartIndex, out newSegmentIndex);  
  30.                             ucDrawPanel.currentFeature.Store();  

3、删除节点

[csharp]  view plain copy
  1. OnMouseDown事件:  
  2. //step1:获取预删除的节点  
  3.                         IPolyline pPolyline;  
  4.                         IHitTest pHitTest;  
  5.                         bool BoolHitTest;  
  6.                         double dist = 0;  
  7.                         double DbHitDis = 0;  
  8.                         int LngPrtIdx = 0;  
  9.                         bool BoolHitRt = false;  
  10.                         hitElement = getElement(pPt, esriGeometryType.esriGeometryPolyline);  
  11.                         if (hitElement != null)  
  12.                         {  
  13.                             pPolyline = hitElement.Geometry as IPolyline;  
  14.                             pHitTest = pPolyline as IHitTest;  
  15.                             ptDelete = new PointClass();  
  16.                             BoolHitTest = pHitTest.HitTest(pPt, pActiveView.Extent.Width / 100,  
  17.                                                            esriGeometryHitPartType.esriGeometryPartVertex, ptDelete,                                                           ref DbHitDis, ref LngPrtIdx, ref indexDelete, ref BoolHitRt);  
  18.                             // pHitTest.HitTest(pPt, pActiveView.Extent.Width / 100,esriGeometryHitPartType.esriGeometryPartVertex, ptDelete,ref DbHitDis, ref LngPrtIdx, ref LngSegIdx, ref BoolHitRt);  
  19.    
  20.                             if (BoolHitTest)  
  21.                             {  
  22.                                 //step2:高?亮显示,符号黑色边框镂空填充  
  23.                                 ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();  
  24.                                 pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;  
  25.                                 pVertexMarkerSymbol.Size = 5;  
  26.                                 pVertexMarkerSymbol.Angle = 0;  
  27.                                 IRgbColor rgbVertex = new RgbColorClass();  
  28.                                 rgbVertex.Red = 0;  
  29.                                 rgbVertex.Blue = 0;  
  30.                                 rgbVertex.Green = 0;  
  31.                                 pVertexMarkerSymbol.Color = rgbVertex;  
  32.    
  33.                                 IMarkerElement pMarkerElement = new MarkerElementClass();  
  34.                                 pMarkerElement.Symbol = pVertexMarkerSymbol;  
  35.                                 var pEla = pMarkerElement as IElement;  
  36.                                 pEla.Geometry = ptDelete as IGeometry;  
  37.                                 pGraphicContainer.AddElement(pEla, 0);  
  38.                                 pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);  
  39.                             }  
  40.                         }  
  41.    
  42. OnMouseUp事件,删除节点:  
  43. IPointCollection pointCollection = ucDrawPanel.currentFeature.Shape as IPointCollection;  
  44.                             pointCollection.RemovePoints(indexDelete, 1);  
  45.                             IPolyline polylineNew = pointCollection as IPolyline;  
  46.                             StoreFeatureGeometry(ucDrawPanel.currentFeature, polylineNew);  
  47. 保存图形要素:  
  48.      private bool StoreFeatureGeometry(IFeature pFeature, IGeometry pIGeometry)  
  49.         {  
  50.             try  
  51.             {  
  52.                 var pFeatureClass = pFeature.Class as IFeatureClass;  
  53.                 var pDataset = pFeatureClass as IDataset;  
  54.                 IWorkspace pWorkspace = pDataset.Workspace;  
  55.                 var pWorkspaceEdit = pWorkspace as IWorkspaceEdit;  
  56.    
  57.                 pWorkspaceEdit.StartEditing(false);  
  58.                 pWorkspaceEdit.StartEditOperation();  
  59.                 pFeature.Shape = pIGeometry;  
  60.                 pFeature.Store();  
  61.                 pWorkspaceEdit.StopEditOperation();  
  62.                 pWorkspaceEdit.StopEditing(true);  
  63.                 return true;  
  64.             }  
  65.             catch (Exception ex)  
  66.             {  
  67.                 return false;  
  68.             }  
  69.         }  
  70.    

4、打断线

[csharp]  view plain copy
  1. 关键字:Split。  
  2. OnMouseDown事件:  
  3. IProximityOperator proximityOperator = ucDrawPanel.currentFeature.Shape as IProximityOperator;  
  4.                         ptSplit = proximityOperator.ReturnNearestPoint(pPt, esriSegmentExtension.esriNoExtension);  
  5.    
  6.                         //step1:创建节点符号  
  7.                         ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();  
  8.                         pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;  
  9.                         pVertexMarkerSymbol.Size = 4;  
  10.                         pVertexMarkerSymbol.Angle = 0;  
  11.                         IRgbColor rgbVertex = new RgbColorClass();  
  12.                         rgbVertex.Red = 255;  
  13.                         pVertexMarkerSymbol.Color = rgbVertex;  
  14.                         //step2:显示在地图上  
  15.                         IMarkerElement pMarkerElement = new MarkerElementClass();  
  16.                         pMarkerElement.Symbol = pVertexMarkerSymbol;  
  17.                         var pEla = pMarkerElement as IElement;  
  18.                         pEla.Geometry = ptSplit as IGeometry;  
  19.                         pGraphicContainer.AddElement(pEla, 0);  
  20.                         pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);  
  21.    
  22. OnMouseUp事件打断线:  
  23. IFeatureEdit featureEdit = ucDrawPanel.currentFeature as IFeatureEdit;  
  24.                             ISet newFeaturesSet = featureEdit.Split(ptSplit);  
  25.                             newFeaturesSet.Reset();  
  26.                             IFeature feature = newFeaturesSet.Next() as IFeature;  

5、合并线

首先判断预合并的两条线拓扑关系,是否邻接关系;满足条件可以用关键字Merge实现,或者自定义方法,重新获取点的集合IPointCollection创建多线。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值