Exemple #1
0
        /// <summary>
        /// 从另一张表复制数据(数据结构相同)
        /// </summary>
        /// <param name="ZFClass"></param>
        /// <param name="clear">是否清空原数据</param>
        public static void CopyFrom(this IFeatureClass featureClass, IFeatureClass otherFeatureClass, bool clear = false)
        {
            if (clear)
            {
                featureClass.Delete();
            }
            //MergeStructFrom
            IFeatureCursor cursor = otherFeatureClass.Search();

            featureClass.CopyFrom(cursor);
        }
 /// <summary>
 /// 将IFeatureCursor保存到指定表
 /// </summary>
 /// <param name="cursor"></param>
 /// <param name="featureClass"></param>
 /// <returns></returns>
 public static bool SaveToFeatureClass(this IFeatureCursor cursor, IFeatureClass featureClass)
 {
     try
     {
         featureClass.CopyFrom(cursor);
     }
     catch (Exception e) {
         Console.WriteLine(e);
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// 复制图层
        /// </summary>
        /// <param name="oldName"></param>
        /// <param name="newName"></param>
        /// <param name="copyReords">思否复制记录</param>
        public static IFeatureClass CopyFeatureClass(this IFeatureWorkspace workspace, string oldName, string newName, bool copyReords = false)
        {
            IFeatureClass oldFClass = workspace.OpenFeatureClass(oldName);

            if (oldFClass != null)
            {
                IFields       fields    = oldFClass.Fields.Clone();
                IFeatureClass newFClass = workspace.CreateFeatureClass(newName, fields, oldFClass.FeatureType, oldFClass.ShapeFieldName);
                if (copyReords)
                {
                    newFClass.CopyFrom(oldFClass);
                }
                return(newFClass);
            }
            return(null);
        }