IFeatureCursor中功能的get_value

时间:2019-10-14 00:36:00

标签: arcobjects

我正在尝试读取IFeatureCursor中功能的属性“ POSTCODE”。 FID已成功读取,但“ POSTCODE”失败。运行时错误“未找到期望字段或无法正确检索。感谢您的建议。保罗

   private void test2(IFeatureCursor pFeatc1)
    {
        IFeature feature = null;
        IFields pFields;
        int ctcur = 0;
        while ((feature = pFeatc1.NextFeature()) != null)
        {
            pFields = feature.Fields;
            int indxid = pFields.FindField("FID");
            int indxpost = pFields.FindField("POSTCODE");
            object valu = feature.get_Value(indxid);
            string valupost = feature.get_Value(indxpost);
            string aValu = Convert.ToString(valu);
            Debug.WriteLine("FID: " + aValu + " Postcode: " + valupost);
            ctcur++;
            feature = pFeatc1.NextFeature();
        }
        MessageBox.Show("count cursor = " + ctcur);
    }

1 个答案:

答案 0 :(得分:0)

我已修改程序并成功读取功能属性“ POSTCODE”。我添加了IFeatureClass.Search(queryFilter,true)以再次通过FID搜索功能并将其保存在光标中,然后使用'feature.get_Value'读取属性。请在下面查看我的更新代码。谢谢。

   private void test2(IFeatureCursor pFeatc1)
    {
        IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
        IMap map = mxdoc.FocusMap;
        IFeatureLayer flayer;
        IMaps pMaps = mxdoc.Maps;
        for (int i = 0; i <= pMaps.Count - 1; i++)
        {
            map = pMaps.get_Item(i);
            IEnumLayer pEnumLayer = map.get_Layers(null, true);
            pEnumLayer.Reset();
            ILayer pLayer = pEnumLayer.Next();
            while (pLayer != null)
            {
                if (pLayer.Name == "AddrKey")
                {
                    Debug.WriteLine("Layer: " + pLayer.Name);
                    flayer = (IFeatureLayer)pLayer;
                    IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

                    IFeature feature = null;
                    IFields pFields;
                    while ((feature = pFeatc1.NextFeature()) != null)
                    {
                        pFields = feature.Fields;
                        int indx = pFields.FindField("FID");
                        object valu = feature.get_Value(indx);
                        string sFID = Convert.ToString(valu);
                        IQueryFilter queryFilter = new QueryFilter();
                        queryFilter.WhereClause = ("FID = " + sFID);
                        Debug.WriteLine("FID: " + sFID);
                        queryFilter.SubFields = "POSTCODE";
                        int fieldPosition = pFeatureClass.FindField("POSTCODE");
                        IFeatureCursor featureCursor = pFeatureClass.Search(queryFilter, true);
                        while ((feature = featureCursor.NextFeature()) != null)
                        {
                            MessageBox.Show(feature.get_Value(fieldPosition));
                        }
                        feature = pFeatc1.NextFeature();
                    }
                }
               pLayer = pEnumLayer.Next();
            }
        }
    }