using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.AE;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kingo.RuleCheck.XJRuleCheck
{
///
/// 公共质检类-仅次于PluginServiceInterface 动态库外不外向引用
///
public class RuleCheckOpertion_DTB
{
///
/// 县级单图斑建库和审核任务包检查
///
///
///
///
/// 系统设置-需执行规则
///
public static List StartXJSHCheck(string tbbsm, string dbPath, List lstBasicDataInfo, string primityKey = "", List> excuteRules = null)
{
List lstWorkapaceAPI = null;
Dictionary dicFeatureClass = null;
try
{
if (!System.IO.File.Exists(dbPath) || lstBasicDataInfo == null || lstBasicDataInfo.Count <= 0)
{
throw new Exception("输入参数错误");
}
List result = new List();
List ruleTypes = new List()
{
RuleType.地类属性与举证照片逻辑性检查,
RuleType.数学基础规范性检查,
RuleType.图形属性规范性检查,
RuleType.通用类表内逻辑性检查,
RuleType.通用类表间逻辑性检查,
RuleType.城镇村属性上图检查
};
DLParams.Init();
dicFeatureClass = new Dictionary();
lstWorkapaceAPI = new List();
foreach (var basicData in lstBasicDataInfo)
{
IWorkspaceAPI workspaceAPI = null;
if (basicData.WorkspaceType == WorkspaceTypeEnum.GDBFile)
workspaceAPI = new WorkspaceAPI(basicData.WorkspacePath, basicData.WorkspaceType, true);
else
workspaceAPI = new WorkspaceAPI(basicData.WorkspacePath, basicData.WorkspaceType);
foreach (var item in basicData.FeatureClassName)
{
dicFeatureClass.Add(item.Key, workspaceAPI.OpenFeatureClass(item.Value).FeatureClass);
}
lstWorkapaceAPI.Add(workspaceAPI);
}
foreach (var item in ruleTypes)
{
List rules = StartCheck(tbbsm, dbPath, dicFeatureClass, item, excuteRules, new List { "JZ005", "JZ007" });
if (rules != null && rules.Count > 0)
{
result.AddRange(rules);
}
}
return result;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (dicFeatureClass != null)
{
foreach (var item in dicFeatureClass)
{
if (item.Value != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(item.Value);
}
}
}
if (lstWorkapaceAPI != null)
{
foreach (var item in lstWorkapaceAPI)
{
item.CloseWorkspace();
}
}
}
}
///
/// 县级单图斑建库和审核任务包检查
///
///
///
///
///
///
///
public static List StartXJSHCheck(string tbbsm, string dbPath, Dictionary dicFeatureClass, List> excuteRules = null, List disExecuteRules = null)
{
try
{
List result = new List();
List ruleTypes = new List()
{
RuleType.地类属性与举证照片逻辑性检查,
RuleType.数学基础规范性检查,
RuleType.图形属性规范性检查,
RuleType.通用类表内逻辑性检查,
RuleType.通用类表间逻辑性检查,
};
DLParams.Init();
foreach (var item in ruleTypes)
{
List rules = StartCheck(tbbsm, dbPath, dicFeatureClass, item, excuteRules, disExecuteRules);
if (rules != null && rules.Count > 0)
{
result.AddRange(rules);
}
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 县级单图斑建库矢量数据检查(注:陕西)
///
///
///
///
public static List StartXJSHCheck(IFeature featureCk, List lstBasicDataInfo = null)
{
List lstWorkapaceAPI = null;
try
{
if (featureCk == null)
{
throw new Exception("输入参数错误");
}
List result = new List();
List ruleTypes = new List()
{
RuleType.矢量图形属性规范性检查
};
DLParams.Init();//公共当前地类集合
foreach (var ruleValue in ruleTypes)
{
List rules = StartCheck(featureCk, ((IDataset)featureCk.Class).Workspace, ruleValue);
if (rules != null && rules.Count > 0)
{
result.AddRange(rules);
}
}
int JCZTIndex = featureCk.Class.FindField("JCZT");
if (JCZTIndex != -1 && result != null)
{
featureCk.Value[JCZTIndex] = result.Count > 0 ? "质检错误" : "已完成";
featureCk.Store();
}
return result;
}
catch (Exception ex)
{
LogAPI.Debug("县级单图斑建库矢量数据检查(注:陕西)异常:" + ex);
throw ex;
}
finally
{
if (lstWorkapaceAPI != null)
{
foreach (var item in lstWorkapaceAPI)
{
item.CloseWorkspace();
}
}
}
}
///
/// 县级建库矢量数据检查(注:国家质检结果检查)
///
///
/// 要执行的质检规则
///
public static List StartGJZJJGCheck(IFeature featureCk, List> excuteRules = null)
{
List lstWorkapaceAPI = null;
try
{
if (featureCk == null || excuteRules == null)
{
throw new Exception("输入参数错误");
}
List result = new List();
List ruleTypes = new List()
{
RuleType.建库图斑图形规范性检查
};
DLParams.Init();//公共当前地类集合
foreach (var ruleValue in ruleTypes)
{
List rules = StartCheck(featureCk, ((IDataset)featureCk.Class).Workspace, ruleValue, excuteRules);
if (rules != null && rules.Count > 0)
{
result.AddRange(rules);
}
}
return result;
}
catch (Exception ex)
{
LogAPI.Debug("县级建库矢量数据检查(注:国家质检结果检查)异常:" + ex);
throw ex;
}
finally
{
if (lstWorkapaceAPI != null)
{
foreach (var item in lstWorkapaceAPI)
{
item.CloseWorkspace();
}
}
}
}
///
/// 县级单图斑建库和审核任务包检查(县级审核加载任务包时仅做二类错误检查)
///
///
///
///
/// 系统设置-需执行规则
///
public static List StartXJSHCheckTypeTwoErrors(string tbbsm, string dbPath, List lstBasicDataInfo, string primityKey = "", List> excuteRules = null)
{
List lstWorkapaceAPI = null;
Dictionary dicFeatureClass = null;
try
{
if (!System.IO.File.Exists(dbPath) || lstBasicDataInfo == null || lstBasicDataInfo.Count <= 0)
{
throw new Exception("输入参数错误");
}
excuteRules = new List>
{
new Tuple("LNGD"),
new Tuple("HFSX"),
new Tuple("DDTC20X"),
new Tuple("TX002"),
new Tuple("TXSXJC"),
new Tuple("TX02X"),
};
List result = new List();
List ruleTypes = new List()
{
RuleType.地类属性与举证照片逻辑性检查,
RuleType.数学基础规范性检查,
RuleType.图形属性规范性检查,
RuleType.通用类表内逻辑性检查,
RuleType.通用类表间逻辑性检查,
};
DLParams.Init();
dicFeatureClass = new Dictionary();
lstWorkapaceAPI = new List();
foreach (var basicData in lstBasicDataInfo)
{
IWorkspaceAPI workspaceAPI = new WorkspaceAPI(basicData.WorkspacePath, basicData.WorkspaceType);
foreach (var item in basicData.FeatureClassName)
{
dicFeatureClass.Add(item.Key, workspaceAPI.OpenFeatureClass(item.Value).FeatureClass);
}
lstWorkapaceAPI.Add(workspaceAPI);
}
foreach (var item in ruleTypes)
{
List rules = StartCheck(tbbsm, dbPath, dicFeatureClass, item, excuteRules, new List { "JZ005", "JZ007" });
if (rules != null && rules.Count > 0)
{
result.AddRange(rules);
}
}
return result;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (dicFeatureClass != null)
{
foreach (var item in dicFeatureClass)
{
if (item.Value != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(item.Value);
}
}
}
if (lstWorkapaceAPI != null)
{
foreach (var item in lstWorkapaceAPI)
{
item.CloseWorkspace();
}
}
}
}
///
/// 开始检查
///
///
///
///
/// 系统设置-需执行规则
/// 不执行规则
///
public static List StartCheck(string tbbsm, string sourcePath, Dictionary dicFeatureClass, RuleType ruleType, List> excuteRules = null, List disExecuteRules = null)
{
List checkRst = new List();
RuleCheckBase_DTB ruleCheck = null;
switch (ruleType)
{
case RuleType.地类属性与举证照片逻辑性检查:
ruleCheck = new DLSXYJZZPCheck_DTB();
break;
case RuleType.数学基础规范性检查:
ruleCheck = new SJJCCheck_DTB();
break;
case RuleType.图形属性规范性检查:
ruleCheck = new TXSXCheck_DTB();
break;
case RuleType.通用类表内逻辑性检查:
ruleCheck = new TYLBBNLJXCheck_DTB();
break;
case RuleType.通用类表间逻辑性检查:
ruleCheck = new TYLBJLJXCheck_DTB();
break;
case RuleType.城镇村属性上图检查:
ruleCheck = new CZCSXCheck_DTB();
break;
}
if (ruleCheck != null)
{
ruleCheck.TBBSM = tbbsm;
ruleCheck.ExcuteRules = excuteRules;
ruleCheck.DisExecuteRules = disExecuteRules;
checkRst = ruleCheck.ExcuteCheck(tbbsm, sourcePath, dicFeatureClass);
if (ruleType == RuleType.单图斑建库人工检查)
checkRst = ruleCheck.AllRGError;
}
return checkRst;
}
///
/// 开始检查-建库图斑/陕西矢量
///
///
///
///
///
///
public static List StartCheck(IFeature featureCk, IWorkspace workspace, RuleType ruleType, List> excuteRules = null)
{
List checkRst = new List();
RuleCheckBase_DTB ruleCheck = null;
switch (ruleType)
{
case RuleType.建库图斑图形规范性检查:
ruleCheck = new TBTXCheck_JK();
break;
case RuleType.矢量图形属性规范性检查:
ruleCheck = new SLSJDataCheck_DTB();
break;
}
if (ruleCheck != null)
{
ruleCheck.SLFeatureCk = featureCk;
ruleCheck.Workspace = workspace as IFeatureWorkspace;//对应的矢量图层
ruleCheck.ExcuteRules = excuteRules;//执行的质检规则
checkRst = ruleCheck.ExcuteCheck(workspace, null, null);
}
return checkRst;
}
}
}