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

171 lines
7.8 KiB

6 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ESRI.ArcGIS.Geodatabase;
namespace Kingo.RuleCheck
{
class YCLOverlapCheck : RuleCheckBase
{
List<string> ruleMethodNames = new List<string>() { "YCLCheck" };
public override List<RuleEntity> ExcuteCheck(string sourePath, IWorkspace workspace)
{
return null;
}
public override List<RuleEntity> ExcuteCheck(string sourePath, Dictionary<string, IWorkspace> workspace)
{
return null;
}
public override List<RuleEntity> ExcuteCheck(IWorkspace workspace, List<string> layerNames, List<string> dataSetNames)
{
return null;
}
/// <summary>
/// 预处理重叠检查
/// </summary>
/// <returns></returns>
public static List<RuleEntity> YCLCheck(string dbPath)
{
//IWorkspace workspace = null;
//IWorkspaceFactory2 wsFactory = null;
//IFeatureClass featureClass = null;
List<RuleEntity> rstList = null;
//CheckHelper.MDBHelper mDBHelper = null;
ESRI.ArcGIS.Geometry.IGeometry geometry1 = null;
ESRI.ArcGIS.Geometry.IGeometry geometry2 = null;
try
{
rstList = new List<RuleEntity>();
//wsFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();
//workspace = wsFactory.OpenFromFile(mdbPath, 0);
////判断图层是否存在
//bool isExist = (workspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, "WYRW");
//if (!isExist)
//{
// return null;
//}
//featureClass = (workspace as IFeatureWorkspace).OpenFeatureClass("WYRW");
//// 创建拓扑规则
//List<ITopologyRule> lstRule = new List<ITopologyRule>();
//ITopologyRule topologyRule = new TopologyRuleClass();
//topologyRule.TopologyRuleType = esriTopologyRuleType.esriTRTAreaNoOverlap;//面要素间无重叠
//topologyRule.Name = "esriTRTAreaNoOverlap";//面要素间无重叠
//topologyRule.OriginClassID = featureClass.FeatureClassID;
//topologyRule.AllOriginSubtypes = true;
//topologyRule.OriginSubtype = 1;
//lstRule.Add(topologyRule);
//rstList = CheckHelper.DataCheckTopologyHelper.CreateTopology(lstRule, workspace, new List<string>() { "WYRW" });
//if (rstList != null && rstList.Count > 0)
//{
// foreach (var item in rstList)
// {
// item.CheckObject = "数据库WYRW图层";
// item.ErrorTip = "外业任务图斑存在重叠";
// item.ErrorType = "一类错误";
// item.RuleCode = "YCLOverlap";
// item.RuleName = "外业任务图斑重叠检查";
// item.RuleContent = @"外业任务图斑图层所有图斑不能相互重叠。";
// }
//}
//mDBHelper = new CheckHelper.MDBHelper(mdbPath);
System.Data.DataTable dataTable = CheckHelper.SQLiteDBOperate.Instance.ExceDataTable(dbPath, "SELECT * from wyrw where XZQDM IS NULL OR XZQDM='' OR XZDM IS NULL OR XZDM='' OR CJDM IS NULL OR CJDM=''");
if (dataTable != null && dataTable.Rows.Count > 0)
{
foreach (System.Data.DataRow item in dataTable.Rows)
{
string tbbsm = item["TBBSM"] as string;
if (rstList.FirstOrDefault(x => x.ErrorId.Equals(tbbsm)) != null)
{
continue;
}
RuleEntity ruleEntity = new RuleEntity()
{
ErrorId = tbbsm,
CheckObject = "数据库WYRW图层",
ErrorTip = "外业任务图斑行政区代码、乡镇代码或村级代码为空",
ErrorType = "一类错误",
RuleCode = "YCLSX",
RuleName = "外业任务图斑行政区代码为空",
RuleContent = @"外业任务图斑图层所有图斑行政区代码、乡镇代码和村级代码不能为空。"
};
rstList.Add(ruleEntity);
}
}
dataTable = CheckHelper.SQLiteDBOperate.Instance.ExceDataTable(dbPath, "SELECT TBBSM,egeometry from wyrw");
if (dataTable != null && dataTable.Rows.Count > 0)
{
for (int i = 0; i < dataTable.Rows.Count; i++)
{
geometry1 = CheckHelper.GeometryConvertHelper.ConverJsonToIGeoemtry(dataTable.Rows[i][1].ToString());
for (int j = i + 1; j < dataTable.Rows.Count; j++)
{
geometry2 = CheckHelper.GeometryConvertHelper.ConverJsonToIGeoemtry(dataTable.Rows[j][1].ToString());
if (CheckHelper.CommonHelper.IsInterSect(geometry1, geometry2))
{
RuleEntity ruleEntity = new RuleEntity()
{
ErrorId = dataTable.Rows[i][0].ToString(),
CheckObject = "数据库WYRW图层",
ErrorTip = "外业任务图斑存在重叠",
ErrorType = "一类错误",
RuleCode = "YCLOverlap",
RuleName = "外业任务图斑重叠检查",
RuleContent = @"外业任务图斑图层所有图斑不能相互重叠。"
};
rstList.Add(ruleEntity);
}
if (geometry2 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(geometry2);
}
}
if (geometry1 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(geometry1);
geometry1 = null;
}
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (geometry1 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(geometry1);
}
if (geometry2 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(geometry2);
}
//if (mDBHelper != null)
//{
// mDBHelper.DisConn();
//}
//if (featureClass != null)
//{
// System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
//}
//if (workspace != null)
//{
// System.Runtime.InteropServices.Marshal.ReleaseComObject(workspace);
//}
//if (wsFactory != null)
//{
// System.Runtime.InteropServices.Marshal.ReleaseComObject(wsFactory);
//}
}
return rstList;
}
}
}