protected override IFeatureDataset CreateFeatureDataset(IWorkspace wsTarget, ISpatialReference pSpatialRef) { if (wsTarget == null) { return(null); } ISpatialReference spatialRef = pSpatialRef; if (spatialRef == null) { if (!string.IsNullOrEmpty(this.ReferenceLayer)) { IWorkspace wsSource = AEAccessFactory.OpenWorkspace(this.m_DataType, this.m_Datasource); IGeoDataset geoDataset = null; // Shp判断使用Try Catch if (this.m_DataType == enumDataType.SHP) { try { geoDataset = (wsSource as IFeatureWorkspace).OpenFeatureClass(this.ReferenceLayer) as IGeoDataset; } catch { } } else { if ((wsSource as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, this.ReferenceLayer)) { geoDataset = (wsSource as IFeatureWorkspace).OpenFeatureClass(this.ReferenceLayer) as IGeoDataset; } else if ((wsSource as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureDataset, this.ReferenceLayer)) { geoDataset = (wsSource as IFeatureWorkspace).OpenFeatureDataset(this.ReferenceLayer) as IGeoDataset; } } if (geoDataset != null) { spatialRef = geoDataset.SpatialReference; } else { SendMessage(enumMessageType.Exception, "NoReferenceDataImport调用错误:数据源中未找到指定的空间参考图层,将按未知参考创建“Dataset”"); } } else { SendMessage(enumMessageType.Exception, "NoReferenceDataImport调用错误:未指定空间参考图层,将按未知参考创建“Dataset”"); } } return(base.CreateFeatureDataset(wsTarget, spatialRef)); }
private bool PrepareForTable(IDataset dsTarget, out string strBaseName, out string strQueryName) { strQueryName = strBaseName = "Base.mdb"; try { AEAccessFactory.CreateFGDB(TempPath, strBaseName); IWorkspace wsBase = AEAccessFactory.OpenWorkspace(enumDataType.FileGDB, string.Format("{0}\\{1}", TempPath, strBaseName)); GPTool gpTool = new GPTool(); DataConverter.ConvertTable(dsTarget.Workspace, wsBase, dsTarget, dsTarget.Name); return(true); } catch { return(false); } }
/// <summary> /// (从数据源)导入到Base库,并返回Base库Workspace对象 /// </summary> /// <param name="wsSource"></param> /// <returns></returns> protected virtual bool ImportToBase(ref IWorkspace wsBase) { // 直接复制的方式 if (m_JustCopy) { return(CopyToBase(ref wsBase)); } // 导入的方式 string strWorkspace = this.m_TargetPath + "\\" + COMMONCONST.DB_Name_Base; if (!Hy.Common.Utility.Esri.AEAccessFactory.OpenFGDB(ref wsBase, strWorkspace)) { SendMessage(enumMessageType.Exception, "导入数据失败:无法打开Base库,请确认在创建任务文件结构时已创建Base库"); return(false); }// Hy.Common.Utility.Esri.AEAccessFactory.CreateFGDB(this.m_TargetPath, COMMONCONST.DB_Name_Base); IFeatureDataset fdsTarget = CreateFeatureDataset(wsBase, this.m_SpatialReference); if (fdsTarget == null) { SendMessage(enumMessageType.Exception, "“Dataset”没有创建成功,无法继续导入"); return(false); } Hy.Common.Utility.Esri.GPTool gpTool = new Hy.Common.Utility.Esri.GPTool(); // 打开数据源 IWorkspace wsSource = null; try { wsSource = AEAccessFactory.OpenWorkspace(this.m_DataType, this.m_Datasource); if (wsSource == null) { SendMessage(enumMessageType.Exception, "打开数据源出错"); return(false); } // 获取FeatureClass名列表 IEnumDataset enDataset = wsSource.get_Datasets(esriDatasetType.esriDTAny); IDataset dataset = enDataset.Next(); while (dataset != null) { switch (dataset.Type) { case esriDatasetType.esriDTTable: SendEvent(dataset.Name); Hy.Common.Utility.Esri.DataConverter.ConvertTable(wsSource, wsBase, dataset, GetObjectName(dataset.Name)); break; case esriDatasetType.esriDTFeatureClass: SendEvent(dataset.Name); gpTool.CopyFeatureClass(string.Format("{0}\\{1}", this.m_Datasource, dataset.Name + (this.m_DataType == enumDataType.SHP ? ".shp" : "")), string.Format("{0}\\{1}\\{2}", strWorkspace, fdsTarget.Name, GetObjectName(dataset.Name))); //Hy.Common.Utility.Esri.DataConverter.ConvertFeatureClass(wsSource as IDataset,fdsTarget as IDataset, dataset as IFeatureClass, GetObjectName(dataset.Name)); break; case esriDatasetType.esriDTFeatureDataset: IFeatureClassContainer fsContainer = dataset as IFeatureClassContainer; for (int i = 0; i < fsContainer.ClassCount; i++) { string strFcName = (fsContainer.get_Class(i) as IDataset).Name; SendEvent(strFcName); gpTool.CopyFeatureClass(string.Format("{0}\\{1}\\{2}", this.m_Datasource, dataset.Name, strFcName), string.Format("{0}\\{1}\\{2}", strWorkspace, fdsTarget.Name, GetObjectName(strFcName))); //Hy.Common.Utility.Esri.DataConverter.ConvertFeatureClass(dataset, fdsTarget as IDataset, fsContainer.get_Class(i), (fsContainer.get_Class(i) as IDataset).Name); } break; default: break; } dataset = enDataset.Next(); } // 释放 enDataset = null; dataset = null; // 改别名 this.RenameClassObjects(wsBase); } catch (Exception exp) { SendMessage(enumMessageType.Exception, "导入Base库出错:" + exp.ToString()); } finally { if (wsSource != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(wsSource); wsSource = null; } } return(true); }
private bool CopyToBase(ref IWorkspace wsBase) { // VCT数据不允许直接复制 if (m_DataType == enumDataType.VCT) { SendMessage(enumMessageType.Exception, "导入VCT数据不允许直接复制"); return(false); } //if (ImportingObjectChanged != null) //{ // ImportingObjectChanged("数据复制"); //} // MDB使用文件复制 if (m_DataType == enumDataType.PGDB) { try { string strDBPath = this.m_TargetPath + "\\Base.MDB"; System.IO.File.Copy(this.m_Datasource, strDBPath);//+ COMMONCONST.DB_Name_Base); if (!Hy.Common.Utility.Esri.AEAccessFactory.OpenPGDB(ref wsBase, strDBPath)) { SendMessage(enumMessageType.Exception, "导入数据(复制文件)后打开出错,请确认数据源为正确的PGDB文件"); return(false); } } catch { SendMessage(enumMessageType.Exception, "导入数据(复制文件)出错"); return(false); } } else // Shp和FileGDB使用文件夹复制 { try { string strFolderName = "Base"; if (m_DataType == enumDataType.SHP) { strFolderName = "Base"; CopyDirectory(this.m_Datasource, this.m_TargetPath, strFolderName); } else { strFolderName = COMMONCONST.DB_Name_Base; Hy.Common.Utility.Esri.GPTool gpTool = new Hy.Common.Utility.Esri.GPTool(); gpTool.Copy(this.m_Datasource, this.m_TargetPath + "\\" + strFolderName); } wsBase = AEAccessFactory.OpenWorkspace(m_DataType, this.m_TargetPath + "\\" + strFolderName); } catch { SendMessage(enumMessageType.Exception, "导入数据(复制文件夹)出错"); return(false); } } return(true); }
/// <summary> /// 使用统一入口进行质检 /// </summary> /// <param name="dsTarget">可以是IWorkspace,IFeatureClass或ITable</param> /// <returns></returns> public DataTable Check(IDataset dsTarget) { // 数据导入 string strBaseName = "Base.gdb"; string strQueryDB = "Base.mdb"; bool ready = false; enumDataType baseDataType = enumDataType.FileGDB; SendCheckingMessage("正在进行数据导入…"); try { Clear(); if (dsTarget is IWorkspace) { ready = PrepareForWorkspace(dsTarget as IWorkspace, out strBaseName, out strQueryDB, out baseDataType); } else if (dsTarget is IFeatureClass) { ready = PrepareForFeatureClass(dsTarget, out strBaseName, out strQueryDB); baseDataType = enumDataType.PGDB; } else if (dsTarget is ITable) { ready = PrepareForTable(dsTarget, out strBaseName, out strQueryDB); baseDataType = enumDataType.PGDB; } if (!ready) { } // 开始准备检查 string strBaseFullName = string.Format("{0}\\{1}", TempPath, strBaseName); string strQueryFullName = string.Format("{0}\\{1}", TempPath, strQueryDB); IWorkspace wsBase = AEAccessFactory.OpenWorkspace(baseDataType, strBaseFullName); IWorkspace wsQuery = AEAccessFactory.OpenWorkspace(enumDataType.PGDB, strQueryFullName); IDbConnection queryConnection = AdoDbHelper.GetDbConnection(strQueryFullName); // 开始执行检查 Checker curChecker = new Checker(); curChecker.VerifyingRuleChanged += new DealingRuleChangedHandler(VerifyingRuleChanged); curChecker.VerifyedComplete += new VerifyedCompleteHandler(VerifyedComplete); curChecker.PretreatingRuleChanged += new DealingRuleChangedHandler(PretreatingRuleChanged); curChecker.PretreatComplete += new CheckEventHandler(PretreatComplete); curChecker.CheckingRuleChanged += new DealingRuleChangedHandler(CheckingRuleChanged); curChecker.CheckComplete += new CheckEventHandler(CheckComplete); curChecker.RuleChecked += new RuleCheckedHandler(RuleChecked); curChecker.TopoRuleCheckBegin += new CheckEventHandler(TopoRuleCheckBegin); curChecker.BaseWorkspace = wsBase; curChecker.QueryWorkspace = wsQuery; curChecker.QueryConnection = queryConnection; curChecker.ResultPath = TempPath; // 如果没有设置SchemaID,获取第一个 // 如果没有设置RuleInfo列表,获取所有 if (string.IsNullOrEmpty(this.SchemaID)) { Dictionary <int, string> dictStandard = SysDbHelper.GetStandardInfo(); if (dictStandard == null || dictStandard.Count == 0) { return(null); } Dictionary <string, string> dictSchema = SysDbHelper.GetSchemasInfo(dictStandard.ElementAt(0).Value); if (dictSchema == null || dictSchema.Count == 0) { return(null); } this.SchemaID = dictSchema.ElementAt(0).Key; } if (this.RuleInfos == null) { TemplateRules templateRule = new TemplateRules(this.SchemaID); this.RuleInfos = templateRule.CurrentSchemaRules; } curChecker.RuleInfos = this.RuleInfos; curChecker.SchemaID = this.SchemaID; curChecker.TopoDBPath = TempPath; curChecker.TopoTolerance = this.TopoTolerence; COMMONCONST.TOPOTOLORANCE = this.TopoTolerence; COMMONCONST.dAreaThread = this.MapScale * 0.04; COMMONCONST.dLengthThread = this.MapScale * 0.2 / 10000; //SendCheckBeginEvent(curChecker); curChecker.Check(); // 检查 // 获取结果 string strResultFullName = string.Format("{0}\\{1}", TempPath, "Result.mdb"); IDbConnection resultConnection = AdoDbHelper.GetDbConnection(strResultFullName); return(GetErrors(resultConnection)); } catch { return(null); } finally { GC.Collect(); //Clear(); } }