添加已加载shp文件的字段值转为List<Point>

博客展示了一段代码,定义了AddfieldsValueToPointD方法,用于将字段值添加到PointD列表中。通过获取图层、要素类、字段等信息,遍历要素并提取坐标和名称,存储到PointD对象中,最后返回PointD列表。还定义了PointD结构体。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        public List<PointD> AddfieldsValueToPointD(int layerNum)
        {
            List<PointD> points = new List<PointD>();
            ILayer layer = null;
            layer = axMapControl1.Map.get_Layer(layerNum);
            IFeatureLayer featureLayer = layer as IFeatureLayer;
            IFeatureClass featureclass = featureLayer.FeatureClass;
            IFields fields = featureclass.Fields;
            IFeatureCursor pFeatureCursor;
            pFeatureCursor = featureLayer.FeatureClass.Search(null, false);
            IFeature pFeature= pFeatureCursor.NextFeature();
            int pointNameIndex = pFeature.Fields.FindField("pointName");
            int YIndex = pFeature.Fields.FindField("Y");
            int XIndex = pFeature.Fields.FindField("X");
            while (pFeature != null)
            {
                PointD point = new PointD();
                
                point.pointName = pFeature.get_Value(pointNameIndex).ToString();
                point.X = Convert.ToDouble(pFeature.get_Value(XIndex).ToString());
                point.Y = Convert.ToDouble(pFeature.get_Value(YIndex).ToString());
                points.Add(point);
                pFeature = pFeatureCursor.NextFeature();
            }
            return points;
        }

 

 public struct PointD
        {
            public double X;
            public double Y;
            public string pointName;
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值