//通过遍历选择要素,获取选择要素相交的要素

private void toolStripButton43_Click(object sender, EventArgs e)

{

//查看与选中要素重叠的要素
if (map1.Layers.Count == 0)
{
return;
}
//重叠分析
//遍历要素,显示面积
PolygonLayer pLayer = map1.Layers[0] as PolygonLayer;
FeatureSet fs = null;
fs = (FeatureSet) map1.Layers[0].DataSet;
if (pLayer.Selection.Count == 0)
{
MessageBox.Show("无选中记录", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

// //遍历选择要素
foreach (Feature feature in pLayer.Selection.ToFeatureList())
{
////实现方式1==================
IEnvelope pEnvelope = null;
pLayer.Select(null, feature.Envelope, SelectionMode.Intersects, out pEnvelope);

////实现方式2=================

//FeatureSet pPolygonFeatureSet = new FeatureSet(DotSpatial.Topology.FeatureType.Polygon);
////pPolygonFeatureSet.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;
//pPolygonFeatureSet.AddFeature(feature);

//Extent pAffectedExtent = null;

//var result = fs.Select(pPolygonFeatureSet.Extent);//, out pAffectedExtent,

//foreach (IFeature feature2 in result)
//{
// pLayer.ZoomToSelectedFeatures();
// MessageBox.Show(feature.DataRow["林班号"] + "-" + feature.DataRow["小班号"] + "重叠:" + feature2.DataRow["林班号"] + "-" + feature2.DataRow["小班号"]); //feature2.DataRow.Field<Int64>("林班号").ToString()
//}

//实现方式3
//var gm1 = (DotSpatial.Topology.Geometry)(feature.BasicGeometry);// point
//foreach (IFeature feature2 in fs.Features)
//{
// //MessageBox.Show(feature.DataRow.Field<string>("NAME"));
// var gm2 = (DotSpatial.Topology.Geometry)(feature2.BasicGeometry);
// if (gm2.Overlaps(gm1))
// {
// MessageBox.Show(feature.DataRow["林班号"] + "-" + feature.DataRow["小班号"] + "重叠:" + feature2.DataRow["林班号"] + "-" + feature2.DataRow["小班号"]);

// // code for whatever you want to do
// }
//}
//======================

}
pLayer.ZoomToSelectedFeatures();
}

04-16 18:38