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 ruleMethodNames = new List() { "YCLCheck" }; public override List ExcuteCheck(string sourePath, IWorkspace workspace) { return null; } public override List ExcuteCheck(string sourePath, Dictionary workspace) { return null; } public override List ExcuteCheck(IWorkspace workspace, List layerNames, List dataSetNames) { return null; } /// /// 预处理重叠检查 /// /// public static List YCLCheck(string dbPath) { //IWorkspace workspace = null; //IWorkspaceFactory2 wsFactory = null; //IFeatureClass featureClass = null; List rstList = null; //CheckHelper.MDBHelper mDBHelper = null; ESRI.ArcGIS.Geometry.IGeometry geometry1 = null; ESRI.ArcGIS.Geometry.IGeometry geometry2 = null; try { rstList = new List(); //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 lstRule = new List(); //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() { "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; } } }