zoukankan      html  css  js  c++  java
  • AE编辑线要素编辑

    http://blog.163.com/liuyang1285@126/blog/static/128913086201212151221503/

     
     
     
     
     

    日志

     
     
    一缕阳光
    我要做个行动者!我需要静下心来品味这份曾经被遗失的美好。
      加博友   关注她

    最新日志

    该作者的其他文章

      2012-02-21 17:12:21|  分类: 工作 |  标签: |字号 订阅

      高亮显示节点

         //高亮显示节点和端点

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

                  }

              }

      添加节点

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

      删除节点

      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;

                  }

              }

      线的打断

      关键字: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;

      线的合并

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

    • 相关阅读:
      使用jquery.validate.js实现boostrap3的校验和验证
      MySQL 随机取数据效率问题
      qq在线客服代码
      使用Shell脚本查找程序对应的进程ID,并杀死进程
      Redis-概述
      JVM的类加载机制
      volatile
      java内存相关
      设计模式--模板方法
      设计模式概述
    • 原文地址:https://www.cnblogs.com/gisoracle/p/2432646.html
    Copyright © 2011-2022 走看看