You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							256 lines
						
					
					
						
							12 KiB
						
					
					
				
			
		
		
	
	
							256 lines
						
					
					
						
							12 KiB
						
					
					
				using ESRI.ArcGIS.DataSourcesFile; | 
						|
using ESRI.ArcGIS.Geodatabase; | 
						|
using KGIS.Framework.OpenData.Control; | 
						|
using KGIS.Framework.OpenData.Filter; | 
						|
using KGIS.Framework.OpenData.InterFace; | 
						|
using KGIS.Framework.Utils.Helper; | 
						|
using Kingo.PluginServiceInterface.Helper.VCT; | 
						|
using System; | 
						|
using System.Collections.Generic; | 
						|
using System.IO; | 
						|
using System.Runtime.InteropServices; | 
						|
 | 
						|
namespace Kingo.PluginServiceInterface.Helper | 
						|
{ | 
						|
    /// <summary> | 
						|
    /// 选择矢量数据帮助类 | 
						|
    /// </summary> | 
						|
    public class OpenDataDialogHelper | 
						|
    { | 
						|
        /// <summary> | 
						|
        /// 选择矢量数据(GDB_MDB_SHP) | 
						|
        /// </summary> | 
						|
        /// <param name="Title">选择数据的标题</param> | 
						|
        /// <param name="DataPathList">选择数据的路径集合</param> | 
						|
        public static void OpenDataDialog(string Title, ref string FinalLocation, ref List<ISpatialDataObject> Selection) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                OpenDataDialog pDialog = new OpenDataDialog(); | 
						|
                ISpatialDataObjectFilter pOFilter = new FilterShapefiles(); | 
						|
                pDialog.AddFilter(pOFilter, true); | 
						|
                pOFilter = new FilterGeoDatabase(); | 
						|
                //pOFilter = new FilterGeoDatabaseFile();//GDB格式 | 
						|
                //pOFilter = new FilterGeoDatabasePersonal();//MDB格式 | 
						|
                pDialog.AddFilter(pOFilter, true); | 
						|
                pDialog.AllowMultiSelect = true; | 
						|
                pDialog.Title = Title; | 
						|
                pDialog.RestoreLocation = true; | 
						|
                pDialog.StartLocation = pDialog.FinalLocation; | 
						|
                System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog(); | 
						|
                if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) | 
						|
                { | 
						|
                    string ImportDataType = Path.GetExtension(pDialog.FinalLocation).ToUpper().Replace('.', ' ').TrimStart(); | 
						|
                    if ("GDB,MDB".Contains(ImportDataType) && pDialog.Selection.Count > 1) | 
						|
                        throw new Exception("GDB,MDB格式不支持多选!"); | 
						|
                    if (string.IsNullOrWhiteSpace(ImportDataType) || !"GDB,MDB,SHP".Contains(ImportDataType)) | 
						|
                        throw new Exception("选择的数据路径有误,请根据过滤条件,重新选择数据库!!"); | 
						|
                    FinalLocation = pDialog.FinalLocation; | 
						|
                    Selection = pDialog.Selection; | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                CommonHelper.RecordsErrLog("选择矢量数据异常", ex); | 
						|
                throw ex; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 选择矢量数据(GDB_MDB_SHP) | 
						|
        /// </summary> | 
						|
        /// <param name="Title">标题</param> | 
						|
        /// <param name="otherDataPathList">数据绝对路径</param> | 
						|
        /// <param name="pSourceFCList">矢量数据要素类</param> | 
						|
        public static void OpenDataDialog(string Title, ref string FinalLocation, ref List<ISpatialDataObject> Selection, ref List<string> otherDataPathList, ref List<IFeatureClass> pSourceFCList) | 
						|
        { | 
						|
            IWorkspaceFactory pWorkspaceFactory = null; | 
						|
            IWorkspace pWorkspace = null; | 
						|
            IFeatureWorkspace pFeatureWorkspace = null; | 
						|
            try | 
						|
            { | 
						|
                OpenDataDialog pDialog = new OpenDataDialog(); | 
						|
                ISpatialDataObjectFilter pOFilter = new FilterShapefiles(); | 
						|
                pDialog.AddFilter(pOFilter, true); | 
						|
                pOFilter = new FilterGeoDatabase(); | 
						|
                pDialog.AddFilter(pOFilter, true); | 
						|
                pDialog.AllowMultiSelect = true; | 
						|
                pDialog.Title = Title; | 
						|
                pDialog.RestoreLocation = true; | 
						|
                pDialog.StartLocation = pDialog.FinalLocation; | 
						|
                System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog(); | 
						|
                if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) | 
						|
                { | 
						|
                    string ImportDataType = Path.GetExtension(pDialog.FinalLocation).ToUpper().Replace('.', ' ').TrimStart(); | 
						|
                    if ("GDB,MDB".Contains(ImportDataType) && pDialog.Selection.Count > 1) | 
						|
                        throw new Exception("GDB,MDB格式不支持多选!"); | 
						|
                    if (string.IsNullOrWhiteSpace(ImportDataType) || !"GDB,MDB,SHP".Contains(ImportDataType)) | 
						|
                        throw new Exception("选择的数据路径有误,请根据过滤条件,重新选择数据库!!"); | 
						|
                    FinalLocation = pDialog.FinalLocation; | 
						|
                    Selection = pDialog.Selection; | 
						|
                    string fileName = string.Empty; | 
						|
                    if (!string.IsNullOrWhiteSpace(ImportDataType) && ImportDataType.Equals("SHP")) | 
						|
                    { | 
						|
                        pSourceFCList = new List<IFeatureClass>(); | 
						|
                        for (int i = 0; i < pDialog.Selection.Count; i++) | 
						|
                        { | 
						|
                            pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); | 
						|
                            pWorkspace = pWorkspaceFactory.OpenFromFile(Path.GetDirectoryName(pDialog.Selection[i].FullName), 0); | 
						|
                            pFeatureWorkspace = pWorkspace as IFeatureWorkspace; | 
						|
                            IFeatureClass pSourceFeatureClass = pFeatureWorkspace.OpenFeatureClass(pDialog.Selection[i].Name); | 
						|
                            pSourceFCList.Add(pSourceFeatureClass); | 
						|
                            fileName += pDialog.Selection[i].Name + ";"; | 
						|
                        } | 
						|
                        otherDataPathList.Add(fileName); | 
						|
                    } | 
						|
                    else if (!string.IsNullOrWhiteSpace(ImportDataType) && ImportDataType.Equals("VCT")) | 
						|
                    { | 
						|
                        string TempMDBFolderPath = Path.GetTempPath(); | 
						|
                        string TempMDBPath = Path.Combine(TempMDBFolderPath, string.Format("{0}.mdb", Path.GetFileNameWithoutExtension(pDialog.FinalLocation))); | 
						|
                        if (File.Exists(TempMDBPath)) | 
						|
                        { | 
						|
                            File.Delete(TempMDBPath); | 
						|
                        } | 
						|
                        VCTToMDBHelper3 vcttomdb = new VCTToMDBHelper3 | 
						|
                        { | 
						|
                            RootPath = TempMDBFolderPath | 
						|
                        }; | 
						|
                        vcttomdb.VCTToMDB(pDialog.FinalLocation); | 
						|
                        if (!File.Exists(TempMDBPath)) | 
						|
                        { | 
						|
                            MessageHelper.ShowError("VCT文件解析失败"); | 
						|
                            return; | 
						|
                        } | 
						|
                        otherDataPathList.Add(pDialog.FinalLocation); | 
						|
                    } | 
						|
                    else | 
						|
                        otherDataPathList.Add(pDialog.FinalLocation); | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                CommonHelper.RecordsErrLog("选择矢量数据异常", ex); | 
						|
                throw ex; | 
						|
            } | 
						|
            finally | 
						|
            { | 
						|
                if (pWorkspaceFactory != null) | 
						|
                    Marshal.ReleaseComObject(pWorkspaceFactory); | 
						|
                if (pFeatureWorkspace != null) | 
						|
                    Marshal.ReleaseComObject(pFeatureWorkspace); | 
						|
                if (pWorkspace != null) | 
						|
                    Marshal.ReleaseComObject(pWorkspace); | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 选择矢量数据(SHP) | 
						|
        /// </summary> | 
						|
        /// <param name="Title">选择数据的标题</param> | 
						|
        /// <param name="DataPathList">选择数据的路径集合</param> | 
						|
        public static void OpenDataDialogForSHP(ref string FinalLocation, ref List<ISpatialDataObject> Selection) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                OpenDataDialog pDialog = new OpenDataDialog(); | 
						|
                ISpatialDataObjectFilter pOFilter = new FilterShapefiles(); | 
						|
                pDialog.AddFilter(pOFilter, true); | 
						|
                pDialog.AllowMultiSelect = true; | 
						|
                pDialog.Title = "选择SHP矢量数据"; | 
						|
                pDialog.RestoreLocation = true; | 
						|
                pDialog.StartLocation = pDialog.FinalLocation; | 
						|
                System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog(); | 
						|
                if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) | 
						|
                { | 
						|
                    string ImportDataType = Path.GetExtension(pDialog.FinalLocation).ToUpper().Replace('.', ' ').TrimStart(); | 
						|
                    if (string.IsNullOrWhiteSpace(ImportDataType) || !"SHP".Contains(ImportDataType)) | 
						|
                        throw new Exception("选择的数据路径有误,请根据过滤条件,重新选择数据库!!"); | 
						|
                    FinalLocation = pDialog.FinalLocation; | 
						|
                    Selection = pDialog.Selection; | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                CommonHelper.RecordsErrLog("选择矢量数据异常", ex); | 
						|
                throw ex; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 选择矢量数据(GDB_MDB) | 
						|
        /// </summary> | 
						|
        /// <param name="Title">标题</param> | 
						|
        /// <param name="otherDataPathList">数据绝对路径</param> | 
						|
        /// <param name="pSourceFCList">矢量数据要素类</param> | 
						|
        public static void OpenDataDialog(string Title, ref string FinalLocation) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                OpenDataDialog pDialog = new OpenDataDialog(); | 
						|
                ISpatialDataObjectFilter pOFilter = new FilterGeoDatabase(); | 
						|
                pDialog.AddFilter(pOFilter, true); | 
						|
                pDialog.AllowMultiSelect = false; | 
						|
                pDialog.Title = Title; | 
						|
                pDialog.RestoreLocation = true; | 
						|
                pDialog.StartLocation = pDialog.FinalLocation; | 
						|
                System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog(); | 
						|
                if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) | 
						|
                { | 
						|
                    string ImportDataType = Path.GetExtension(pDialog.FinalLocation).ToUpper().Replace('.', ' ').TrimStart(); | 
						|
                    if (string.IsNullOrWhiteSpace(ImportDataType) || !"GDB,MDB".Contains(ImportDataType)) | 
						|
                        throw new Exception("选择的数据路径有误,请根据过滤条件,重新选择数据库!!"); | 
						|
                    FinalLocation = pDialog.FinalLocation; | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                CommonHelper.RecordsErrLog("选择矢量数据异常", ex); | 
						|
                throw ex; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 选择矢量数据(FeatureClass) | 
						|
        /// </summary> | 
						|
        /// <param name="Title">标题</param> | 
						|
        /// <param name="FullName">要素类全名称路径</param> | 
						|
        /// <param name="SelFeatureClass">要素类</param> | 
						|
        public static void OpenDataDialog(string Title, ref string FullName, ref IFeatureClass SelFeatureClass) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                OpenDataDialog pDialog = new OpenDataDialog(); | 
						|
                ISpatialDataObjectFilter pOFilter = new FilterShapefiles(); | 
						|
                pDialog.AddFilter(pOFilter, true); | 
						|
                pOFilter = new FilterFeatureDatasetsAndFeatureClasses(); | 
						|
                pDialog.AddFilter(pOFilter, true); | 
						|
                pDialog.Title = Title; | 
						|
                pDialog.RestoreLocation = true; | 
						|
                pDialog.StartLocation = pDialog.FinalLocation; | 
						|
                pDialog.AllowMultiSelect = false; | 
						|
                System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog(); | 
						|
                if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) | 
						|
                { | 
						|
                    foreach (ISpatialDataObject distObj in pDialog.Selection) | 
						|
                    { | 
						|
                        if (distObj.DatasetType == esriDatasetType.esriDTFeatureClass) | 
						|
                        { | 
						|
                            if ((distObj.DatasetName as ESRI.ArcGIS.esriSystem.IName).Open() is IFeatureClass pFeatureClass) | 
						|
                            { | 
						|
                                SelFeatureClass = pFeatureClass; | 
						|
                                FullName = distObj.FullName; | 
						|
                                break; | 
						|
                            } | 
						|
                        } | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                CommonHelper.RecordsErrLog("选择图层出现异常", ex); | 
						|
                MessageHelper.ShowError("选择图层出现异常:" + ex.Message); | 
						|
            } | 
						|
        } | 
						|
 | 
						|
    } | 
						|
}
 | 
						|
 |