Hopes

          Start Here..

           

          FeatureClass.Search(IQuery Filter,bool Recycling)參數(shù)說明

          FeatureClass.Search(IQuery Filter,bool Recycling)參數(shù)說明
          2011-07-19 8:32
          IFeatureClass的Search方法大家經(jīng)常用到,很多人對Search方法的其中一個參數(shù)bool Recycling不是很理解。
          目前網(wǎng)上關(guān)于這個參數(shù)的意義的解釋有兩個版本:
          1.第一版本是Isnotnull大牛的:
          http://bbs.esrichina-bj.cn/ESRI/viewthread.php?tid=13461
          他提出的觀點的是:參數(shù)Recycling為True的時候是傳引用,為False的時候為傳值
          2.第二個版本是Echo兄的:
          http://gis.cnblogs.com/home.aspx?page=3
          他提出的觀點是:參數(shù)Recycling為True的時候游標(biāo)對象(Ifeaturecursor)是只包含一條記錄,為False的時候游標(biāo)對象(Ifeaturecursor)為10條記錄(假設(shè)Featureclass有10條記錄)

          我經(jīng)過測試提出個人的觀點:
          1.pFeatureCursor存儲的是所有符合條件的Feature對象的引用,
          2.Recycling的意思是回收,參數(shù)Recycling為True的時當(dāng)執(zhí)行這個方法IFeature pFeature=pFeatureCursor.NextFeature()上一條記錄的值在內(nèi)存中所占的地址就會被銷毀回收,為False的時候當(dāng)執(zhí)行這個方法IFeature pFeature=pFeatureCursor.NextFeature()上一條記錄的值依然存在在內(nèi)存中。
          Ok,接下來以實例證明本觀點:

          1.參數(shù)Recycling設(shè)置為True
                     IFeatureClass pFeatureClass = (this.axMapControl1.get_Layer(0) as IFeatureLayer).FeatureClass;
                      IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, true);
                      //IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                      List<IFeature> pFeatures = new List<IFeature>();
                      IFeature pFeature = pFeatureCursor.NextFeature();
                      while (pFeature != null)
                      {
                          pFeatures.Add(pFeature);
                          pFeature = pFeatureCursor.NextFeature();
                      }
                      
                      for (int i = 0; i < pFeatures.Count; i++)
                      {
                          MessageBox.Show(((pFeatures.Shape as IPolygon) as IArea).Area.ToString());
                      }
          分析:pFeatures集合存儲了指向FeatureClass上所有Feature的引用,但是由于Recycling參數(shù)設(shè)置為TRUE也就是說沒執(zhí)行一個NextFeautre方法上一條記錄的Feature值在內(nèi)存中被回收,所以到最后遍歷pFeatures集合的時候所有的IFeature引用指向的Feature對象都為Null。所以會引發(fā)一下錯誤(如下圖所示):




          2.參數(shù)Recycling設(shè)置為False
                     IFeatureClass pFeatureClass = (this.axMapControl1.get_Layer(0) as IFeatureLayer).FeatureClass;
                     //IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, true);
                      IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
                      List<IFeature> pFeatures = new List<IFeature>();
                      IFeature pFeature = pFeatureCursor.NextFeature();
                      while (pFeature != null)
                      {
                          pFeatures.Add(pFeature);
                          pFeature = pFeatureCursor.NextFeature();
                      }
                      
                      for (int i = 0; i < pFeatures.Count; i++)
                      {
                          MessageBox.Show(((pFeatures.Shape as IPolygon) as IArea).Area.ToString());
                      }
          分析:pFeatures集合存儲了指向FeatureClass上所有Feature的引用,但是由于Recycling參數(shù)設(shè)置為False也就是說每執(zhí)行一個NextFeautre方法上一條記錄的Feature值在內(nèi)存中依然存在,所以到最后遍歷pFeatures集合的時候所有的 IFeature引用指向的Feature對象都依然存在。所以會執(zhí)行的很Happy(如下圖所示):

           

          posted on 2012-04-05 19:52 ** 閱讀(1821) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計

          公告

          你好!

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          收藏夾

          C#學(xué)習(xí)

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 博兴县| 韶山市| 佛坪县| 五河县| 宁化县| 独山县| 抚宁县| 镇原县| 卓尼县| 那曲县| 舒城县| 徐闻县| 尚义县| 大石桥市| 冷水江市| 得荣县| 甘孜县| 古浪县| 彭山县| 香格里拉县| 怀安县| 怀远县| 长子县| 潞城市| 仲巴县| 云浮市| 铁岭市| 徐州市| 奇台县| 沙雅县| 长沙市| 安国市| 惠来县| 棋牌| 项城市| 峨边| 江都市| 当阳市| 松潘县| 靖边县| 兴和县|