利用IIdentify接口实现点选和矩形选择要素

IIdentify接口定义了获得要素图层单个要素的属性的捷径方法。它有一个Identify方法,返回一个IArray数组对象。
将下列代码放入MouseDown事件中,可以实现点选或者矩形选择要素。
 1             IMap pMap;
 2             IPoint pPoint;
 3             pMap = axMapControl1.Map;
 4             pPoint = axMapControl1.ToMapPoint(e.x, e.y);
 5
 6             IIdentify pIdentify;
 7             pIdentify = (IIdentify)pMap.get_Layer(0);
 8
 9             IArray pIDArray;
10             IFeatureIdentifyObj pFeatIdObj;
11             IIdentifyObj pIdObj;
12             //点选
13             IEnvelope pEnv=new EnvelopeClass();
14             pEnv =axMapControl1.ActiveView.Extent;
15             pEnv.Height= 100;
16             pEnv.Width  = 100;
17             pEnv.CenterAt(pPoint);
18             pIDArray = pIdentify.Identify(pEnv);
19             //矩形选择
20              //IEnvelope testIRectangleElement;
21            //testIRectangleElement = axMapControl1.TrackRectangle();
22            //pIDArray = pIdentify.Identify(testIRectangleElement);
23            //i = pIDArray.Count;
24             if (pIDArray != null)
25             {
26                 for (int i = 0; i <= pIDArray.Count; i++)
27                 {
28                     pFeatIdObj = (IFeatureIdentifyObj)pIDArray.get_Element(i);
29                     pIdObj = (IIdentifyObj)pFeatIdObj;
30                     pIdObj.Flash(axMapControl1.ActiveView.ScreenDisplay);
31                     //消息显示查询目标的信息
32                     MessageBox.Show("Layer:" + pIdObj.Layer.Name + "Feature:" + pIdObj.Name);
33                 }

34             }

35             else
36             {
37                 MessageBox.Show("No feature identified.");
38             }

39
40        }
41
42
43
44
(部分代码来自ESRI中国社区)

posted on 2008-05-26 22:21  duckweeds  阅读(1301)  评论(0编辑  收藏  举报

导航