用C#+AE方法查看mdb文件属性

private List<IFeature> RecSelectFetures(IFeatureLayer pFeatureLayer)
        {
            List<IFeature> pFeatures = new List<IFeature>();
            if (pFeatureLayer != null)
            {
                IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
                pFeatureSelection.Clear();
                axMapControl1.Refresh();


                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                IGeometry pGeometry = axMapControl1.TrackRectangle();
                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                pSpatialFilter.Geometry = pGeometry;
                pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pSpatialFilter, false);
                IFeature pFeature = pFeatureCursor.NextFeature();
                pFeatureSelection.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew;
                while (pFeature != null)
                {
                    pFeatureSelection.Add(pFeature);
                    pFeatures.Add(pFeature);
                    pFeature = pFeatureCursor.NextFeature();
                }
                axMapControl1.ActiveView.Refresh();
            }
            return pFeatures;

        }

 private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
        {
            IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft;
            IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight;
            int x1, x2, y1, y2;
            pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1);
            pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2);
            double pixelExtent = x2 - x1;
            double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
            double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
            return pixelUnits * sizeOfOnePixel;
        }


注意本人使用了Dev的treeList,直接复制是会出错的,建议使用时自行修改。


        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            IMap pMap = axMapControl1.Map;
            IActiveView pActiveView = pMap as IActiveView;
            IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
            IPoint point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            ITopologicalOperator pTOpo = point as ITopologicalOperator;
            double length;
            length = ConvertPixelsToMapUnits(pActiveView, 4);
            IGeometry pBuffer = pTOpo.Buffer(length);
            IGeometry pGeomentry = pBuffer.Envelope;
            ISelectionEnvironment pSelEnv = new SelectionEnvironment();//新建选择环境
            IRgbColor pColor = new RgbColor();
            pColor.Red = 255;
            pSelEnv.DefaultColor = pColor;//设置高亮颜色
            pMap.SelectByShape(pBuffer, pSelEnv, false);//选择图
            axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);


            List<IFeature> S = RecSelectFetures(pFeatureLayer);
            if (S.Count > 0)
            {
                treeList1.ClearNodes();
                try
                {
                    treeList1.BeginUpdate();
                    int k = 0;
                    for (int i = 0; i < S.Count; i++)
                    {
                        for (int j = 0; j < S[i].Fields.FieldCount; j++)
                        {
                            IField pFiled = S[i].Fields.get_Field(j);
                            treeList1.Columns.Add();
                            treeList1.Columns[j].Caption = pFiled.Name;
                            treeList1.Columns[j].VisibleIndex = j;
                        }
                        string sFirseFidValue = S[i].get_Value(0).ToString();
                        treeList1.AppendNode(new object[] { sFirseFidValue }, null);
                        for (int m = 1; m < S[i].Fields.FieldCount; m++)
                        {
                            object FieldValue;
                            if (S[i].Class.Fields.get_Field(m).Name == "SHAPE")
                            {
                                FieldValue = S[i].Shape.GeometryType.ToString();
                            }
                            else
                            {
                                FieldValue = S[i].get_Value(m).ToString();
                            }
                            treeList1.Nodes[k][m] = FieldValue;
                        }
                        k = k + 1;
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show("错误" + exc.ToString());
                }
                finally
                {
                    treeList1.EndUpdate();
                }
            }
        }


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值