Dotspatial 要素重叠分析
private void toolStripButton30_Click(object sender, EventArgs e)
{
//面状重叠分析
if (mapMain.Layers.Count == 0)
{
return;
}
//重叠分析
//遍历要素,显示面积
FeatureSet fs = null;
fs = Lzq_LayerManager.getFeatureSetByName(layerNamePolygon, mapMain); //(FeatureSet) map1.Layers[0].DataSet;
//MessageBox.Show("图层类型:" + fs.FeatureType.ToString());
if (fs.FeatureType != FeatureType.Polygon)
{
return;
}
DotSpatial.Topology.Geometry gm1, gm2;
for (int i = 0; i < fs.Features.Count; i++)
{
gm1 = (DotSpatial.Topology.Geometry) (fs.Features[i].BasicGeometry);
for (int j = i + 1; j < fs.Features.Count; j++)
{
gm2 = (DotSpatial.Topology.Geometry) (fs.Features[j].BasicGeometry);
if (gm1.IsSimple && gm2.IsSimple)
{
try
{
if (gm1.Overlaps(gm2)) //重叠
{
//try
//{
Geometry p = (Geometry)gm1.Intersection(gm2);
DotSpatial.Topology.CoordinateArrays.RemoveRepeatedPoints(p.Coordinates);
if (p.Area > 0.001)
{
MessageBox.Show("\ngm1——lb:" +
fs.Features[i].DataRow["林班号"].ToString() + " xb:" +
fs.Features[i].DataRow["小班号"].ToString() + "——gm1 Area" +
gm1.Area.ToString() +
"\ngm2——lb:" +
fs.Features[j].DataRow["林班号"].ToString() + " xb:" +
fs.Features[j].DataRow["小班号"].ToString() + "——gm2 Area" +
gm2.Area.ToString() +
"\n重叠 面积:" +
p.Area);
}
//}
//catch
//{
//}
}
}
catch
{
}
}
//}
//catch (Exception exc)
//{
// // MessageBox.Show(exc.Message);
//}
}
}
fs = null;
}