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; } /// /// 矢量任务建库变更图斑 /// public IFeature SLFeatureCk { get; set; } /// /// 质检外业任务图斑标识码 /// public string TBBSM { get; set; } /// /// 任务包数据路径 /// public string SourcePath { get; set; } /// /// 过程数据路径 /// public string ProcessDataPath { get; set; } /// /// 是否为首轮执行 /// public bool FirstRun { get; set; } = true; /// /// 变更范围矢量集合 /// public Dictionary BGFWDic { get; set; } /// /// 人工错误(漏斗式) /// public List AllRGError { get; set; } = new List(); /// /// 要执行规则 /// public List> ExcuteRules { get; set; } /// /// 不执行规则 /// public List DisExecuteRules { get; set; } public IFeatureWorkspace Workspace { get; set; } public int Wkid { get; set; } public List LayerNames { get; set; } public List DataSetNames { get; set; } public Dictionary DicFeatureClass { get; set; } public IWorkspace sourceWorkSpace; protected List StartCheck(string sourePath, IWorkspace workSpace, List 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 StartCheck(string tbbsm, string sourePath, Dictionary dicFeatureClass, List ruleNames) { this.SourcePath = sourePath; this.DicFeatureClass = dicFeatureClass; return Check(ruleNames); } protected List StartCheck(string sourePath, Dictionary workspace, List 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 StartCheck(IWorkspace workspace, List ruleNames, List layerNames, List dataSetNames) { this.Workspace = workspace as IFeatureWorkspace; this.LayerNames = layerNames; this.DataSetNames = dataSetNames; return Check(ruleNames); } #region 获取配置文件中的质检规则 /// /// GetConfigList /// /// 规则所在对象中的类名 /// protected List GetConfigList(string className) { List liststr = new List(); try { string FilePath = System.IO.Path.Combine(SysAppPath.GetConfigPath(), "CheckRuleConfigs.xml"); XDocument pXDoc = XDocument.Load(FilePath); var sdm = SysConfigsOprator.GetAppsetingValueByKey("ArearName"); IEnumerable 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 ExcuteCheck(string sourePath, IWorkspace workspace); public abstract List ExcuteCheck(string sourePath, Dictionary dicFeatureClass); public abstract List ExcuteCheck(IWorkspace workspace, List layerNames, List dataSetNames); public abstract List ExcuteCheck(string tbbsm, string sourePath, Dictionary 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(); } /// /// 变更范围矢量化 /// private void ConvertBGFW() { BGFWDic = new Dictionary(); 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 Check(List ruleNames) { List rst = new List(); 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) { rst.AddRange(ruleEntity as List); } } } 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); } /// /// 求两个图形相交部分 /// /// 图形1 /// 图形2 /// 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; } } }