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

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

Identify接口定义了获得要素图层单个要素的属性的捷径方法。它有一个Identify方法,返回一个IArray数组对象。
将下列代码放入MouseDown事件中,可以实现点选或者矩形选择要素。

IMap pMap;
IPoint pPoint;
pMap = axMapControl1.Map;
pPoint = axMapControl1.ToMapPoint(e.x, e.y);
IIdentify pIdentify;
pIdentify = (IIdentify)pMap.get_Layer(0);
IArray pIDArray;
IFeatureIdentifyObj pFeatIdObj;
IIdentifyObj pIdObj;

//点选
IEnvelope pEnv=new EnvelopeClass();
pEnv =axMapControl1.ActiveView.Extent;
pEnv.Height= 100;
pEnv.Width  = 100;
pEnv.CenterAt(pPoint);
pIDArray = pIdentify.Identify(pEnv);

//矩形选择
 //IEnvelope testIRectangleElement;
//testIRectangleElement = axMapControl1.TrackRectangle();
//pIDArray = pIdentify.Identify(testIRectangleElement);
//i = pIDArray.Count;
if (pIDArray != null)
{
    for (int i = 0; i <= pIDArray.Count; i++)
    {
        pFeatIdObj = (IFeatureIdentifyObj)pIDArray.get_Element(i);
        pIdObj = (IIdentifyObj)pFeatIdObj;
        pIdObj.Flash(axMapControl1.ActiveView.ScreenDisplay);
        //消息显示查询目标的信息
        MessageBox.Show("Layer:" + pIdObj.Layer.Name + "Feature:" + pIdObj.Name);
    }
}
else
{
    MessageBox.Show("No feature identified.");
}

}

此外,有关使用Identify,实现点击查询并闪烁显示,并把查询要素的信息通过DataGridView显示出来。可参考本博文文章AE中Identify查询工具的实现

原文地址:https://www.cnblogs.com/arxive/p/6113655.html