查询结果

C#AE实现点选查询

 

mapControl.MousePointer = esriControlsMousePointer.esriPointerIdentify;//修改鼠标样式
            mapControl.OnMouseDown += new AxESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEventHandler(EsriMapEvent.MapSelection_OnMouseDown);//添加事件

 

 public static void MapSelection_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            AxMapControl map = sender as AxMapControl;
            if (e.button == 1 && map.MousePointer == esriControlsMousePointer.esriPointerIdentify)
            {
                
                #region//获取点选的属性表
                map.Map.ClearSelection();
                IPoint pt = new PointClass();
                pt.PutCoords(e.mapX, e.mapY);
                //根据像素获取实际距离
                double length = map.ActiveView.ConvertPixelsToMapUnits();
                //获取到点选的线
                ITopologicalOperator topoint = pt as ITopologicalOperator;
                //获取缓冲区
                IGeometry buffer = topoint.Buffer(length);
                //选中要素,只有一个要素
                map.Map.SelectByShape(buffer, null, true);
                map.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                IEnumFeature pEnumFeature = map.Map.FeatureSelection as IEnumFeature;
                IFeature pFeature = pEnumFeature.Next();
                if (pFeature == null)
                    return;
                IFeatureClass pfeatureClass = pFeature.Class as IFeatureClass;
                for (int i = 0; i < map.Map.LayerCount; i++)
                {
                    if (map.get_Layer(i) is IFeatureLayer)
                    {
                        IFeatureClass iFeatureCla = (map.get_Layer(i) as IFeatureLayer).FeatureClass;
                        if (iFeatureCla == pfeatureClass)
                        {
                            int OID = Convert.ToInt32(pFeature.Value[0]);
                            pFeature = iFeatureCla.GetFeature(OID);
                            break;
                        }
                    }
                }

                DataTable dt = GetFeatureDataTable(pFeature);
                Form attributeData = new Form();
                attributeData.SetBounds(150, 150, 350, 500);

//dev控件GridControl,用来存放属性数据
                GridControl gridControl = new GridControl();
                gridControl.DataSource = dt;
                attributeData.Controls.Add(gridControl);
                gridControl.Dock = DockStyle.Fill;
                attributeData.Show();
                //清除选择
                map.Map.ClearSelection();

                #endregion
            }

        }
        #region//获得Ifeature的属性及字段
        public static DataTable GetFeatureDataTable(IFeature pFeature)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("位置:");
            dt.Columns.Add("数据:");

            for (int i = 0; i < pFeature.Fields.FieldCount; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = pFeature.Fields.Field[i].Name;
                dr[1] = pFeature.Value[i];
                dt.Rows.Add(dr);
            }
            return dt;
        }
        #endregion

相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2021-11-28
  • 2021-12-05
猜你喜欢
  • 2021-11-21
  • 2021-11-28
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案