Ejemplo n.º 1
0
        /// <summary>
        /// 在内存中创建新要素类,根据查询条件复制要素到新要素类,返回新要素类
        /// </summary>
        /// <param name="sourceClass">要素类</param>
        /// <param name="whereClause">筛选条件,值为null或Empty时将复制全部要素</param>
        /// <param name="memoryClassName">内存要素类的名称</param>
        /// <returns></returns>
        public static IFeatureClass CopyDataToNewMemory(this IFeatureClass sourceClass, string whereClause, string memoryClassName = "tempFeatureClass")
        {
            var fields      = sourceClass.CloneFeatureClassFields();
            var memoryClass = CreateInMemory(memoryClassName, fields);

            sourceClass.QueryFeatures(whereClause, feature =>
            {
                IFeature memoryFeature = memoryClass.CreateFeature();
                memoryFeature.Shape    = feature.ShapeCopy;
                for (int i = 0; i < memoryClass.Fields.FieldCount; i++)
                {
                    memoryFeature.set_Value(i, feature.get_Value(i));
                }

                memoryFeature.Store();
            });
            return(memoryClass);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在内存中创建新要素类,根据查询条件复制要素到新要素类,返回新要素类
        /// </summary>
        /// <param name="sourceClass">要素类</param>
        /// <param name="whereClause">筛选条件,值为null或Empty时将复制全部要素</param>
        /// <param name="memoryClassName">内存要素类的名称</param>
        /// <returns></returns>
        public static IFeatureClass CopyDataToNewMemory(this IFeatureClass sourceClass, string whereClause, string memoryClassName = "tempFeatureClass")
        {
            IFields       fields      = sourceClass.CloneFeatureClassFields();
            IFeatureClass memoryClass = CreateInMemory(memoryClassName, fields);
            IQueryFilter  filter      = new QueryFilterClass();

            filter.WhereClause = whereClause;
            IFeatureCursor cursor = sourceClass.Search(filter, false);
            IFeature       feature;

            while ((feature = cursor.NextFeature()) != null)
            {
                IFeature tmpFeature = memoryClass.CreateFeature();
                tmpFeature.Shape = feature.ShapeCopy;
                tmpFeature.Store();
            }
            return(memoryClass);
        }