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.
275 lines
14 KiB
275 lines
14 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.esriSystem; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
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.Data; |
|
|
|
namespace Kingo.Plugin.DataCheck.Helper.JCDLTB |
|
{ |
|
public class JCDLTBAreaNoOverlapCheck : 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 JCDLTBAreaNoOverlapCheck() : 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 = "JCDLTBDataCheck" |
|
}); |
|
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='2001000300000014' and ErrorLayer='JCDLTBDataCheck' 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 = "2001000300000014", |
|
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='200500' "); |
|
//if (dtED == null && dtED.Rows.Count == 0) return; |
|
//ProjectInfo projectInfo = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo); |
|
//IFeatureLayer Fc_JCDLTB = GetLayerFromPath(projectInfo.ProjDir + "\\PrjDB.gdb", "JC_DLTB"); |
|
//foreach (DataRow dr_Err in dtED.Rows) |
|
//{ |
|
// if (!string.IsNullOrEmpty(dr_Err["ErrorArea"].ToTrim())) |
|
// { |
|
// IGeometry geo = dr_Err["ErrorArea"].ToTrim().ToGeometry(false); |
|
// if (geo != null && !geo.IsEmpty) |
|
// { |
|
// List<IFeature> bgFeatures = null; |
|
// Dictionary<int, double> keyValuePairs = new Dictionary<int, double>(); |
|
// if (dr_Err["ErrorDesc"].ToTrim().Contains("重叠")) |
|
// { |
|
// bgFeatures = FeatureAPI.Identify(geo, Fc_JCDLTB); |
|
// if (bgFeatures.Count == 0) continue; |
|
// if (bgFeatures.Count == Fc_JCDLTB.FeatureClass.FeatureCount(null)) continue; |
|
// for (int i = 0; i < bgFeatures.Count; i++) |
|
// { |
|
// var polyline = (bgFeatures[i].Shape as ITopologicalOperator).Intersect(geo, esriGeometryDimension.esriGeometry1Dimension) as IPolyline; |
|
// keyValuePairs.Add(i, polyline.Length); |
|
// } |
|
// var _FeaturesIndex = keyValuePairs.OrderByDescending(x => x.Value).FirstOrDefault().Key; |
|
// var InterSectGeo = FeatureAPI.InterSect(bgFeatures[0].ShapeCopy, bgFeatures[1].ShapeCopy); |
|
// IGeometry diffGeo = FeatureAPI.Difference(bgFeatures[_FeaturesIndex].ShapeCopy, InterSectGeo);//擦除 |
|
// if (diffGeo.IsEmpty) continue; |
|
// bgFeatures[_FeaturesIndex].Shape = diffGeo; |
|
// bgFeatures[_FeaturesIndex].Store(); |
|
// Marshal.ReleaseComObject(diffGeo); |
|
// SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, $"delete from DataCheckResults WHERE ID = '{dr_Err["ID"].ToTrim()}'", null); |
|
// } |
|
// else if (dr_Err["ErrorDesc"].ToTrim().Contains("缝隙")) |
|
// { |
|
// bgFeatures = FeatureAPI.Identify(geo, Fc_JCDLTB); |
|
// if (bgFeatures.Count == 0) continue; |
|
// if (bgFeatures.Count == Fc_JCDLTB.FeatureClass.FeatureCount(null)) |
|
// { |
|
// SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, $"delete from DataCheckResults WHERE ID = '{dr_Err["ID"].ToTrim()}'", null); |
|
// continue; |
|
// } |
|
// for (int i = 0; i < bgFeatures.Count; i++) |
|
// { |
|
// var polyline = (bgFeatures[i].Shape as ITopologicalOperator).Intersect(geo, esriGeometryDimension.esriGeometry1Dimension) as IPolyline; |
|
// keyValuePairs.Add(i, polyline.Length); |
|
// } |
|
// var _FeaturesIndex = keyValuePairs.OrderByDescending(x => x.Value).FirstOrDefault().Key; |
|
// try |
|
// { |
|
// var Uniongeo = Union(bgFeatures[_FeaturesIndex].ShapeCopy, geo); |
|
// if (Uniongeo != null) |
|
// { |
|
// bgFeatures[_FeaturesIndex].Shape = Uniongeo; |
|
// bgFeatures[_FeaturesIndex].Store(); |
|
// Marshal.ReleaseComObject(Uniongeo); |
|
// SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, $"delete from DataCheckResults WHERE ID = '{dr_Err["ID"].ToTrim()}'", null); |
|
// } |
|
// } |
|
// catch (Exception ex) |
|
// { |
|
// throw; |
|
// } |
|
// } |
|
// } |
|
// } |
|
//} |
|
//StartLoadData(pParm); |
|
//#endregion |
|
} |
|
public static IGeometry Union(IGeometry pGeo1, IGeometry pGeo2) |
|
{ |
|
IGeometry result = null; |
|
try |
|
{ |
|
if (pGeo1 == null || pGeo2 == null) |
|
{ |
|
result = null; |
|
} |
|
else |
|
{ |
|
ITopologicalOperator topologicalOperator = pGeo1 as ITopologicalOperator; |
|
if (topologicalOperator != null) |
|
{ |
|
ITopologicalOperator to2 = pGeo2 as ITopologicalOperator; |
|
IGeometry line = to2.Boundary; |
|
IGeometry IntersectLine = to2.Intersect(pGeo1, esriGeometryDimension.esriGeometry1Dimension); |
|
IPolyline tempLine = IntersectLine as IPolyline; |
|
IGeometryCollection paths = line as IGeometryCollection; |
|
#region |
|
IGeometryCollection geometryCollection = pGeo1 as IGeometryCollection; |
|
IRing ring = null; |
|
for (int i = 0; i < geometryCollection.GeometryCount; i++) |
|
{ |
|
ring = geometryCollection.get_Geometry(i) as IRing; |
|
IPath path = paths.Geometry[0] as IPath; |
|
to2 = line as ITopologicalOperator; |
|
if (line is IPolyline) |
|
{ |
|
bool b1; |
|
int i1, i2; |
|
(line as IPolyline).SplitAtPoint(tempLine.FromPoint, false, true, out b1, out i1, out i2); |
|
(line as IPolyline).SplitAtPoint(tempLine.ToPoint, false, true, out b1, out i1, out i2); |
|
} |
|
for (int p = 0; p < paths.GeometryCount; p++) |
|
{ |
|
IPath tpath = paths.Geometry[p] as IPath; |
|
if (tpath.Length == tempLine.Length) continue; |
|
bool b = ring.Reshape(tpath); |
|
if (b = true) break; |
|
} |
|
} |
|
IGeometry pGeometry = geometryCollection as IGeometry; |
|
#endregion |
|
result = pGeometry; |
|
return result; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
result = null; |
|
LogAPI.Debug(ex.Message); |
|
} |
|
return result; |
|
} |
|
private IPoint Snapping(IPoint point, IFeatureLayer Fc_JCDLTB) |
|
{ |
|
//IFeatureLayer Fc_JCDLTB = GetLayerFromPath(projectInfo.ProjDir + "\\PrjDB.gdb", "JC_DLTB"); |
|
double tol = 0.0001; |
|
ITopologicalOperator pTopo = point as ITopologicalOperator; |
|
IGeometry pGeometry = pTopo.Buffer(tol).Envelope as IGeometry; |
|
IIdentify indentify = Fc_JCDLTB as IIdentify; |
|
if (indentify == null) |
|
return null; |
|
IArray pIDs = indentify.Identify(pGeometry); |
|
if (pIDs == null || pIDs.Count == 0) |
|
return null; |
|
//List<MovePointStruct> pointList = new List<MovePointStruct>(); |
|
for (int index = 0; index < pIDs.Count; index++) |
|
{ |
|
IFeatureIdentifyObj pFeatIdObj = pIDs.get_Element(index) as IFeatureIdentifyObj; |
|
IRowIdentifyObject pRowObj = pFeatIdObj as IRowIdentifyObject; |
|
IFeature iF = pRowObj.Row as IFeature; |
|
IPoint iHitPt = new ESRI.ArcGIS.Geometry.Point(); |
|
IHitTest iHitTest = iF.Shape as IHitTest; |
|
double hitDist = 0; |
|
int partIndex = 0; |
|
int vertexIndex = 0; |
|
bool bRightSide = false; |
|
if (iHitTest.HitTest(point, tol, esriGeometryHitPartType.esriGeometryPartVertex, |
|
iHitPt, ref hitDist, ref partIndex, ref vertexIndex, ref bRightSide)) |
|
{ |
|
point = iHitPt; |
|
//pointList.Add(new MovePointStruct() |
|
//{ |
|
// Feature = iF, |
|
// Geometry = iF.Shape, |
|
// PartIndex = partIndex, |
|
// VertexIndex = vertexIndex |
|
//}); |
|
} |
|
} |
|
//this.m_hookHelper.ActiveView.Refresh(); |
|
//return pointList; |
|
return null; |
|
} |
|
|
|
public override void StartSingleRepair(object pParm) |
|
{ |
|
|
|
} |
|
|
|
public override void StartCheckForThread(object pParam) |
|
{ |
|
|
|
} |
|
} |
|
} |
|
|
|
|