Dotspatial 要素重疊部分去除

private void toolStripButton32_Click(object sender, EventArgs e)
{
  /重疊部分去除操做——測試成功
  if (mapMain.Layers.Count == 0)
  {
    return;
  }
  //重疊分析
  //遍歷要素,顯示面積
  FeatureSet fs = null;
  fs = Lzq_LayerManager.getFeatureSetByName(layerNamePolygon, mapMain);測試

  if (fs.FeatureType != FeatureType.Polygon)
  {
    return;
  }

  for (int i = 0; i < fs.Features.Count; i++)
  {
    var gm1 = (DotSpatial.Topology.Geometry) (fs.Features[i].BasicGeometry); // point
    //DotSpatial.Topology.CoordinateArrays.RemoveRepeatedPoints(gm1.Coordinates);
    for (int j = i + 1; j < fs.Features.Count ; j++)
    {
      var gm2 = (DotSpatial.Topology.Geometry) (fs.Features[j].BasicGeometry);orm

      if (gm1.IsSimple && gm2.IsSimple)
      {
        //try
        //{
          if (gm1.Overlaps(gm2))
          {
            IGeometry geo = (gm1.Difference(gm2));
            DotSpatial.Topology.CoordinateArrays.RemoveRepeatedPoints(geo.Coordinates);
            if (geo.IsSimple)
            {
              geo.Normalize();
              fs.Features[i].BasicGeometry = geo;
            }
          }
        //}
        //catch(Exception exc)
        //{
          // string msg = "林班號:" + fs.Features[i].DataRow["林班號"].ToString() +
          // " 小班號:" + fs.Features[i].DataRow["小班號"].ToString();
          // MessageBox.Show(exc + "\n" + msg);
        //}
      }
      else
      {
        MessageBox.Show("isSimple is false");
      }
    }

  }ip

  MessageBox.Show("圖斑個數:"+fs.Features.Count.ToString()+"\n屬性表個數:"+fs.DataTable.Rows.Count);
  fs.UpdateExtent();
  fs.InitializeVertices();
  fs.Save();get

  mapMain.ResetBuffer();string

  MessageBox.Show(@"重疊去除功能,執行完畢!", @"系統提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}it

相關文章
相關標籤/搜索