转自
本文是模仿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;}}