年度变更建库软件5.0版本
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.

302 lines
11 KiB

6 months ago
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using Kingo.RuleCheck.CheckHelper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
namespace Kingo.RuleCheck.XJRuleCheck
{
public abstract class RuleCheckBase_DTB
{
public CheckHelper.MDBHelper mdbHelper { get; set; }
/// <summary>
/// 矢量任务建库变更图斑
/// </summary>
public IFeature SLFeatureCk { get; set; }
/// <summary>
/// 质检外业任务图斑标识码
/// </summary>
public string TBBSM { get; set; }
/// <summary>
/// 任务包数据路径
/// </summary>
public string SourcePath { get; set; }
/// <summary>
/// 过程数据路径
/// </summary>
public string ProcessDataPath { get; set; }
/// <summary>
/// 是否为首轮执行
/// </summary>
public bool FirstRun { get; set; } = true;
/// <summary>
/// 变更范围矢量集合
/// </summary>
public Dictionary<string, BGFWEntity> BGFWDic { get; set; }
/// <summary>
/// 人工错误(漏斗式)
/// </summary>
public List<RuleEntity> AllRGError { get; set; } = new List<RuleEntity>();
/// <summary>
/// 要执行规则
/// </summary>
public List<Tuple<string>> ExcuteRules { get; set; }
/// <summary>
/// 不执行规则
/// </summary>
public List<string> DisExecuteRules { get; set; }
public IFeatureWorkspace Workspace { get; set; }
public int Wkid { get; set; }
public List<string> LayerNames { get; set; }
public List<string> DataSetNames { get; set; }
public Dictionary<string, IFeatureClass> DicFeatureClass { get; set; }
public IWorkspace sourceWorkSpace;
protected List<RuleEntity> StartCheck(string sourePath, IWorkspace workSpace, List<string> ruleNames)
{
this.SourcePath = sourePath;
this.Workspace = workSpace as IFeatureWorkspace;
this.OpenConnection(sourePath);
DataTable dtMetadata = mdbHelper.ExecuteDataTable("select * from WJMetadata");
if (dtMetadata != null && dtMetadata.Rows.Count > 0)
{
this.Wkid = Convert.ToInt32(dtMetadata.Rows[0]["WKID"]);
}
ConvertBGFW();
return Check(ruleNames);
}
protected List<RuleEntity> StartCheck(string tbbsm, string sourePath, Dictionary<string, IFeatureClass> dicFeatureClass, List<string> ruleNames)
{
this.SourcePath = sourePath;
this.DicFeatureClass = dicFeatureClass;
return Check(ruleNames);
}
protected List<RuleEntity> StartCheck(string sourePath, Dictionary<string, IFeatureClass> workspace, List<string> ruleNames)
{
this.sourceWorkSpace = OpenWorkspace(sourePath);
this.Workspace = this.sourceWorkSpace as IFeatureWorkspace;
this.SourcePath = sourePath;
this.DicFeatureClass = workspace;
this.OpenConnection(sourePath);
return Check(ruleNames);
}
protected List<RuleEntity> StartCheck(IWorkspace workspace, List<string> ruleNames, List<string> layerNames, List<string> dataSetNames)
{
this.Workspace = workspace as IFeatureWorkspace;
this.LayerNames = layerNames;
this.DataSetNames = dataSetNames;
return Check(ruleNames);
}
#region 获取配置文件中的质检规则
/// <summary>
/// GetConfigList
/// </summary>
/// <param name="className">规则所在对象中的类名</param>
/// <returns></returns>
protected List<string> GetConfigList(string className)
{
List<string> liststr = new List<string>();
try
{
string FilePath = System.IO.Path.Combine(SysAppPath.GetConfigPath(), "CheckRuleConfigs.xml");
XDocument pXDoc = XDocument.Load(FilePath);
var sdm = SysConfigsOprator.GetAppsetingValueByKey("ArearName");
IEnumerable<XElement> elements = pXDoc.Element("CheckRules").Elements().Where(x => x.Attribute("Name").Value.ToTrim().Contains(sdm));
var elements1 = elements.FirstOrDefault().Elements();
foreach (var item in elements1)
{
if (item.Attribute("IsCheck").Value == "True" && item.Attribute("ClassName").Value == className)
liststr.Add(item.Attribute("RuleCode").Value);
}
}
catch (Exception ex)
{
LogAPI.Debug("GetConfigList异常:" + ex.Message);
LogAPI.Debug("GetConfigList异常:" + ex.StackTrace);
}
return liststr;
}
#endregion
public abstract List<RuleEntity> ExcuteCheck(string sourePath, IWorkspace workspace);
public abstract List<RuleEntity> ExcuteCheck(string sourePath, Dictionary<string, IFeatureClass> dicFeatureClass);
public abstract List<RuleEntity> ExcuteCheck(IWorkspace workspace, List<string> layerNames, List<string> dataSetNames);
public abstract List<RuleEntity> ExcuteCheck(string tbbsm, string sourePath, Dictionary<string, IFeatureClass> dicFeatureClass);
private void OpenConnection(string connectionString)
{
//this.connection = connection = new SQLiteConnection("Data Source=" + connectionString);
//this.connection.Open();
this.mdbHelper = new CheckHelper.MDBHelper(connectionString);
this.mdbHelper.connOpen();
}
/// <summary>
/// 变更范围矢量化
/// </summary>
private void ConvertBGFW()
{
BGFWDic = new Dictionary<string, BGFWEntity>();
string sql = "select * from bgfw";
DataTable dt = mdbHelper.ExecuteDataTable(sql);
if (dt == null || dt.Rows.Count <= 0)
{
return;
}
foreach (DataRow item in dt.Rows)
{
string bsm = item["bsm"].ToString();
IGeometry geometry = GeometryConvertHelper.ConvertWKTToIGeometry(item["geometry"].ToString());
if (BGFWDic.ContainsKey(bsm))
{
BGFWDic[bsm].Shape = geometry;
}
else
{
BGFWDic.Add(bsm, new BGFWEntity() { BSM = bsm, Shape = geometry });
}
}
}
private void DisposeConnect()
{
if (this.mdbHelper != null)
{
this.mdbHelper.DisConn();
}
}
private List<RuleEntity> Check(List<String> ruleNames)
{
List<RuleEntity> rst = new List<RuleEntity>();
try
{
foreach (var item in ruleNames)
{
if (ExcuteRules != null && ExcuteRules.Count > 0 && ExcuteRules.FirstOrDefault(x => x.Item1.Equals(item)) == null)
continue;
if (DisExecuteRules != null && DisExecuteRules.Contains(item))
continue;
MethodInfo method = this.GetType().GetMethod(item);
if (method != null)
{
//DateTime dt = DateTime.Now;
object ruleEntity = method.Invoke(this, null);
//Console.WriteLine($"{item}执行时间:{(DateTime.Now - dt).TotalSeconds}");
if (ruleEntity != null)
{
if (ruleEntity is RuleEntity)
{
rst.Add(ruleEntity as RuleEntity);
}
else if (ruleEntity is List<RuleEntity>)
{
rst.AddRange(ruleEntity as List<RuleEntity>);
}
}
}
else
{
}
}
return rst;
}
catch (Exception ex)
{
throw ex;
}
finally
{
this.DisposeConnect();
}
}
private IWorkspace OpenWorkspace(string sourcePath)
{
AccessWorkspaceFactoryClass factoryClass = new AccessWorkspaceFactoryClass();
IPropertySet result = new PropertySetClass();
result.SetProperty("DATABASE", sourcePath);
return factoryClass.Open(result, 0);
}
/// <summary>
/// 求两个图形相交部分
/// </summary>
/// <param name="pGeo1">图形1</param>
/// <param name="pGeo2">图形2</param>
/// <returns></returns>
public IGeometry InterSect(IGeometry pGeo1, IGeometry pGeo2)
{
try
{
IGeometry result = null;
if (pGeo1 == null || pGeo2 == null)
return null;
ITopologicalOperator topo = pGeo1 as ITopologicalOperator;
if (topo != null)
{
topo.Simplify();
ITopologicalOperator topo2 = pGeo2 as ITopologicalOperator;
topo2.Simplify();
if (pGeo1.GeometryType == esriGeometryType.esriGeometryPoint || pGeo2.GeometryType == esriGeometryType.esriGeometryPoint)
{
result = topo.Intersect(pGeo2, esriGeometryDimension.esriGeometry0Dimension);
}
else if (pGeo1.GeometryType == esriGeometryType.esriGeometryPolyline || pGeo2.GeometryType == esriGeometryType.esriGeometryPolyline)
{
result = topo.Intersect(pGeo2, esriGeometryDimension.esriGeometry1Dimension);
}
else
{
result = topo.Intersect(pGeo2, pGeo2.Dimension);
}
if (result != null)
{
ITopologicalOperator resultTopo = result as ITopologicalOperator;
resultTopo.Simplify();
}
return result;
}
return null;
}
catch (Exception ex)
{
throw ex;
}
}
}
public class BGFWEntity
{
public string BSM { get; set; }
public IGeometry Shape { get; set; }
}
}