博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AE 线编辑
阅读量:6478 次
发布时间:2019-06-23

本文共 10608 字,大约阅读时间需要 35 分钟。

转自原文 

1、高亮显示节点

//高亮显示节点和端点  public void HighLightNode()  {      //清空      _mapCtrl.Map.ClearSelection();      _mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, _mapCtrl.ActiveView.Extent);      var pGraphicsContainer = _mapCtrl.Map as IGraphicsContainer;      pGraphicsContainer.DeleteAllElements();      _mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);             //增加      ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();      ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass      {          Color = new RgbColorClass { Red = 255, Green = 0, Blue = 0 },          Width = 2,          Style = esriSimpleLineStyle.esriSLSSolid      };             ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass      {          Color =              new RgbColorClass { Red = 255, Green = 0, Blue = 0 },          Style = esriSimpleMarkerStyle.esriSMSCircle,          Size = 5      };      switch (currentFeature.Shape.GeometryType)      {          case esriGeometryType.esriGeometryPoint:              //IMarkerElement pMarkerElement = new MarkerElementClass();              //pMarkerElement.Symbol = simpleMarkerSymbol;              //var pEla = pMarkerElement as IElement;              //pEla.Geometry = currentFeature.Shape;              //var pActiveView = _mapCtrl.ActiveView;              //var pGraphicsContainer = _mapCtrl.Map as IGraphicsContainer;              //pGraphicsContainer.AddElement(pEla, 0);              //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);              break;          case esriGeometryType.esriGeometryPolyline:              ILineElement pLineElement = new LineElementClass();              pLineElement.Symbol = simpleLineSymbol;              var pEla1 = pLineElement as IElement;              pEla1.Geometry = currentFeature.Shape;              var pActiveView1 = _mapCtrl.ActiveView;              var pGraphicsContainer1 = _mapCtrl.Map as IGraphicsContainer;              pGraphicsContainer1.AddElement(pEla1, 0);              pActiveView1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);              break;          case esriGeometryType.esriGeometryPolygon:              IPolygonElement pPolygonElement = new PolygonElementClass { Symbol = simpleFillSymbol };              var pEla2 = pPolygonElement as IElement;              pEla2.Geometry = currentFeature.Shape;              var pActiveView2 = _mapCtrl.ActiveView;              var pGraphicsContainer2 = _mapCtrl.Map as IGraphicsContainer;              pGraphicsContainer2.AddElement(pEla2, 0);              pActiveView2.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);              break;      }      //显示节点      //step1:创建节点符号      ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();      pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;      pVertexMarkerSymbol.Size = 3;      pVertexMarkerSymbol.Angle = 0;      IRgbColor rgbVertex = new RgbColorClass();      rgbVertex.Green = 255;      pVertexMarkerSymbol.Color = rgbVertex;      ISimpleMarkerSymbol pEndPointMarkerSymbol = new SimpleMarkerSymbol();      pEndPointMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;      pEndPointMarkerSymbol.Size = 4;      pEndPointMarkerSymbol.Angle = 0;      IRgbColor rgbEndPoint = new RgbColorClass();      rgbEndPoint.Red = 255;      pEndPointMarkerSymbol.Color = rgbEndPoint;             //判D断要素的类型      if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)      {          IGeometryCollection pGeoColl;          ISegmentCollection pSegColl;          ISegment pSegment;          IPath path;          IPointCollection pEndPointCol;          IMultipoint pEndPoints;          IPoint pEndPoint;          pEndPoints = new MultipointClass();          pEndPointCol = pEndPoints as IPointCollection;          pGeoColl = currentFeature.Shape as IGeometryCollection;          for (int i = 0; i < pGeoColl.GeometryCount; i++)          {              pSegColl = pGeoColl.get_Geometry(i) as ISegmentCollection;              path = pGeoColl.get_Geometry(i) as IPath;              pEndPointCol.AddPoint(path.FromPoint);              pEndPointCol.AddPoint(path.ToPoint);                     for (int j = 0; j < pSegColl.SegmentCount; j++)              {                  pSegment = pSegColl.get_Segment(j);                  //show vertex                  AddPointSymbolToMap(pSegment.FromPoint, pVertexMarkerSymbol);                  AddPointSymbolToMap(pSegment.ToPoint, pVertexMarkerSymbol);              }          }          //show endpoint          for (int k = 0; k < pEndPointCol.PointCount; k++)          {              pEndPoint = pEndPointCol.get_Point(k);              AddPointSymbolToMap(pEndPoint, pEndPointMarkerSymbol);          }           }      else if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)      {          IPoint pEndPoint;          pEndPoint = currentFeature.Shape as IPoint;          AddPointSymbolToMap(pEndPoint, pEndPointMarkerSymbol);      }  }

2、添加节点

OnMouseDown事件:  IProximityOperator proximityOperator = ucDrawPanel.currentFeature.Shape as IProximityOperator;  ptInsert = proximityOperator.ReturnNearestPoint(pPt, esriSegmentExtension.esriNoExtension);     //step1: 创建节点符号  ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();  pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;  pVertexMarkerSymbol.Size = 3;  pVertexMarkerSymbol.Angle = 0;  IRgbColor rgbVertex = new RgbColorClass();  rgbVertex.Green = 255;  pVertexMarkerSymbol.Color = rgbVertex;  //step2: 显示在地图上  IMarkerElement pMarkerElement = new MarkerElementClass();  pMarkerElement.Symbol = pVertexMarkerSymbol;  var pEla = pMarkerElement as IElement;  pEla.Geometry = ptInsert as IGeometry;  pGraphicContainer.AddElement(pEla, 0);  pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);     OnMouseUp事件,添加一个节点,但不打断线:  // 注意:如果第三个参数createPart设为true,线会被打断,不可取  //线?splitAtPoint  bool isSplitted;  int newPartIndex;  int newSegmentIndex;  IPolyline polyline = ucDrawPanel.currentFeature.Shape as IPolyline;  //插入一点,newSegmentIndex记录插入点的相对线的节点位置  polyline.SplitAtPoint(ptInsert, true, false, out isSplitted, out newPartIndex, out newSegmentIndex);  ucDrawPanel.currentFeature.Store();

3、删除节点

OnMouseDown事件:  //step1:获取预删除的节点  IPolyline pPolyline;  IHitTest pHitTest;  bool BoolHitTest;  double dist = 0;  double DbHitDis = 0;  int LngPrtIdx = 0;  bool BoolHitRt = false;  hitElement = getElement(pPt, esriGeometryType.esriGeometryPolyline);  if (hitElement != null)  {      pPolyline = hitElement.Geometry as IPolyline;      pHitTest = pPolyline as IHitTest;      ptDelete = new PointClass();      BoolHitTest = pHitTest.HitTest(pPt, pActiveView.Extent.Width / 100,                                     esriGeometryHitPartType.esriGeometryPartVertex, ptDelete,                                                           ref DbHitDis, ref LngPrtIdx, ref indexDelete, ref BoolHitRt);      // pHitTest.HitTest(pPt, pActiveView.Extent.Width / 100,esriGeometryHitPartType.esriGeometryPartVertex, ptDelete,ref DbHitDis, ref LngPrtIdx, ref LngSegIdx, ref BoolHitRt);             if (BoolHitTest)      {          //step2:高?亮显示,符号黑色边框镂空填充          ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();          pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;          pVertexMarkerSymbol.Size = 5;          pVertexMarkerSymbol.Angle = 0;          IRgbColor rgbVertex = new RgbColorClass();          rgbVertex.Red = 0;          rgbVertex.Blue = 0;          rgbVertex.Green = 0;          pVertexMarkerSymbol.Color = rgbVertex;                 IMarkerElement pMarkerElement = new MarkerElementClass();          pMarkerElement.Symbol = pVertexMarkerSymbol;          var pEla = pMarkerElement as IElement;          pEla.Geometry = ptDelete as IGeometry;          pGraphicContainer.AddElement(pEla, 0);          pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);      }  }             OnMouseUp事件,删除节点:      IPointCollection pointCollection = ucDrawPanel.currentFeature.Shape as IPointCollection;      pointCollection.RemovePoints(indexDelete, 1);      IPolyline polylineNew = pointCollection as IPolyline;      StoreFeatureGeometry(ucDrawPanel.currentFeature, polylineNew);      保存图形要素:           private bool StoreFeatureGeometry(IFeature pFeature, IGeometry pIGeometry)  {      try      {          var pFeatureClass = pFeature.Class as IFeatureClass;          var pDataset = pFeatureClass as IDataset;          IWorkspace pWorkspace = pDataset.Workspace;          var pWorkspaceEdit = pWorkspace as IWorkspaceEdit;                 pWorkspaceEdit.StartEditing(false);          pWorkspaceEdit.StartEditOperation();          pFeature.Shape = pIGeometry;          pFeature.Store();          pWorkspaceEdit.StopEditOperation();          pWorkspaceEdit.StopEditing(true);          return true;      }      catch (Exception ex)      {          return false;      }  }

4、打断线

关键字:Split。  OnMouseDown事件:  IProximityOperator proximityOperator = ucDrawPanel.currentFeature.Shape as IProximityOperator;  ptSplit = proximityOperator.ReturnNearestPoint(pPt, esriSegmentExtension.esriNoExtension);     //step1:创建节点符号  ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();  pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;  pVertexMarkerSymbol.Size = 4;  pVertexMarkerSymbol.Angle = 0;  IRgbColor rgbVertex = new RgbColorClass();  rgbVertex.Red = 255;  pVertexMarkerSymbol.Color = rgbVertex;  //step2:显示在地图上  IMarkerElement pMarkerElement = new MarkerElementClass();  pMarkerElement.Symbol = pVertexMarkerSymbol;  var pEla = pMarkerElement as IElement;  pEla.Geometry = ptSplit as IGeometry;  pGraphicContainer.AddElement(pEla, 0);  pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);     OnMouseUp事件打断线:  IFeatureEdit featureEdit = ucDrawPanel.currentFeature as IFeatureEdit;  ISet newFeaturesSet = featureEdit.Split(ptSplit);  newFeaturesSet.Reset();  IFeature feature = newFeaturesSet.Next() as IFeature;

5、合并线

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

 

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。
    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/6263130.html
,如需转载请自行联系原作者
你可能感兴趣的文章
集合异常之List接口
查看>>
Softmax回归
查看>>
紫书 习题11-11 UVa 1644 (并查集)
查看>>
App工程结构搭建:几种常见Android代码架构分析
查看>>
使用openssl进行证书格式转换
查看>>
ZOJ 3777 Problem Arrangement
查看>>
Callable和Future
查看>>
少用数字来作为参数标识含义
查看>>
ScrollView中嵌套ListView
查看>>
Algs4-2.3.1如何切分数组
查看>>
观察者模式
查看>>
在properties.xml中定义变量,在application.xml中取值问题
查看>>
js 数组
查看>>
Linux scp命令详解
查看>>
cell reuse & disposebag
查看>>
【故障处理】ORA-12545: Connect failed because target host or object does not exist
查看>>
云时代,程序员将面临的分化
查看>>
js判断移动端是否安装某款app的多种方法
查看>>
学习angularjs的内置API函数
查看>>
4、输出名称 Exported names
查看>>