• AE获得鼠标选择的图层信息


    使用SelectionChanged事件

       private void axMapControl_OnSelectionChanged(object sender, EventArgs e)
        {
            if (iMapAction == 1)
            {
                //---------------------------------------Identify--------------------------------------------------//
                ITableSelection pTable;
                ILayer pLayer;
                string pointId = string.Empty;
                //获得选择的点
                for (int i = 0; i < axMapControl.LayerCount; i++)
                {
                    pTable = (ITableSelection)axMapControl.get_Layer(i);
                    pLayer = axMapControl.get_Layer(i);
                    if (pLayer.Name == "newpoint")
                    {
                        pointId = GetFieldValue(AddSelection(pTable.SelectionSet, pLayer.Name));
                        break;
                    }
                    pTable.Clear();
                }
                //判断点是不是为空
                if (!string.IsNullOrEmpty(pointId))
                {
                    //查询是否存在于站点集合中
                    if (hAreaIdList.IndexOf(pointId) != -1)
                    {
                        if (_pfrmRealTimeData == null)
                        {
                            _pfrmRealTimeData = new frmRealTimeData(pointId);
                            _pfrmRealTimeData.ShowDialog();
                        }
                        else
                        {
                            //如果不是第一点击
                            if (pointIdList.Count > 1)
                            {
                                _pfrmRealTimeData = null;
                                _pfrmRealTimeData = new frmRealTimeData(pointId);
                                _pfrmRealTimeData.ShowDialog();
                            }
                        }
                        if (pointIdList.Count < 5)
                            pointIdList.Add(pointId);
                    }
                }
            }
        }

     /// <summary>
        /// 获得选择的图层
        /// </summary>
        /// <param name="pSelection"></param>
        /// <param name="strLayer"></param>
        /// <returns></returns>
        private ArrayList AddSelection(ISelectionSet pSelection, string strLayer)
        {
            IQueryFilter pFilter = new QueryFilterClass();
            ICursor pCursor;
            pSelection.Search(pFilter, false, out pCursor);
            ESRI.ArcGIS.Geodatabase.IRow pRow;
            pRow = pCursor.NextRow();
            ArrayList Keys = new ArrayList();
            Keys.Add(strLayer);
            if (pRow != null)
            {
                IRowBuffer pBuffer;
                do
                {
                    pBuffer = (IRowBuffer)pRow;
                    Keys.Add(pBuffer.get_Value(0));
                    pRow = pCursor.NextRow();
                } while (pRow != null);
            }
            return Keys;
        }

        /// <summary>
        /// 获得节点的值
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private string GetFieldValue(ArrayList list)
        {
            string pointId = string.Empty;
            if (list.Count > 1)
            {
                string strLayer = string.Empty;
                strLayer = list[0].ToString();
                for (int j = 1; j < list.Count; j++)
                {
                    IFeatureLayer pLayer;
                    int i;
                    for (i = 0; i < axMapControl.Map.LayerCount; i++)
                    {
                        if (axMapControl.Map.get_Layer(i).Name == strLayer)
                            break;
                    }
                    pLayer = (IFeatureLayer)axMapControl.Map.get_Layer(i);
                    IFeatureCursor pCursor;
                    IQueryFilter pFilter = new QueryFilterClass();

                    pFilter.WhereClause = " FID = " + list[i];
                    pCursor = pLayer.Search(pFilter, false);
                    IFeature pFeature;
                    IRowBuffer pRow;
                    pFeature = pCursor.NextFeature();
                    if (pFeature != null)
                    {
                        pRow = (IRowBuffer)pFeature;
                        for (int k = 0; k < pRow.Fields.FieldCount; k++)
                        {
                            if (pRow.Fields.get_Field(k).Name == "pointid")
                            {
                                pointId = pRow.get_Value(k).ToString();
                                break;
                            }
                        }
                    }
                }
            }
            return pointId;
        }

    版权说明

      如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。
      作      者:温景良
      文章出处:http://wenjl520.cnblogs.com/  或  http://www.cnblogs.com/

  • 相关阅读:
    剑气之争,聊聊算法岗位的门户之见!
    80%学生的困惑,学完C/C++之后学什么?
    算法工程师日常,训练的模型翻车了怎么办?
    迭代器设计模式,帮你大幅提升Python性能
    十年编程经验总结,三点技巧帮你提升代码能力!
    CenterNet:Corner-Center三元关键点,检测性能全面提升 | ICCV 2019
    CornerNet:经典keypoint-based方法,通过定位角点进行目标检测 | ECCV2018
    阿里面试:MySQL如何设计索引更高效?
    大厂是怎么进行SQL调优的?
    程序人生|从网瘾少年到微软、BAT、字节offer收割机逆袭之路
  • 原文地址:https://www.cnblogs.com/wenjl520/p/1362455.html
Copyright © 2020-2023  润新知