现在的位置: 首页 > 综合 > 正文

Arcengine, C#,有objectid返回Feature

2013年10月02日 ⁄ 综合 ⁄ 共 1922字 ⁄ 字号 评论关闭

1、       查询实现

/// <summary>

        /// 获得Feature

        /// </summary>

        /// <param name="pLineLayer"></param>

        /// <param name="FID"></param>

        /// <returns></returns>

        private IFeature GetFeatureByFID(IFeatureClass pFeatureClass, int FID)

        {

 

            IQueryFilter pQueryFilter = new QueryFilterClass();

            pQueryFilter.WhereClause =pFeatureClass.OIDFieldName+ "=" + FID;

            IFeatureCursor pFeatureCursor = pFeatureClass.Search(pQueryFilter, true);

            try

            {

                return pFeatureCursor.NextFeature();

            }

            finally

            {

                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);

            }

        }

2、       直接使用GetFeature

PFeatureClass.GetFeature(10);

3、       比较两者速度一样,方法二简单,方法一灵活,可以方便改为其他使用

4、       多个ID使用

      public void IFeatureClass__GetFeatures(IFeatureClass featureClass, string nameOfField)

        {

            //get the index of the field we are interested in

            int fieldIndexValue = featureClass.FindField(nameOfField);

 

            System.Collections.Generic.List<int> constructoidList = new System.Collections.Generic.List<int>();

            constructoidList.Add(1);

            constructoidList.Add(2);

            constructoidList.Add(3);

            constructoidList.Add(4);

            constructoidList.Add(10);

            int[] oidList = constructoidList.ToArray();

 

            IFeatureCursor featureCursor = featureClass.GetFeatures(oidList, false);

            IFeature feature = featureCursor.NextFeature();

            // loop through the returned features and get the value for the field

            while (feature != null)

            {

                //do something with each feature(ie update geometry or attribute)

                Console.WriteLine("The {0} field contains a value of {1}", nameOfField, feature.get_Value(fieldIndexValue));

                feature = featureCursor.NextFeature();

            }

 

        }

抱歉!评论已关闭.