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);
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");
}
}
}
MessageBox.Show("图斑个数:"+fs.Features.Count.ToString()+"\n属性表个数:"+fs.DataTable.Rows.Count);
fs.UpdateExtent();
fs.InitializeVertices();
fs.Save();
mapMain.ResetBuffer();
MessageBox.Show(@"重叠去除功能,执行完毕!", @"系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}