Arcengine 的IEnumFeature接口使用的一个细节

5 篇文章 0 订阅

前阵子写一个到处SHP文件的函数不断出现到处后属性为空的问题,后来尝试半天,发现是少了两行代码,虽然解决了,但是其实还是不知道这两行代码是干什么的,后来网上读到前人帖子提到这个。http://blog.csdn.net/brokencar/article/details/6069997

API中的REMARK,他是这样写的:When this interface is used to access features from a map's feature selection (IMap.FeatureSelection), the IEnumFeatureSetup.AllFields property should be used to return fully hydrated features.也就是说:ArcGIS中FeatureSelection默认的时候只存入Feature 的Shape,而不是整个Feature的字段数据。如果要查看其他数据,必须要进行以下转换才可以。


            IActiveView pActiveView = axMapControl1.ActiveView;

            IMap pMap = axMapControl1.ActiveView.FocusMap;
            if (pMap.SelectionCount == 0) return;
            IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
            IEnumFeatureSetup pEnumFeatureSetup = pEnumFeature as IEnumFeatureSetup;
            pEnumFeatureSetup.AllFields = true;

            IFeature pFeature = pEnumFeature.Next();


         
            while (pFeature != null)

            {

 for (int i = 0; i < frmExport.pTableField.Rows.Count; i++)
                        {

//如果缺少红色的两行代码,则虽然pFeature不为空,pFeature的fieldcount也是对的,但是 pFeature.get_Value(i)时一直为null,导出属性表很多字段也会为空
                            object strtemp = pFeature.get_Value(i);
                            string str1;
                            if(strtemp!=null)
                            str1 = strtemp.ToString();
                        }

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值