Esempio n. 1
0
        private static ESRI.ArcGIS.Geodatabase.IFeatureWorkspace getWorkspace(string fPath)
        {
            fPath = fPath.Trim();

            string workspacePath = System.IO.Path.GetDirectoryName(fPath);
            string featureClass  = System.IO.Path.GetFileName(fPath);

            if ((new Regex(@"\.shp$")).IsMatch(fPath))
            {
                try
                {
                    return(shapeWsf.OpenFromFile(workspacePath, 0) as IFeatureWorkspace);
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    throw new System.IO.FileNotFoundException("Shapefile workspace not found: " + workspacePath);
                }
            }
            else if ((new Regex(@"\\[^\\]*\.(gdb|GDB)\\[^\\]*$")).IsMatch(fPath))
            {
                try
                {
                    return(gdbWsf.OpenFromFile(workspacePath, 0) as IFeatureWorkspace);
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    throw new System.IO.FileNotFoundException("Geodatabase workspace not found: " + workspacePath);
                }
            }
            else if ((new Regex(@"\\[^\\]*\.(gdb|GDB)\\[^\\]*\\[^\\]*$")).IsMatch(fPath))
            {
                string datasetName = System.IO.Path.GetFileName(workspacePath);
                workspacePath = System.IO.Path.GetDirectoryName(workspacePath);
                ESRI.ArcGIS.Geodatabase.IWorkspace ws = gdbWsf.OpenFromFile(workspacePath, 0);

                ESRI.ArcGIS.Geodatabase.IEnumDataset dss = ws.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset);
                ESRI.ArcGIS.Geodatabase.IDataset     ds;

                while ((ds = dss.Next()) != null)
                {
                    if (ds.Name == datasetName)
                    {
                        return(ds.Workspace as IFeatureWorkspace);
                    }
                }
                throw new System.IO.FileNotFoundException("feature dataset not found: " + System.IO.Path.Combine(workspacePath, datasetName));
            }
            else
            {
                throw new System.IO.FileNotFoundException("Invalid feature class path: " + fPath);
            }
        }
Esempio n. 2
0
        public static bool GetAllDataSets(string strServer, string strServerName, string strDataBase, string strUser, string strPassWord, string strVersion, string strDataType, out List <string> listDatasets)
        {
            //cyf 20110609 测试数据库连接 包括SDE、PDB、gdb
            Fan.Common.Gis.SysGisDataSet pSysDt = new Fan.Common.Gis.SysGisDataSet();
            Exception pError = null;

            listDatasets = null;
            //if (this.combox_DBFormat.SelectedValue.ToString() == enumInterDBFormat.ARCGISGDB.GetHashCode().ToString())
            //{
            //    if (!Directory.Exists(txtDataBase.Text))
            //    {
            //        pError = new Exception("数据库文件路径不存在!");
            //        return false;
            //    }
            //    pSysDt.SetWorkspace(this.txtDataBase.Text, enumWSType.GDB, out pError);
            //}
            //else if (this.combox_DBFormat.SelectedValue.ToString() == enumInterDBFormat.ARCGISSDE.GetHashCode().ToString())
            //{
            pSysDt.SetWorkspace(strServer, strServerName, strDataBase, strUser, strPassWord, strVersion, out pError);

            //}
            //else if (this.combox_DBFormat.SelectedValue.ToString() == enumInterDBFormat.ARCGISPDB.GetHashCode().ToString())
            //{
            //    if (!File.Exists(txtDataBase.Text))
            //    {pError = new Exception("数据库路径不存在!");
            //        return false;
            //    }

            //    pSysDt.SetWorkspace(this.txtDataBase.Text, enumWSType.PDB, out pError);
            //}
            //if (pError != null)
            //{
            //    pError = new Exception("连接数据库失败!");
            //    return false;
            //}
            ESRI.ArcGIS.Geodatabase.IWorkspace pWs = pSysDt.WorkSpace;
            if (pWs == null)
            {
                return(false);
            }
            //连接成功后,将数据集加载到下拉列表框中
            if (strDataType.Equals("DLG"))
            {
                //框架要素库中数据集名称
                List <string> LstDtName = pSysDt.GetAllFeatureDatasetNames();
                if (LstDtName.Count == 0)
                {
                    //pError = new Exception("该数据库下不存在数据集,请检查!");
                    return(false);
                }
                //遍历数据集名称,将数据集加载在下拉列表框中
                if (listDatasets == null)
                {
                    listDatasets = new List <string>();
                }
                foreach (string item in LstDtName)
                {
                    //历史数据集,不添加
                    if (item.ToLower().EndsWith("_GOH"))
                    {
                        continue;
                    }
                    string GetDataSetName = item;//数据集名称
                    //添加
                    listDatasets.Add(GetDataSetName);
                }
            }
            else if (strDataType.Equals("DOM") || strDataType.Equals("DEM"))
            {
                IEnumDataset pEnumDataset = null;

                pEnumDataset = pWs.get_Datasets(esriDatasetType.esriDTRasterDataset);
                if (pEnumDataset == null)
                {
                    pError = new Exception("获取栅格数据名称出错!");
                    return(false);
                }
                pEnumDataset.Reset();
                IDataset pDt = pEnumDataset.Next();
                if (listDatasets == null)
                {
                    listDatasets = new List <string>();
                }
                //遍历栅格数据集
                while (pDt != null)
                {
                    string rasteName = ""; //栅格数据名称
                    rasteName = pDt.Name;
                    //添加
                    listDatasets.Add(rasteName);
                    pDt = pEnumDataset.Next();
                }


                pEnumDataset = pWs.get_Datasets(esriDatasetType.esriDTRasterCatalog);
                if (pEnumDataset == null)
                {
                    pError = new Exception("获取栅格数据名称出错!");
                    return(false);
                }
                pEnumDataset.Reset();
                pDt = pEnumDataset.Next();
                if (pDt == null)
                {
                    pError = new Exception("获取栅格数据名称出错!");
                    return(false);
                }

                //遍历栅格编目
                while (pDt != null)
                {
                    string rasteName = ""; //栅格数据名称
                    rasteName = pDt.Name;

                    //added by chulili 20110715过滤掉原本存在的历史库
                    if (!rasteName.ToLower().EndsWith("_GOH"))
                    {
                        //将栅格数据名称添加到数组中
                        listDatasets.Add(rasteName);
                    }
                    pDt = pEnumDataset.Next();
                }
            }
            return(true);
        }
Esempio n. 3
0
        //获取数据集
        public bool GetAllDataSets(string strServer, string strServerName, string strDataBase, string strUser, string strPassWord, string strVersion, string strDataType, out List <string> listDatasets)
        {
            //cyf 20110609 测试数据库连接 包括SDE、PDB、gdb
            SysCommon.Gis.SysGisDataSet pSysDt = new SysCommon.Gis.SysGisDataSet();
            Exception pError = null;

            listDatasets = null;
            pSysDt.SetWorkspace(strServer, strServerName, strDataBase, strUser, strPassWord, strVersion, out pError);


            ESRI.ArcGIS.Geodatabase.IWorkspace pWs = pSysDt.WorkSpace;
            if (pWs == null)
            {
                return(false);
            }
            //连接成功后,将数据集加载到下拉列表框中
            if (strDataType.Equals("DLG"))
            {
                //框架要素库中数据集名称
                List <string> LstDtName = pSysDt.GetAllFeatureDatasetNames();
                if (LstDtName.Count == 0)
                {
                    //pError = new Exception("该数据库下不存在数据集,请检查!");
                    return(false);
                }
                //遍历数据集名称,将数据集加载在下拉列表框中
                if (listDatasets == null)
                {
                    listDatasets = new List <string>();
                }
                foreach (string item in LstDtName)
                {
                    //历史数据集,不添加
                    if (item.ToLower().EndsWith("_GOH"))
                    {
                        continue;
                    }
                    string GetDataSetName = item;//数据集名称
                    //添加
                    listDatasets.Add(GetDataSetName);
                }
            }
            //  else if (strDataBase.Equals("DOM") || strDataBase.Equals("DEM"))
            else if (strDataType.Equals("DOM") || strDataType.Equals("DEM"))

            {
                IEnumDataset pEnumDataset = null;

                pEnumDataset = pWs.get_Datasets(esriDatasetType.esriDTRasterDataset);
                if (pEnumDataset == null)
                {
                    pError = new Exception("获取栅格数据名称出错!");
                    return(false);
                }
                pEnumDataset.Reset();
                IDataset pDt = pEnumDataset.Next();
                if (listDatasets == null)
                {
                    listDatasets = new List <string>();
                }
                //遍历栅格数据集
                while (pDt != null)
                {
                    string rasteName = ""; //栅格数据名称
                    rasteName = pDt.Name;
                    //添加
                    listDatasets.Add(rasteName);
                    pDt = pEnumDataset.Next();
                }


                pEnumDataset = pWs.get_Datasets(esriDatasetType.esriDTRasterCatalog);
                if (pEnumDataset == null)
                {
                    pError = new Exception("获取栅格数据名称出错!");
                    return(false);
                }
                pEnumDataset.Reset();
                pDt = pEnumDataset.Next();
                if (pDt == null)
                {
                    pError = new Exception("获取栅格数据名称出错!");
                    return(false);
                }

                //遍历栅格编目
                while (pDt != null)
                {
                    string rasteName = ""; //栅格数据名称
                    rasteName = pDt.Name;

                    //added by chulili 20110715过滤掉原本存在的历史库
                    if (!rasteName.ToLower().EndsWith("_GOH"))
                    {
                        //将栅格数据名称添加到数组中
                        listDatasets.Add(rasteName);
                    }
                    pDt = pEnumDataset.Next();
                }
            }
            return(true);
        }