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.
304 lines
11 KiB
304 lines
11 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.AE.ExtensionMethod; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.ComponentModel; |
|
using System.Windows; |
|
using System.Windows.Controls; |
|
|
|
namespace Kingo.Plugin.DataCheck.View.V_Repair |
|
{ |
|
/// <summary> |
|
/// 变更检查数据合并 的交互逻辑 |
|
/// </summary> |
|
public partial class FrmBGFeaterMerge : BaseWindow |
|
{ |
|
public List<CheckedErrData> Errorlist = new List<CheckedErrData>(); |
|
public List<CheckedBgData> Bglist = new List<CheckedBgData>(); |
|
|
|
/// <summary> |
|
/// 标记是否合并成功 |
|
/// </summary> |
|
public bool IsMerge = false; |
|
public FrmBGFeaterMerge() |
|
{ |
|
InitializeComponent(); |
|
this.Resources = Application.LoadComponent(new Uri(string.Format("{0}.{1}", "/Kingo.Plugin.DataCheck;component/Views/V_Resources/V_ResDic", "xaml"), UriKind.Relative)) as ResourceDictionary; |
|
DataTemplate datatemplate = this.Resources["ItemNode2"] as DataTemplate; |
|
listErrorGeo.ItemTemplate = datatemplate; |
|
} |
|
|
|
/// <summary> |
|
/// 合并 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void btnOK_MergeClick(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
IFeatureLayer dltbbg_Layer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG"); |
|
List<CheckedErrData> obj_Err = Errorlist.FindAll(x => x.IsChecked == true); |
|
List<CheckedBgData> obj_BG = Bglist.FindAll(x => x.IsBgChecked == true); |
|
if (obj_Err == null || obj_BG == null) |
|
{ |
|
MessageHelper.ShowTips("数据都不可为空!"); |
|
} |
|
IGeometry geo = null; |
|
IFeature f_bgFc = null; |
|
if (obj_Err.Count == 1 && obj_BG.Count == 1) |
|
{ |
|
try |
|
{ geo = IPolygonExtension.ToGeometry(obj_Err[0].ErrorArea, true, esriGeometryType.esriGeometryPolygon); } |
|
catch |
|
{ geo = IPolygonExtension.ToGeometry(obj_Err[0].ErrorArea, false, esriGeometryType.esriGeometryPolyline); } |
|
if (Convert.ToInt32(obj_BG[0].OBJECTID) <= 0 || geo == null) return;//未处理OID为异常的时候; |
|
f_bgFc = dltbbg_Layer.FeatureClass.GetFeature(Convert.ToInt32(obj_BG[0].OBJECTID));//变更图斑 |
|
if (geo.GeometryType == esriGeometryType.esriGeometryPolyline) |
|
{ |
|
var geometry = RepairGeometry(f_bgFc, geo); |
|
IGeometry geometrys = FeatureAPI.Union(f_bgFc.ShapeCopy, geometry); |
|
f_bgFc.Shape = geometrys; |
|
f_bgFc.Store(); |
|
IsMerge = true; |
|
this.btnComplat.IsEnabled = true; |
|
MessageHelper.ShowTips("合并成功!"); |
|
} |
|
else if (geo.GeometryType == esriGeometryType.esriGeometryPolygon) |
|
{ |
|
if (FeatureAPI.IsAdjacent(f_bgFc.ShapeCopy, geo) && !FeatureAPI.IsContains(f_bgFc.ShapeCopy, geo)) |
|
{ |
|
IGeometry geometrys = FeatureAPI.Union(f_bgFc.Shape, geo); |
|
f_bgFc.Shape = geometrys; |
|
f_bgFc.Store(); |
|
IsMerge = true; |
|
this.btnComplat.IsEnabled = true; |
|
MessageHelper.ShowTips("合并成功!"); |
|
} |
|
else |
|
{ |
|
MessageHelper.ShowTips("合并失败,选择图斑可能为不相邻或包含关系!"); |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
MessageHelper.ShowTips("数据勾选错误,应错误图斑和变更图斑各一条!"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
MessageHelper.ShowTips("合并失败!"); |
|
} |
|
} |
|
|
|
#region RepairGeometry |
|
private IGeometry RepairGeometry(IFeature feature, IGeometry geometry) |
|
{ |
|
IGeometry geometrys = null; |
|
try |
|
{ |
|
geometrys = feature.ShapeCopy; |
|
IPointCollection ps = geometry as IPointCollection; |
|
IPointCollection reshapePath = new PathClass(); |
|
reshapePath.AddPointCollection(ps); |
|
IGeometryCollection geometryCollection = feature.ShapeCopy as IGeometryCollection; |
|
IRing ring = null; |
|
for (int i = 0; i < geometryCollection.GeometryCount; i++) |
|
{ |
|
ring = geometryCollection.get_Geometry(i) as IRing; |
|
ring.Reshape(reshapePath as IPath); |
|
} |
|
geometrys = geometryCollection as IGeometry; |
|
if (geometrys == null || geometrys.IsEmpty) |
|
{ |
|
return geometrys; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug($"RepairGeometry异常,异常信息如下:{ex.Message}"); |
|
LogAPI.Debug(ex); |
|
} |
|
return geometrys; |
|
} |
|
#endregion |
|
///// <summary> |
|
///// 转化图形 |
|
///// </summary> |
|
///// <param name="pointsStr"></param> |
|
///// <returns></returns> |
|
//private IGeometry GetPolygonFromWkt(string pointsStr) |
|
//{ |
|
// //OSGeo.OGR.Ogr.RegisterAll(); |
|
// IGeometry geometry = new PolygonClass(); |
|
// OSGeo.OGR.Geometry rstGeometry = OSGeo.OGR.Geometry.CreateFromWkt(pointsStr); |
|
// byte[] geometryBytes = new byte[rstGeometry.WkbSize()]; |
|
// rstGeometry.ExportToWkb(geometryBytes); |
|
// IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3; |
|
// int bytesLen = geometryBytes.Length; |
|
// factory.CreateGeometryFromWkbVariant(geometryBytes, out geometry, out bytesLen); |
|
// IPolygon polygon = geometry as IPolygon; |
|
// polygon.Close(); |
|
// ITopologicalOperator pBoundaryTop = polygon as ITopologicalOperator; |
|
// pBoundaryTop.Simplify(); |
|
// return geometry; |
|
//} |
|
/// <summary> |
|
/// |
|
/// </summary> |
|
/// <param name="features">变更图斑</param> |
|
/// <param name="checkResult">错误图斑信息</param> |
|
public void GetViewData(List<IFeature> features, DataCheckResult checkResult) |
|
{ |
|
try |
|
{ |
|
Bglist.Clear(); |
|
Errorlist.Clear(); |
|
//变更图斑 |
|
foreach (IFeature f in features) |
|
{ |
|
CheckedBgData datasource = new CheckedBgData |
|
{ |
|
IsBgChecked = false, |
|
DataFeaterinfor = "OBJECTID=" + f.get_Value(f.Fields.FindField(f.Class.OIDFieldName)).ToString(), |
|
OBJECTID = f.OID.ToString() |
|
}; |
|
Bglist.Add(datasource); |
|
} |
|
//错误图斑 |
|
CheckedErrData datasources = new CheckedErrData |
|
{ |
|
IsChecked = false, |
|
DataFeaterinfor = "错误图形", //"Area=" + checkResult.ErrorDesc.Split('[')[1].Split(']')[0].ToString(), |
|
ErrorArea = checkResult.ErrorArea, |
|
OBJECTID = checkResult.PrimaryKeyValue, |
|
ErrorCode = checkResult.ErrorCode |
|
}; |
|
Errorlist.Add(datasources); |
|
listErrorGeo.ItemsSource = Errorlist; |
|
BGChecklist.ItemsSource = Bglist; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 取消 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void btnCanleClick(object sender, RoutedEventArgs e) |
|
{ |
|
this.Close(); |
|
} |
|
|
|
private void BtnComplat_Click(object sender, RoutedEventArgs e) |
|
{ |
|
this.IsCancel = false; |
|
this.Close(); |
|
} |
|
|
|
/// <summary> |
|
/// 双击高亮 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void CheckBox_Click(object sender, System.Windows.Input.MouseButtonEventArgs e) |
|
{ |
|
try |
|
{ |
|
IFeatureLayer dltbbg_Layer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG"); |
|
object bgData = (e.Source as CheckBox).Parent; |
|
CheckBox comboBox = e.Source as CheckBox; |
|
string bg_OID = comboBox.Content.ToString().Split('=')[1].ToString();//BG_OID |
|
if (!string.IsNullOrWhiteSpace(bg_OID)) |
|
{ |
|
IFeature feature = dltbbg_Layer.FeatureClass.GetFeature(Convert.ToInt32(bg_OID)); |
|
if (feature.ShapeCopy != null && !feature.ShapeCopy.IsEmpty) |
|
{ |
|
MapsManager.Instance.MapService.SelectFeature("DLTBBG", bg_OID, false); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 选择项数据实体 |
|
/// </summary> |
|
public class CheckedBgData : INotifyPropertyChanged |
|
{ |
|
public bool _IsBgChecked; |
|
public bool IsBgChecked |
|
{ |
|
get { return _IsBgChecked; } |
|
set |
|
{ |
|
_IsBgChecked = value; |
|
RaisePropertyChanged("IsBgChecked"); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 数据信息 |
|
/// </summary> |
|
public string DataFeaterinfor { set; get; } |
|
public string OBJECTID { set; get; } |
|
|
|
public event PropertyChangedEventHandler PropertyChanged; |
|
private void RaisePropertyChanged(string v) |
|
{ |
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(v)); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 选择项数据实体 |
|
/// </summary> |
|
public class CheckedErrData : INotifyPropertyChanged |
|
{ |
|
private bool _IsChecked; |
|
public bool IsChecked |
|
{ |
|
get { return _IsChecked; } |
|
set |
|
{ |
|
_IsChecked = value; |
|
RaisePropertyChanged("IsChecked"); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 数据类型 |
|
/// </summary> |
|
public string DataFeaterinfor { set; get; } |
|
public string OBJECTID { set; get; } |
|
public string EID { set; get; } |
|
public string ErrorCode { set; get; } |
|
|
|
public string ErrorArea { set; get; } |
|
|
|
public event PropertyChangedEventHandler PropertyChanged; |
|
private void RaisePropertyChanged(string v) |
|
{ |
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(v)); |
|
} |
|
} |
|
|
|
}
|
|
|