Exemplo n.º 1
0
        /// <summary>
        /// 根据源图层后缀,自动判断打开对应的工作空间
        /// </summary>
        /// <param name="sourceLayer"></param>
        /// <returns></returns>
        public static IWorkspace OpenWorkspace(String sourceLayer)
        {
            string     PathName   = System.IO.Path.GetDirectoryName(sourceLayer);
            IWorkspace pWorkspace = null;

            if (sourceLayer.IndexOf(".shp") != -1)
            {
                pWorkspace = WorkspaceUtil.OpenShapeFileWorkspace(PathName);
            }
            else if (sourceLayer.IndexOf(".mdb") != -1)
            {
                PathName   = sourceLayer.Substring(0, sourceLayer.IndexOf(".mdb") + 4);
                pWorkspace = WorkspaceUtil.OpenMdbWorspace(PathName);
            }
            else if (sourceLayer.IndexOf(".gdb") != -1)
            {
                PathName   = sourceLayer.Substring(0, sourceLayer.IndexOf(".gdb") + 4);
                pWorkspace = WorkspaceUtil.OpenFileGdbWorkspace(PathName);
            }
            else if (sourceLayer.IndexOf(".sde") != -1)
            {
                PathName   = sourceLayer.Substring(0, sourceLayer.IndexOf(".sde") + 4);
                pWorkspace = WorkspaceUtil.OpenSdeWorkspace(PathName, out string user, out string message);
            }
            return(pWorkspace);
        }
Exemplo n.º 2
0
 /// <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 + "要素类");
     }
 }
Exemplo n.º 3
0
        /// <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);
        }