码迷,mamicode.com
首页 > Windows程序 > 详细

C# ArcEngine 实现点击要素高亮并弹出其属性

时间:2015-10-28 18:52:09      阅读:501      评论:0      收藏:0      [点我收藏+]

标签:

本文是模仿ArcMap里面的Identify(识别)功能,通过点击要素,使其高亮显示并弹出其属性表!本文只做了点击查询!

本文所用的环境为VS2010,AecEngine基于C#语言,界面是用Dev做的,比windows自带的窗体稍微好看点,效果如下:

技术分享

主要实现代码(在axMapControl1_OnMouseDown下):

 1                         ITopologicalOperator pTopo;
 2                         IGeometry pGeometry;
 3                         IFeature pFeature;
 4                         IFeatureLayer pFeatureLayer;
 5                         IFeatureCursor pCursor;
 6                         ISpatialFilter pFilter;
 7                         DataTable dataTable;
 8                         
 9                         for (int i = 0; i < axMapControl1.Map.LayerCount; i++)
10                         {
11                             
12                             pPoint = new PointClass();
13                             pPoint.PutCoords(e.mapX, e.mapY);
14                             pTopo = pPoint as ITopologicalOperator;17                             double m_Radius = 1;
18                             pGeometry = pTopo.Buffer(m_Radius); 
19                             if (pGeometry == null)
20                                 continue;
21                             axMapControl1.Map.SelectByShape(pGeometry, null, true);//第三个参数为是否只选中一个
22                             axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); //选中要素高亮显示
23                             pFilter = new SpatialFilterClass();
25                             pFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
26                             pFilter.Geometry = pGeometry;
27                             pFeatureLayer = axMapControl1.Map.get_Layer(i) as IFeatureLayer; 
28                             pCursor = pFeatureLayer.Search(pFilter, false);
29                             pFeature = pCursor.NextFeature();
30                             string fieldName;
31                             if (pFeature != null)
33                             {
34                                 if (Application.OpenForms["otherQueryForm"] == null)
35                                 {
36                                     otherqueryform = new otherQueryForm();
37                                     otherqueryform.Show();
38                                 }
39                                 else
40                                 {
41                                     Application.OpenForms["otherQueryForm"].Show();
42                                 }//这里主要控制子窗体不会重复弹出
44                                 dataTable = new DataTable();
45                                 for (int k = 0; k < 2; k++)
46                                 {
47                                     if (k == 0)
48                                     {
49                                         dataTable.Columns.Add("属性");
50                                     }
51                                     if (k == 1)
52                                     {
53                                         dataTable.Columns.Add("");
54                                     }
55                                 }
56                                 DataRow datarow;
57                                 for (int j = 0; j < pFeature.Fields.FieldCount; j++)
58                                 {
59                                     datarow = dataTable.NewRow();
60                                     for (int m = 0; m < 2; m++)
61                                     {
62                                         if (m == 0)
63                                         {
64                                             fieldName = pFeature.Fields.get_Field(j).Name;
65                                             datarow[m] = fieldName;
66                                         }
67                                         if (m == 1)
68                                         {
69                                             if (pFeature.Fields.get_Field(j).Name == "Shape")
70                                             {
71                                                 if (pFeature.Shape.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
72                                                 {
73                                                     datarow[m] = "";
74                                                 }
75                                                 if (pFeature.Shape.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline)
76                                                 {
77                                                     datarow[m] = "线";
78                                                 }
79                                                 if (pFeature.Shape.GeometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
80                                                 {
81                                                     datarow[m] = "";
82                                                 }
83                                             }
84                                             else
85                                             {
86                                                 datarow[m] = pFeature.get_Value(j).ToString();
87                                             }
88                                         }
89                                     }
90                                     dataTable.Rows.Add(datarow);
91                                 }
92                                 otherqueryform.dataGridView1.DataSource = dataTable;
93                                 otherqueryform.layerName_dev.Text = pFeatureLayer.Name;
94                                 otherqueryform.dataGridView1.Refresh();
95                                 pFeature = null;
96                                 break;
97                             }99                         }

 

C# ArcEngine 实现点击要素高亮并弹出其属性

标签:

原文地址:http://www.cnblogs.com/fengzhiwei-blog/p/4917983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!