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.
208 lines
10 KiB
208 lines
10 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.esriSystem; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.AE.ExtensionMethod; |
|
using KGIS.Framework.DBOperator; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Data; |
|
using System.Linq; |
|
using System.Runtime.InteropServices; |
|
|
|
namespace Kingo.Plugin.DataCheck.Helper.JCCZCDYD |
|
{ |
|
public class JCCZCDYDAreaNoOverlapCheck : DataCheckRule |
|
{ |
|
private string _RuleName; |
|
public override string RuleName { get => _RuleName; set => _RuleName = value; } |
|
private string _RuleDesc; |
|
public override string RuleDesc { get => _RuleDesc; set => _RuleDesc = value; } |
|
public JCCZCDYDAreaNoOverlapCheck() : base() |
|
{ |
|
_RuleName = "面要素间无重叠"; |
|
_RuleDesc = "检查基础城镇村等用地图斑中面要素质检是否存在重叠的拓扑错误"; |
|
} |
|
public override void StartCheck(object pParm) |
|
{ |
|
try |
|
{ |
|
base.CheckState = EnumCheckState.检查中; |
|
IFeatureLayer m_Fc = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑"); |
|
IDataCheckHelper dataCheckHelper = UIShell.OSGi.BundleRuntime.Instance.GetFirstOrDefaultService<IDataCheckHelper>(); |
|
if (dataCheckHelper == null) |
|
{ |
|
base.CheckState = EnumCheckState.检查失败; |
|
return; |
|
} |
|
dataCheckHelper.DataCheck(new CheckParametr() |
|
{ |
|
CheckType = enumCheckType.Graphic, |
|
DataSource = m_Fc.FeatureClass, |
|
IDataCheckName = "JCCZCDYDDataCheck" |
|
}); |
|
StartLoadData(pParm); |
|
base.CheckState = EnumCheckState.检查完成; |
|
} |
|
catch (Exception ex) |
|
{ |
|
base.CheckState = EnumCheckState.检查失败; |
|
LogAPI.Debug(string.Format("{0}", _RuleName)); |
|
LogAPI.Debug(ex); |
|
} |
|
} |
|
public override void StartLoadData(object pParm) |
|
{ |
|
try |
|
{ |
|
string dbPath = System.IO.Path.Combine((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ProjDir, "DataCheckrResult.db"); |
|
DataTable dtFJ = SQLiteDBOperate.Instance.ExceDataTable(dbPath, "select * from DataCheckResults WHERE ErrorCode like '200%' and ErrorLayer='JCCZCDYDDataCheck' order by ErrorType DESC"); |
|
if (dtFJ == null) |
|
return; |
|
base.CheckResults.Clear(); |
|
for (int i = 0; i < dtFJ.Rows.Count; i++) |
|
{ |
|
int id = dtFJ.Rows[i]["ID"].ToInt(); |
|
int bgoid = dtFJ.Rows[i]["OBJECTID"].ToInt(); |
|
string jcError = dtFJ.Rows[i]["ErrorDesc"].ToTrim(); |
|
string jcErroArea = dtFJ.Rows[i]["ErrorArea"].ToTrim(); |
|
string bgErrorType = dtFJ.Rows[i]["ErrorType"].ToTrim(); |
|
EnumErrorType errType = (EnumErrorType)Enum.Parse(typeof(EnumErrorType), bgErrorType); |
|
base.CheckResults.Add(new DataCheckResult() |
|
{ |
|
ID = id, |
|
ErrorDesc = jcError, |
|
ErrorCode = bgoid <= 0 ? "200200" : "200100", |
|
ErrorLayer = "JCDLTB", |
|
PrimaryKey = "OBJECTID", |
|
PrimaryKeyValue = bgoid.ToTrim(), |
|
ErrorType = errType, |
|
ErrorArea = jcErroArea, |
|
Icon = string.Format("pack://siteoforigin:,,,/Images/{0}.{1}", errType.ToString(), "png") |
|
}); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageHelper.ShowError("加载检查结果视图数据失败,请查看日志!"); |
|
LogAPI.Debug(ex.Message); |
|
} |
|
} |
|
|
|
public override void StartRepair(object pParm) |
|
{ |
|
#region 200200-200100图形修复 |
|
string dbPath = System.IO.Path.Combine((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).ProjDir, "DataCheckrResult.db"); |
|
DataTable dtED = SQLiteDBOperate.Instance.ExceDataTable(dbPath, "select * from DataCheckResults where ErrorCode='200200' or ErrorCode='200100'");//失效数据集合 |
|
if (dtED == null && dtED.Rows.Count == 0) return; |
|
IFeatureLayer fix_BGLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG"); |
|
foreach (DataRow dr_Err in dtED.Rows) |
|
{ |
|
if (!string.IsNullOrEmpty(dr_Err["ErrorArea"].ToTrim())) |
|
{ |
|
IGeometry geo = dr_Err["ErrorArea"].ToTrim().ToGeometry(); |
|
if (geo != null && !geo.IsEmpty) |
|
{ |
|
List<IFeature> bgFeatures = FeatureAPI.Identify(geo, fix_BGLayer); |
|
//单个图形需要合并/擦除的情况 |
|
if (bgFeatures.Count == 1)//当前图斑 |
|
{ |
|
if (FeatureAPI.IsAdjacent(bgFeatures[0].ShapeCopy, geo) && !FeatureAPI.IsContains(bgFeatures[0].ShapeCopy, geo)) |
|
{ |
|
IGeometry geometrys = FeatureAPI.Union(bgFeatures[0].Shape, geo);//合并 |
|
bgFeatures[0].Shape = geometrys; |
|
bgFeatures[0].Store(); |
|
Marshal.ReleaseComObject(geometrys); |
|
SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, string.Format("delete from DataCheckResults WHERE ID = '{0}'", dr_Err["ID"].ToTrim()), null); |
|
} |
|
else if (FeatureAPI.IsContains(bgFeatures[0].ShapeCopy, geo) || dr_Err["PrimaryKeyValue"].ToString() == bgFeatures[0].OID.ToString())//包含情况 |
|
{ |
|
IGeometry diffGeo = FeatureAPI.Difference(bgFeatures[0].ShapeCopy, geo);//擦除 |
|
if (diffGeo.IsEmpty) continue;//非-1 OID 边界外 |
|
bgFeatures[0].Shape = diffGeo; |
|
bgFeatures[0].Store(); |
|
Marshal.ReleaseComObject(diffGeo); |
|
SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, string.Format("delete from DataCheckResults WHERE ID = '{0}'", dr_Err["ID"].ToTrim()), null); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
#endregion |
|
#region 200200图形修复 |
|
//string dbPath = System.IO.Path.Combine(Platform.Instance.GetProjectInfo().ProjDir, "DataCheckrResult.db"); |
|
//DataTable dtED = SQLiteDBOperate.Instance.ExceDataTable(dbPath, "select Errone_ID,ED_Type,ErrorData,ErrorArea from ErroneousData where ErrorCode='200200'");//失效数据集合 |
|
//if (dtED == null && dtED.Rows.Count == 0) return; |
|
//IFeatureLayer m_BGLayer = Platform.Instance.MapsService.GetFeatureLayerByName("DLTBBG"); |
|
//IFeatureLayer m_JCLayer = Platform.Instance.MapsService.GetFeatureLayerByName("JC_DLTB"); |
|
//int idxJCBSM = m_JCLayer.FeatureClass.FindField("BSM"); |
|
//foreach (DataRow dr in dtED.Rows) |
|
//{ |
|
// if (string.IsNullOrEmpty(dr["ErrorArea"].ToTrim())) |
|
// continue; |
|
// IGeometry geo = GeometryConvertHelper.ConverJsonToIGeoemtry(dr["ErrorArea"].ToTrim()); |
|
// if (geo == null || geo.IsEmpty) continue; |
|
// List<IFeature> bgFeatures = FeatureAPI.Identify(geo, m_BGLayer); |
|
// if (bgFeatures == null) continue; |
|
// List<IFeature> unionFeatures = new List<IFeature>(); |
|
// foreach (IFeature bg_f in bgFeatures) |
|
// { |
|
// List<IFeature> jcFeatures = FeatureAPI.Identify(bg_f.ShapeCopy, m_JCLayer); |
|
// double interArea = 0; |
|
// foreach (var jc_f in jcFeatures) |
|
// { |
|
// string strBSM = jc_f.Value[idxJCBSM].ToTrim(); |
|
// if (strBSM != dr["ErrorData"].ToTrim()) continue; |
|
// IGeometry interGeo = FeatureAPI.InterSect(jc_f.ShapeCopy, bg_f.ShapeCopy); |
|
// if (interGeo.IsEmpty) continue; |
|
// IArea area = interGeo as IArea; |
|
// if (area == null) continue; |
|
// interArea = area.Area; |
|
// } |
|
// if (interArea > 0) |
|
// unionFeatures.Add(bg_f); |
|
// } |
|
// if (unionFeatures.Count == 1) |
|
// { |
|
// IFeature bg_f = unionFeatures[0]; |
|
// bg_f.Shape = FeatureAPI.Union(bg_f.ShapeCopy, geo); |
|
// bg_f.Store(); |
|
// } |
|
// else if (unionFeatures.Count > 1) |
|
// { |
|
// IFeature bg_f = null; |
|
// double maxLen = 0; |
|
// foreach (var item in unionFeatures) |
|
// { |
|
// double len = FeatureAPI.LengthOfSide(item.ShapeCopy, geo); |
|
// if (len > maxLen) |
|
// { |
|
// maxLen = len; |
|
// bg_f = item; |
|
// } |
|
// } |
|
// bg_f.Shape = FeatureAPI.Union(bg_f.ShapeCopy, geo); |
|
// bg_f.Store(); |
|
// } |
|
//} |
|
#endregion |
|
} |
|
|
|
public override void StartSingleRepair(object pParm) |
|
{ |
|
|
|
} |
|
|
|
public override void StartCheckForThread(object pParam) |
|
{ |
|
|
|
} |
|
} |
|
} |
|
|
|
|