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

252 lines
8.5 KiB

using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using Kingo.RuleCheck.CheckHelper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Kingo.RuleCheck
{
public abstract class RuleCheckBase
{
public CheckHelper.MDBHelper mdbHelper { get; set; }
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, IWorkspace> WorkspaceDic { 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 sourePath, Dictionary<string, IWorkspace> workspace, List<string> ruleNames)
{
this.sourceWorkSpace = OpenWorkspace(sourePath);
this.Workspace = this.sourceWorkSpace as IFeatureWorkspace;
this.SourcePath = sourePath;
this.WorkspaceDic = 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);
}
public abstract List<RuleEntity> ExcuteCheck(string sourePath, IWorkspace workspace);
public abstract List<RuleEntity> ExcuteCheck(string sourePath, Dictionary<string, IWorkspace> workspace);
public abstract List<RuleEntity> ExcuteCheck(IWorkspace workspace, List<string> layerNames, List<string> dataSetNames);
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)
{
object ruleEntity = method.Invoke(this, null);
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; }
}
}