/// <summary> /// 打开图层 /// </summary> /// <param name="featureClassPath">要素类完成目录和要素类名称,格式:目录|要素类</param> /// <param name="featureClassPathSeparator">要素类路径分隔符</param> /// <param name="workspace">输出打开的工作空间</param> /// <param name="featureClass">输出打开的要素类</param> public static void OpenFeatureClass(string featureClassPath, string featureClassPathSeparator, out IFeatureWorkspace workspace, out IFeatureClass featureClass) { string[] paths = featureClassPath.Split(featureClassPathSeparator); if (2 == paths.Length) { workspace = WorkspaceUtil.OpenWorkspace(paths[0]) as IFeatureWorkspace; featureClass = workspace.OpenFeatureClass(paths[1]); } else { LOG.Error("数据源路径格式不正确"); throw new Exception("数据源路径格式不正确,格式应为:mdb路径" + featureClassPathSeparator + "要素类"); } }
/// <summary> /// 拷贝图层到目标数据库 /// </summary> /// <param name="sourceLayers">原始图层</param> /// <param name="targetDatabase">本地mdb或者gdb</param> public static bool CopyLayer(string[] sourceLayers, string targetDatabase) { foreach (string sourceLayer in sourceLayers) { try { string pLayerName = System.IO.Path.GetFileName(sourceLayer); IWorkspace pWorkspace = WorkspaceUtil.OpenWorkspace(sourceLayer); IFeatureClass featureClass = (pWorkspace as IFeatureWorkspace).OpenFeatureClass(pLayerName); IWorkspace pOutWorkspace = WorkspaceUtil.OpenWorkspace(targetDatabase); FeatureClassUtil.ExportToWorkspace(featureClass, pOutWorkspace); } catch (Exception ex) { LOG.Error("拷贝图层失败,详情:" + ex.Message); continue; } } LOG.Info("完成拷贝图层"); return(true); }