zoukankan      html  css  js  c++  java
  • DotSpatial 要素删除节点

    
    

    /// <summary>
    /// 要素删除节点
    /// </summary>
    /// <param name="selectedFeature">被选中的要素</param>
    /// <param name="deleteCoord">节点坐标</param>

    1  private void DeleteVertex(IFeature selectedFeature, Coordinate deleteCoord)
      2         {
      3             if (selectedFeature == null)
      4             {
      5                 return;
      6             }
      7 
      8             if (_layer.DataSet.FeatureType == FeatureType.Polygon)
      9             {
     10                 _layer.EditMode = true;
     11 
     12                 for (int prt = 0; prt < selectedFeature.Geometry.NumGeometries; prt++)
     13                 {
     14                     IGeometry g = _selectedFeature.Geometry.GetGeometryN(prt);
     15                     Polygon poly = (Polygon)g;
     16 
     17                     #region 外环中查找
     18 
     19                     List<Coordinate> listCoorExtRing =poly.ExteriorRing.Coordinates.ToList<Coordinate>();
     20 
     21                     for (int ic = 0; ic < listCoorExtRing.Count; ic++)
     22                     {
     23                         if (listCoorExtRing[ic] == deleteCoord)
     24                         {
     25                             if (ic == 0 || ic == listCoorExtRing.Count - 1)//首节点被选中时,首末节点均删除
     26                             {
     27                                 listCoorExtRing.RemoveAt(listCoorExtRing.Count - 1);
     28                                 listCoorExtRing.RemoveAt(ic);
     29 
     30                                 listCoorExtRing.Add(listCoorExtRing[0]);
     31                                 break;
     32                             }
     33                             else
     34                             {
     35                                 listCoorExtRing.RemoveAt(ic);
     36 
     37                                 break;
     38                             }
     39                         }
     40                     }
     41                     //创建外环
     42                     LinearRing ringExterior = new LinearRing(listCoorExtRing.ToArray());
     43 
     44                     #endregion
     45 
     46                     #region 内环中查找
     47 
     48                     LinearRing[] ringInterior = null;
     49                     if (poly.NumInteriorRings > 0)
     50                     {
     51                         ringInterior = new LinearRing[poly.NumInteriorRings];
     52 
     53                         //遍历内环
     54                         for (int i = 0; i < poly.NumInteriorRings; i++)
     55                         {
     56                             List<Coordinate> listCoorIntRing =poly.GetInteriorRingN(i).Coordinates.ToList<Coordinate>();
     57                             //判断
     58                             for (int ic = 0; ic < listCoorIntRing.Count; ic++)
     59                             {
     60                                 if (listCoorIntRing[ic] == deleteCoord)
     61                                 {
     62                                     if (ic == 0 || ic == listCoorIntRing.Count - 1)//首节点被选中时,首末节点均删除
     63                                     {
     64                                         listCoorIntRing.RemoveAt(listCoorIntRing.Count - 1);
     65                                         listCoorIntRing.RemoveAt(ic);
     66 
     67                                         listCoorIntRing.Add(listCoorIntRing[0]);
     68                                         break;
     69                                     }
     70                                     else
     71                                     {
     72                                         listCoorIntRing.RemoveAt(ic);
     73                                         break;
     74                                     }
     75                                 }
     76                             }
     77 
     78                             ringInterior[i] = new LinearRing(listCoorIntRing.ToArray());
     79                             listCoorIntRing = null;
     80                         }
     81                     }
     82 
     83                     #endregion
     84 
     85                     #region 要素Geometry更新
     86                                       
     87                     Polygon polyNew = null;
     88                     if (poly.NumInteriorRings > 0)//存在内环
     89                     {
     90                         polyNew = new Polygon(ringExterior, ringInterior);
     91                     }
     92                     else //仅存在外环
     93                     {
     94                         polyNew = new Polygon(ringExterior);
     95                     }
     96 
     97                     selectedFeature.Geometry = polyNew;
     98 
     99                     #endregion
    100 
    101                 }
    102                 _layer.DataSet.InvalidateVertices();
    103                 _layer.DataSet.UpdateExtent();
    104                 _layer.DataSet.Save();
    105 
    106                 _layer.EditMode = false;
    107 
    108                 Map.Invalidate();
    109             }
    110         }
  • 相关阅读:
    20165103 第四周查漏补缺
    20165103 2017-2018-2 《Java程序设计》第3周学习总结
    20165103 2017-2018-2 《Java程序设计》第2周学习总结
    20165103 2017-2018-2 《Java程序设计》第1周学习总结
    MySQL事务一致性理解
    mysql的事务四个特性以及 事务的四个隔离级别
    序列化和反序列化的简单理解
    内存溢出和内存泄漏的区别,产生原因以及解决方案
    oracle入门学习之oracle数据库结构
    Java微服务(Spring-boot+MyBatis+Maven)入门教程
  • 原文地址:https://www.cnblogs.com/kogame/p/15647063.html
Copyright © 2011-2022 走看看