本文是模仿ArcMap里面的Identify(识别)功能,通过点击要素,使其高亮显示并弹出其属性表!本文只做了点击查询!
ITopologicalOperator pTopo;
IGeometry pGeometry;
IFeature pFeature;
IFeatureLayer pFeatureLayer;
IFeatureCursor pCursor;
ISpatialFilter pFilter;
DataTable dataTable;
for (int i = 0; i < axMapControl1.Map.LayerCount; i++)
{
pPoint = new PointClass();
pPoint.PutCoords(e.mapX, e.mapY);
pTopo = pPoint as ITopologicalOperator;
double m_Radius = 1;
pGeometry = pTopo.Buffer(m_Radius);
if (pGeometry == null)
continue;
axMapControl1.Map.SelectByShape(pGeometry, null, true);//第三个参数为是否只选中一个
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); //选中要素高亮显示
pFilter = new SpatialFilterClass();
pFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
pFilter.Geometry = pGeometry;
pFeatureLayer = axMapControl1.Map.get_Layer(i) as IFeatureLayer;
pCursor = pFeatureLayer.Search(pFilter, false);
pFeature = pCursor.NextFeature();
string fieldName;
if (pFeature != null)
{
if (Application.OpenForms["otherQueryForm"] == null)
{
otherqueryform = new otherQueryForm();
otherqueryform.Show();
}
else
{
Application.OpenForms["otherQueryForm"].Show();
}//这里主要控制子窗体不会重复弹出
dataTable = new DataTable();
for (int k = 0; k < 2; k++)
{
if (k == 0)
{
dataTable.Columns.Add("属性");
}
if (k == 1)
{
dataTable.Columns.Add("值");
}
}
DataRow datarow;
for (int j = 0; j < pFeature.Fields.FieldCount; j++)
{
datarow = dataTable.NewRow();
for (int m = 0; m < 2; m++)
{
if (m == 0)
{
fieldName = pFeature.Fields.get_Field(j).Name;
datarow[m] = fieldName;
}
if (m == 1)
{
if (pFeature.Fields.get_Field(j).Name == "Shape")
{
if (pFeature.Shape.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
{
datarow[m] = "点";
}
If ( pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
{
datarow[m] = "线";
}
if (pFeature.Shape.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
{
datarow[m] = "面";
}
}
else
{
datarow[m] = pFeature.get_Value(j).ToString();
}
}
}
dataTable.Rows.Add(datarow);
}
otherqueryform.dataGridView1.DataSource = dataTable;
otherqueryform.layerName_dev.Text = pFeatureLayer.Name;
otherqueryform.dataGridView1.Refresh();
pFeature = null;
break;
}
}
你们的评论、反馈,及对你们有所用,是我整理材料和博文写作的最大的鼓励和唯一动力。欢迎讨论和关注!
没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。