using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; namespace Kingo.RuleCheck { /// /// 图形、属性规范性检查 /// public class TXSXCheck : RuleCheckBase { List ruleMethodNames = new List() { //"TX004" "TX001","TX002","TX003","TX004","TX005","TX006","TX007","TX008","TX009","TX010","TX011","BSM001","SX001","TX012","SX002","TX021","TX022","TX023","TX024" }; private string dataSetName = "TDBZSJJ"; public override List ExcuteCheck(string sourePath, IWorkspace workspace) { return this.StartCheck(sourePath, workspace, ruleMethodNames); } public override List ExcuteCheck(string sourePath, Dictionary workspace) { return this.StartCheck(sourePath, workspace, ruleMethodNames); } public override List ExcuteCheck(IWorkspace workspace, List layerNames, List dataSetNames) { return this.StartCheck(workspace, ruleMethodNames, layerNames, dataSetNames); } public List TX001() { List result = new List(); try { result = CheckRule("DTBDLTBGX", esriTopologyRuleType.esriTRTAreaNoOverlap, "图斑重叠检查"); if (result != null && result.Count > 0) { foreach (RuleEntity item in result) { item.ErrorTip = "【DTBDLTBGX】面要素间存在缝隙"; item.CheckObject = "单图斑建库成果"; item.ErrorType = "一类错误"; item.RuleCode = "TX001"; item.RuleContent = "若同一图层内存在面与面重叠(包括完全重叠与部分重叠,容差超过0.0001米)的图斑,认定为错误图斑"; item.RuleName = "图斑重叠检查"; } } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { ErrorTip = "【DTBDLTBGX】面要素间存在缝隙", ErrorId = "规则检查失败:" + ex.Message, CheckObject = "单图斑建库成果", ErrorType = "一类错误", RuleCode = "TX001", RuleContent = "若同一图层内存在面与面重叠(包括完全重叠与部分重叠,容差超过0.0001米)的图斑,认定为错误图斑", RuleName = "图斑重叠检查", }; result.Add(ruleEntity); } return result; } public List TX002() { List result = new List(); try { result = CheckRule("DTBDLTBGX"); if (result != null && result.Count > 0) { foreach (RuleEntity item in result) { item.ErrorTip = "同一任务图斑下的单图斑成果,若为相邻相同属性图斑,应合并上图"; item.CheckObject = "DTBDLTBGX"; item.ErrorType = "一类错误"; item.RuleCode = "TX002"; item.RuleContent = "对于DTBDLTBGX层中的图斑,若其地类编码、种植属性代码、图斑细化代码、耕地类型、单独图层代码、城镇村属性码与同一任务包下相邻的其他单图斑均相同,认定为错误图斑。"; item.RuleName = "相同属性相邻图斑合并情况检查"; } } //result = CheckRule("DTBDLTBGX", esriTopologyRuleType.esriTRTAreaNoGaps, "面要素缝隙检查"); //if (result != null && result.Count > 0) //{ // //对于面图层来说,本身会有一个边界外的缝隙,这个缝隙不算错误,所以当只有一个缝隙时,表示该图层无问题 // if (result.Count == 1) // { // return null; // } // foreach (RuleEntity item in result) // { // item.ErrorTip = "【矢量图层】面要素间存在缝隙"; // item.CheckObject = "DTBDLTBGX"; // item.ErrorType = "一类错误"; // item.RuleCode = "TX002"; // item.RuleContent = "若同一面层内不同面要素之间存在缝隙,且容差超过0.0001米的情况,认定为错误图斑"; // item.RuleName = "面要素缝隙检查"; // } //} } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { ErrorTip = "同一任务图斑下的单图斑成果,若为相邻相同属性图斑,应合并上图", ErrorId = "规则检查失败:" + ex.Message, CheckObject = "DTBDLTBGX", ErrorType = "一类错误", RuleCode = "TX002", RuleContent = "对于DTBDLTBGX层中的图斑,若其地类编码、种植属性代码、图斑细化代码、耕地类型、单独图层代码、城镇村属性码与同一任务包下相邻的其他单图斑均相同,认定为错误图斑。", RuleName = "相同属性相邻图斑合并情况检查" }; result.Add(ruleEntity); } return result; } public List TX003() { List result = new List(); try { System.Data.DataTable dataTable = this.mdbHelper.ExecuteDataTable($"SELECT BSM FROM DTBDLTBGX WHERE ZC_EXTRA / (PointCount - 1) < 1 OR ZC_EXTRA / (PointCount - 1) > 70 "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = item[0].ToString(), ErrorTip = "【DTBDLTBGX】存在节点密度不符合要求图斑", ErrorType = "一类错误", RuleCode = "TX003", RuleName = "图形节点密度检查", RuleContent = "若图斑存在节点密度过于稀疏、稠密(平均节点密度<1米,或大于70米)的情况,认定为错误图斑。" }); } } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "【DTBDLTBGX】存在节点密度不符合要求图斑", ErrorType = "一类错误", RuleCode = "TX003", RuleName = "图形节点密度检查", RuleContent = "若图斑存在节点密度过于稀疏、稠密(平均节点密度<1米,或大于70米)的情况,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List TX004() { List result = new List(); try { System.Data.DataTable dataTable = this.mdbHelper.ExecuteDataTable($"SELECT BSM FROM DTBDLTBGX WHERE MJZCB_Extra <0.2 AND MinAngle_Extra<20 AND DLBM NOT IN ('1001','1002','1003','1004','1006','1009','1107','1107A','1109') "); /* * 临时修改:应对系统汇报演示 */ //dataTable = this.mdbHelper.ExecuteDataTable($"SELECT BSM FROM DTBDLTBGX WHERE MJZCB_Extra >0.2 AND MinAngle_Extra<25 AND DLBM NOT IN ('1001','1002','1006','1009','1107','1109') "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = item[0].ToString(), ErrorTip = "【DTBDLTBGX】存在碎小或狭长图斑", ErrorType = "一类错误", RuleCode = "TX004", RuleName = "碎小、狭长图斑检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1107、1107A、1109外的其余图斑,若满足面积/周长<0.2,且有一个角度小于20的条件,认定为错误图斑。" }); } } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "【矢量图层】存在碎小或狭长图斑", ErrorType = "一类错误", RuleCode = "TX004", RuleName = "碎小、狭长图斑检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1107、1107A、1109外的其余图斑,若满足面积/周长<0.2,且有一个角度小于20的条件,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List TX005() { List result = new List(); try { System.Data.DataTable dataTable = this.mdbHelper.ExecuteDataTable($"SELECT BSM FROM DTBDLTBGX WHERE Shape_Area<50 AND DLBM NOT IN ('1001','1002','1003','1004','1006','1009','1101','1107','1107A','1203') "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = item[0].ToString(), ErrorTip = "【DTBDLTBGX】存在不够上图面积的图斑", ErrorType = "一类错误", RuleCode = "TX005", RuleName = "碎面多边形检查", RuleContent = "DTBDLTBGX层中,除地类编码为1001、1002、1003、1004、1006、1009、1101、1107、1107A、1203外的其它图斑,若存在面积小于50平方米的图斑,认定为错误图斑" }); } } //dataTable = this.mdbHelper.ExecuteDataTable($"SELECT BSM FROM DTBDLTBGXGC WHERE TBBGMJ<0.1"); //if (dataTable != null && dataTable.Rows.Count > 0) //{ // foreach (DataRow item in dataTable.Rows) // { // result.Add(new RuleEntity() // { // CheckObject = "单图斑建库成果", // ErrorId = item[0].ToString(), // ErrorTip = "【DTBDLTBGX】存在不够上图面积的图斑", // ErrorType = "一类错误", // RuleCode = "TX005", // RuleName = "碎面多边形检查", // RuleContent = "单图斑地类图斑更新过程层要素若存在面积小于0.1平方米的图斑,认定为错误图斑。" // }); // } //} } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "【DTBDLTBGX】存在不够上图面积的图斑", ErrorType = "一类错误", RuleCode = "TX005", RuleName = "碎面多边形检查", RuleContent = "单图斑地类图斑更新过程层要素若存在面积小于0.1平方米的图斑,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List TX006() { List result = new List(); try { string infeaturePath = System.IO.Path.Combine(this.SourcePath, this.dataSetName, "DTBDLTBGX"); bool checkGeometry = CheckHelper.GeoprocessorHelper.CheckGeometry(infeaturePath, "DTBDLTBGX_CheckGeometry", this.SourcePath); if (!checkGeometry) { throw new Exception("图形、属性规范检查“图形自相交检查异常”"); } string qyerySQL = string.Format("SELECT FEATURE_ID,PROBLEM FROM {0}", "DTBDLTBGX_CheckGeometry"); DataTable dt = this.mdbHelper.ExecuteDataTable(qyerySQL); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow item in dt.Rows) { if (item[1].ToString() == "self intersections" || item[1].ToString() == "自相交") { RuleEntity ruleEntity = new RuleEntity(); ruleEntity.ErrorId = item[0].ToString(); ruleEntity.ErrorTip = "【DTBDLTBGX】存在自相交图斑"; ruleEntity.CheckObject = "单图斑建库成果"; ruleEntity.ErrorType = "一类错误"; ruleEntity.RuleCode = "TX006"; ruleEntity.RuleContent = "面层内要素若存在自相交图斑,认定为错误图斑"; ruleEntity.RuleName = "图形自相交检查"; result.Add(ruleEntity); } else if (item[1].ToString() == "") { } } } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { ErrorTip = "【DTBDLTBGX】存在自相交图斑", ErrorId = "规则检查失败:" + ex.Message, CheckObject = "单图斑建库成果", ErrorType = "一类错误", RuleCode = "TX006", RuleContent = "面层内要素若存在自相交图斑,认定为错误图斑", RuleName = "图形自相交检查" }; result.Add(ruleEntity); } return result; } public List TX007() { string tableName = "DTBDLTBGX"; string addFieldName = "MULTPART"; ESRI.ArcGIS.DataManagementTools.CalculateField calc = new ESRI.ArcGIS.DataManagementTools.CalculateField(); calc.field = addFieldName; calc.expression = "!shape.ismultipart!"; calc.expression_type = "PYTHON"; IFeature feature = null; IFeatureCursor featureCursor = null; int multiPartIndex = -1; IFeatureClass pFeatureClass = null; List result = new List(); try { bool isExist = (sourceWorkSpace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, tableName); if (!isExist) { return result; } pFeatureClass = (sourceWorkSpace as IFeatureWorkspace).OpenFeatureClass(tableName); //判断如果图层没有数据则跳过 if (pFeatureClass.FeatureCount(null) <= 0) { return result; } multiPartIndex = CheckHelper.GeoprocessorHelper.CreateFiled(pFeatureClass, addFieldName); calc.in_table = pFeatureClass; CheckHelper.GeoprocessorHelper.CalculateField(calc); IQueryFilter queryFilter = new QueryFilterClass() { WhereClause = addFieldName + "='TRUE'", SubFields = $"OBJECTID,BSM,{addFieldName},{pFeatureClass.ShapeFieldName}" }; featureCursor = pFeatureClass.Search(queryFilter, true); while ((feature = featureCursor.NextFeature()) != null) { //此处排除内外环的要素,判断当前要素图形是否存在多个外环 GeometryBag ExterGeometryBag = (feature.ShapeCopy as ESRI.ArcGIS.Geometry.IPolygon4).ExteriorRingBag as GeometryBag; IGeometryCollection ExterRingGeometryCollection = ExterGeometryBag as IGeometryCollection; if (ExterRingGeometryCollection.GeometryCount <= 1) { continue; } RuleEntity ruleEntity = new RuleEntity(); ruleEntity.ErrorId = feature.Value[feature.Fields.FindField("bsm")].ToString(); ruleEntity.ErrorTip = $"【{tableName}】存在组合图斑"; ruleEntity.CheckObject = "单图斑建库成果"; ruleEntity.ErrorType = "一类错误"; ruleEntity.RuleCode = "TX007"; ruleEntity.RuleContent = "面层内要素若存在组合图斑,认定为错误图斑"; ruleEntity.RuleName = "组合图斑检查"; result.Add(ruleEntity); Marshal.ReleaseComObject(feature); } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity(); ruleEntity.ErrorId = "规则检查失败:" + ex.Message; ruleEntity.ErrorTip = $"【{tableName}】存在组合图斑"; ruleEntity.CheckObject = "单图斑建库成果"; ruleEntity.ErrorType = "一类错误"; ruleEntity.RuleCode = "TX007"; ruleEntity.RuleContent = "面层内要素若存在组合图斑,认定为错误图斑"; ruleEntity.RuleName = "组合图斑检查"; result.Add(ruleEntity); } finally { if (multiPartIndex > -1) { CheckHelper.GeoprocessorHelper.DeleteField(pFeatureClass, addFieldName); } if (feature != null) { Marshal.ReleaseComObject(feature); } if (featureCursor != null) { Marshal.ReleaseComObject(featureCursor); } if (pFeatureClass != null) { Marshal.ReleaseComObject(pFeatureClass); } } return result; } public List TX008() { return null; } public List TX009() { return null; } public List TX010() { List result = new List(); try { System.Data.DataTable dataTable = this.mdbHelper.ExecuteDataTable($"SELECT BSM FROM DTBDLTBGX WHERE MinAngle_Extra<10 "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = item[0].ToString(), ErrorTip = "【DTBDLTBGX】存在尖锐角或局部狭长错误图斑", ErrorType = "一类错误", RuleCode = "TX010", RuleName = "尖锐角及局部狭长检查", RuleContent = "图层内若存在一个角度小于10度,或局部狭长的图斑,认定为错误图斑。" }); } } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "【DTBDLTBGX】存在尖锐角或局部狭长错误图斑", ErrorType = "一类错误", RuleCode = "TX010", RuleName = "尖锐角及局部狭长检查", RuleContent = "图层内若存在一个角度小于10度,或局部狭长的图斑,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List TX011() { List result = new List(); try { System.Data.DataTable dataTable = this.mdbHelper.ExecuteDataTable($"SELECT BSM FROM DTBDLTBGX WHERE 1/MJZCB_Extra>1 AND DLBM NOT IN ('1001','1002','1003','1004','1006','1009','1101','1107','1107A') "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = item[0].ToString(), ErrorTip = "【DTBDLTBGX】存在图形不规则的错误图斑", ErrorType = "一类错误", RuleCode = "TX011", RuleName = "不规则图形检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1101、1107、1107A的图斑外,图层内若存在周长/面积>1的图斑,认定为错误图斑。" }); } } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "【DTBDLTBGX】存在图形不规则的错误图斑", ErrorType = "一类错误", RuleCode = "TX011", RuleName = "不规则图形检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1101、1107、1107A的图斑外,图层内若存在周长/面积>1的图斑,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List BSM001() { List result = new List(); try { System.Data.DataTable dataTable = this.mdbHelper.ExecuteDataTable($"SELECT * FROM (SELECT BSM,COUNT(1) AS GS FROM DTBDLTBGX GROUP BY BSM) WHERE GS>1"); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = item[0].ToString(), ErrorTip = "【DTBDLTBGX】内图斑标识码不唯一", ErrorType = "一类错误", RuleCode = "BSM001", RuleName = "标识码唯一性检查", RuleContent = "图层内图斑标识码若不唯一,认定为错误图斑。" }); } } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "【DTBDLTBGX】内图斑标识码不唯一", ErrorType = "一类错误", RuleCode = "BSM001", RuleName = "标识码唯一性检查", RuleContent = "图层内图斑标识码若不唯一,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List SX001() { return null; } public List TX012() { List result = new List(); HashSet tbbsms = new HashSet(); try { //string sql = "select C.TBBSM,B.MJ,C.shape_area from WYRW c left join (SELECT TBBSM,sum(A.shape_area) as MJ FROM DTBDLTBGX A group by A.TBBSM)b on c.TBBSM=b.TBBSM WHERE B.MJ/C.shape_area<0.9"; //System.Data.DataTable dataTable = this.mdbHelper.ExecuteDataTable(sql); //if (dataTable != null && dataTable.Rows.Count > 0) //{ //foreach (DataRow item in dataTable.Rows) //{ // tbbsms.Add(item[0].ToString()); //} //} string tempMDBPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceWorkSpace.PathName), System.IO.Path.GetFileNameWithoutExtension(sourceWorkSpace.PathName) + "_Diss.mdb"); System.IO.File.Copy(sourceWorkSpace.PathName, tempMDBPath, true); var workspace = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass().OpenFromFile(tempMDBPath, 0); IDatabaseCompact databaseCompact = (IDatabaseCompact)workspace; databaseCompact.Compact(); IFeatureClass pGxFeatureClass = (workspace as IFeatureWorkspace).OpenFeatureClass("DTBDLTBGX"); IFeatureClass pWyrwFeatureClass = (workspace as IFeatureWorkspace).OpenFeatureClass("WYRW"); var temp_result = CheckHelper.GeoprocessorHelper.Erase(pWyrwFeatureClass, pGxFeatureClass, $"{tempMDBPath}//temp"); if (temp_result.FeatureCount(null) > 0) { var layer_result = CheckHelper.GeoprocessorHelper.MultipartToSinglepart(temp_result, $"{tempMDBPath}//layer_result"); var tmdbHelper = new CheckHelper.MDBHelper(tempMDBPath); tmdbHelper.connOpen(); DataTable dt = tmdbHelper.ExecuteDataTable("SELECT TBBSM from layer_result where Shape_Area>=50"); if (dt != null) { foreach (DataRow dr in dt.Rows) { tbbsms.Add(dr[0] + string.Empty); } } tmdbHelper.DisConn(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(workspace); foreach (var it in tbbsms) { result.Add(new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = it, ErrorTip = "下发任务图斑未完全响应", ErrorType = "一类错误", RuleCode = "TX012", RuleName = "单图斑待上报范围规范性检查", RuleContent = "(1)将同一任务图斑下所有单图斑成果的面积和记为A;任务图斑面积记为B;当A/B的比例小于90%时,认定为错误图斑。或(2)将任务图斑擦除同一任务图斑下所有单图斑成果,剩余部分进行打散为各个小图斑,若存在某一小图斑的面积≥50平方米,认定为错误图斑。" }); } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库成果", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "下发任务图斑未完全响应", ErrorType = "一类错误", RuleCode = "TX012", RuleName = "单图斑待上报范围规范性检查", RuleContent = "(1)将同一任务图斑下所有单图斑成果的面积和记为A;任务图斑面积记为B;当A/B的比例小于90%时,认定为错误图斑。或(2)将任务图斑擦除同一任务图斑下所有单图斑成果,剩余部分进行打散为各个小图斑,若存在某一小图斑的面积≥50平方米,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List SX002() { List result = new List(); try { string sql = "SELECT * from DTBDLTBGX where KCDLBM not in ('','1203','1207')"; System.Data.DataTable dataTable = this.mdbHelper.ExecuteDataTable(sql); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "DTBDLTBGX层", ErrorId = item[0].ToString(), ErrorTip = "扣除地类编码只能为1203、1207或空。", ErrorType = "一类错误", RuleCode = "SX002", RuleName = "扣除地类编码规范性检查", RuleContent = "当扣除地类编码值域须为1203、1207、空,其中之一,若不是,认定为错误图斑。" }); } } } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "DTBDLTBGX层", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "扣除地类编码只能为1203、1207或空。", ErrorType = "一类错误", RuleCode = "SX002", RuleName = "扣除地类编码规范性检查", RuleContent = "当扣除地类编码值域须为1203、1207、空,其中之一,若不是,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List TX021() { List result = new List(); if (!FirstRun) return result; try { CheckHelper.MDBHelper tMdbHelper = new CheckHelper.MDBHelper(ProcessDataPath); tMdbHelper.connOpen(); System.Data.DataTable dataTable = tMdbHelper.ExecuteDataTable($"SELECT objectid FROM N WHERE MJZCB_Extra <0.2 AND MinAngle_Extra<20 AND DLBM NOT IN ('1001','1002','1003','1004','1006','1009','1107','1107A','1109') "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库N图层", ErrorId = item[0].ToString(), ErrorTip = "被动变化图斑存在碎小或狭长图斑", ErrorType = "一类错误", RuleCode = "TX021", RuleName = "碎小、狭长图斑检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1107、1107A、1109外的其余图斑,若满足面积/周长<0.2,且有一个角度小于20的条件,认定为错误图斑。" }); } } tMdbHelper.DisConn(); } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库N图层", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "被动变化图斑存在碎小或狭长图斑", ErrorType = "一类错误", RuleCode = "TX021", RuleName = "碎小、狭长图斑检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1107、1107A、1109外的其余图斑,若满足面积/周长<0.2,且有一个角度小于20的条件,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List TX022() { List result = new List(); if (!FirstRun) return result; try { CheckHelper.MDBHelper tMdbHelper = new CheckHelper.MDBHelper(ProcessDataPath); tMdbHelper.connOpen(); System.Data.DataTable dataTable = tMdbHelper.ExecuteDataTable($"SELECT objectid FROM N WHERE Shape_Area<50 AND DLBM NOT IN ('1001','1002','1003','1004','1006','1009','1101','1107','1107A','1203') "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库N图层", ErrorId = item[0].ToString(), ErrorTip = "被动变化图斑存在不够上图面积的图斑", ErrorType = "一类错误", RuleCode = "TX022", RuleName = "碎面多边形检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1101、1107、1107A、1203外的其它图斑,若存在面积小于50平方米的图斑,认定为错误图斑" }); } } tMdbHelper.DisConn(); } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库N图层", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "被动变化图斑存在不够上图面积的图斑", ErrorType = "一类错误", RuleCode = "TX022", RuleName = "碎面多边形检查", RuleContent = "单图斑地类图斑更新过程层要素若存在面积小于0.1平方米的图斑,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List TX023() { List result = new List(); if (!FirstRun) return result; try { CheckHelper.MDBHelper tMdbHelper = new CheckHelper.MDBHelper(ProcessDataPath); tMdbHelper.connOpen(); System.Data.DataTable dataTable = tMdbHelper.ExecuteDataTable($"SELECT objectid FROM N WHERE MinAngle_Extra<10 "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库N图层", ErrorId = item[0].ToString(), ErrorTip = "被动变化图斑存在尖锐角或局部狭长错误图斑", ErrorType = "一类错误", RuleCode = "TX023", RuleName = "尖锐角及局部狭长检查", RuleContent = "图层内若存在一个角度小于10度,或局部狭长的图斑,认定为错误图斑。" }); } } tMdbHelper.DisConn(); } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库N图层", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "被动变化图斑存在尖锐角或局部狭长错误图斑", ErrorType = "一类错误", RuleCode = "TX023", RuleName = "尖锐角及局部狭长检查", RuleContent = "图层内若存在一个角度小于10度,或局部狭长的图斑,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } public List TX024() { List result = new List(); if (!FirstRun) return result; try { CheckHelper.MDBHelper tMdbHelper = new CheckHelper.MDBHelper(ProcessDataPath); tMdbHelper.connOpen(); System.Data.DataTable dataTable = tMdbHelper.ExecuteDataTable($"SELECT objectid FROM N WHERE 1/MJZCB_Extra>1 AND DLBM NOT IN ('1001','1002','1003','1004','1006','1009','1101','1107','1107A') "); if (dataTable != null && dataTable.Rows.Count > 0) { foreach (DataRow item in dataTable.Rows) { result.Add(new RuleEntity() { CheckObject = "单图斑建库N图层", ErrorId = item[0].ToString(), ErrorTip = "被动变化图斑存在图形不规则的错误图斑", ErrorType = "一类错误", RuleCode = "TX024", RuleName = "不规则图形检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1101、1107、1107A的图斑外,图层内若存在周长/面积>1的图斑,认定为错误图斑。" }); } } tMdbHelper.DisConn(); } catch (Exception ex) { RuleEntity ruleEntity = new RuleEntity() { CheckObject = "单图斑建库N图层", ErrorId = "规则检查失败:" + ex.Message, ErrorTip = "被动变化图斑存在图形不规则的错误图斑", ErrorType = "一类错误", RuleCode = "TX024", RuleName = "不规则图形检查", RuleContent = "除地类编码为1001、1002、1003、1004、1006、1009、1101、1107、1107A的图斑外,图层内若存在周长/面积>1的图斑,认定为错误图斑。" }; result.Add(ruleEntity); } return result; } private List CheckRule(string tableName, esriTopologyRuleType topologyRuleType, string topologyRuleName) { IWorkspace workspace = null; IWorkspaceFactory2 wsFactory = null; List result = new List(); try { if (sourceWorkSpace == null || string.IsNullOrWhiteSpace(sourceWorkSpace.PathName) || !System.IO.File.Exists(sourceWorkSpace.PathName)) { return result; } string topoMDBPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceWorkSpace.PathName), System.IO.Path.GetFileNameWithoutExtension(sourceWorkSpace.PathName) + "_Topo.mdb"); System.IO.File.Copy(sourceWorkSpace.PathName, topoMDBPath, true); wsFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass(); workspace = wsFactory.OpenFromFile(topoMDBPath, 0); //判断图层是否存在 bool isExist = (workspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, tableName); if (!isExist) { return null; } IDatabaseCompact databaseCompact = (IDatabaseCompact)workspace; databaseCompact.Compact(); IFeatureClass pFeatureClass = (workspace as IFeatureWorkspace).OpenFeatureClass(tableName); //判断如果图层没有数据则跳过 if (pFeatureClass.FeatureCount(null) <= 0) { return null; } // 创建拓扑规则 ITopologyRule topologyRule = new TopologyRuleClass(); topologyRule.TopologyRuleType = topologyRuleType;//面要素之间无空隙 topologyRule.Name = topologyRuleName;//"MustNoIntersection"; topologyRule.OriginClassID = pFeatureClass.FeatureClassID; topologyRule.AllOriginSubtypes = true; result = CheckHelper.DataCheckTopologyHelper.CreateTopology(new List { topologyRule }, workspace, new List() { tableName }, this.dataSetName); } catch (Exception ex) { throw ex; } finally { if (workspace != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(workspace); } if (wsFactory != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(wsFactory); } } return result; } private List CheckRule(string tableName) { IWorkspace workspace = null; IWorkspaceFactory2 wsFactory = null; List result = new List(); try { if (sourceWorkSpace == null || string.IsNullOrWhiteSpace(sourceWorkSpace.PathName) || !System.IO.File.Exists(sourceWorkSpace.PathName)) { return result; } string topoMDBPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sourceWorkSpace.PathName), System.IO.Path.GetFileNameWithoutExtension(sourceWorkSpace.PathName) + "_Diss.mdb"); System.IO.File.Copy(sourceWorkSpace.PathName, topoMDBPath, true); wsFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass(); workspace = wsFactory.OpenFromFile(topoMDBPath, 0); //判断图层是否存在 bool isExist = (workspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, tableName); if (!isExist) { return null; } IDatabaseCompact databaseCompact = (IDatabaseCompact)workspace; databaseCompact.Compact(); IFeatureClass pFeatureClass = (workspace as IFeatureWorkspace).OpenFeatureClass(tableName); //判断如果图层没有数据则跳过 if (pFeatureClass.FeatureCount(null) <= 0) { return null; } CheckHelper.GeoprocessorHelper.PolygonNeighbors(pFeatureClass, $"{topoMDBPath}//result", "BSM;DLBM;TBXHDM;ZZSXDM;GDLX;DDTCBZ;CZCSXM"); var tmdbHelper = new CheckHelper.MDBHelper(topoMDBPath); tmdbHelper.connOpen(); DataTable dt = tmdbHelper.ExecuteDataTable("SELECT src_BSM from result where LENGTH >0 AND src_DLBM = nbr_DLBM AND src_TBXHDM = nbr_TBXHDM AND src_ZZSXDM = nbr_ZZSXDM AND src_GDLX = nbr_GDLX AND src_DDTCBZ = nbr_DDTCBZ AND src_CZCSXM = nbr_CZCSXM"); if (dt != null) { foreach (DataRow dr in dt.Rows) { RuleEntity ruleEntity = new RuleEntity(); ruleEntity.ErrorId = dr[0] + string.Empty; result.Add(ruleEntity); } } tmdbHelper.DisConn(); } catch (Exception ex) { throw ex; } finally { if (workspace != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(workspace); } if (wsFactory != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(wsFactory); } } return result; } } }