using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
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.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Views;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using UIShell.OSGi;
using KUI.Windows;
using KGIS.Framework.Utils.Interface;
using System.Data;
using KGIS.Framework.DBOperator;
namespace Kingo.Plugin.DLTB_IDG.View
{
///
/// 地类增量图斑更新 的交互逻辑
///
public partial class ZLDataModifyView : UserControl, IDockPanel2
{
private EngineEditorClass pEditor = null;
private List _Elements = null;
private IElementInfo _FeatureInfo = null;
private IFeatureLayer _curDLTBGX_FL = null;
private IFeatureLayer _curDLTBGXGC_FL = null;
private string MaxBSM { get; set; }
public event EventHandler CloseViewHandler;
private int SaveFeatureOID = -1;
private bool IsSave = false;
private ControlsMapRefreshViewCommandClass refresh = new ControlsMapRefreshViewCommandClass();
private Dictionary jc_FieldsIndex;
private Dictionary gx_FieldsIndex;
private Dictionary gxgc_FieldsIndex;
public Dictionary TempBSMDic = new Dictionary();
public Dictionary TempTBBHDic = new Dictionary();
///
/// 基础地类图斑层
///
private IFeatureLayer jcdltb_Layer = null;
private string XZQCode = string.Empty;
IRDBHelper rdbHelper = null;
DataTable dtDict = null;
public ZLDataModifyView(IFeatureLayer GXLayer)
{
InitializeComponent();
Title = "增量更新变更";
this.DockAreas = DockStyle.DockRight | DockStyle.Document;
this.FloatSize = new System.Drawing.Size(400, 800);
this.DefaultArea = DockStyle.DockRight;
this.DockWidth = 400;
this.ShowCloseButton = true;
this.ShowAutoHideButton = true;
InitView();
this.Loaded += (s, e) =>
{
MapsManager.Instance.MapService.OnSelectionChanged += MapService_OnSelectionChanged;
_curDLTBGX_FL = GXLayer;// MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGX");
_curDLTBGXGC_FL = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGXGC");
jcdltb_Layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
XZQCode = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE;
refresh.OnCreate(MapsManager.Instance.MapService.Hook);
pEditor = new EngineEditorClass();
};
}
///
/// 构造函数()
///
public ZLDataModifyView()
{
refresh = new ControlsMapRefreshViewCommandClass();
}
private void MapService_OnSelectionChanged(object sender, EventArgs e)
{
try
{
ISelectionSet pSelectionSetes = (_curDLTBGX_FL as IFeatureSelection).SelectionSet;//获取图层要素已被选择的
int oid = -1;
if (pSelectionSetes != null && pSelectionSetes.Count == 1)
{
if (IsSave) return;
IEnumIDs enumIDs = pSelectionSetes.IDs;
enumIDs.Reset();
while ((oid = enumIDs.Next()) >= 0)
{
IFeature f = _curDLTBGX_FL.FeatureClass.GetFeature(oid);
_FeatureInfo.BindData(f);
SaveFeatureOID = oid;
btnSave.Visibility = Visibility.Visible;
btnDele.Visibility = Visibility.Collapsed;
break;
}
Marshal.ReleaseComObject(enumIDs);
}
else if (pSelectionSetes != null && pSelectionSetes.Count != 1)
{
oid = -1;
}
if (oid == -1)
{
_FeatureInfo.BindData(_curDLTBGX_FL.FeatureClass.CreateFeatureBuffer() as IFeature);
btnSave.Visibility = Visibility.Collapsed;
btnDele.Visibility = Visibility.Collapsed;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
#region 继承属性
public bool IsShow { get; set; }
public int ShowIndex { get; set; }
public bool ResetSize { get; set; }
public bool AllowEdit { get; set; }
public Guid ID { get; set; }
public DockStyle DockAreas { get; set; }
public System.Drawing.Size FloatSize { get; set; }
public int DockWidth { get; set; }
public int DockHeight { get; set; }
public DockStyle DefaultArea { get; set; }
public bool ShowCloseButton { get; set; }
public bool ShowAutoHideButton { get; set; }
public string Title { get; set; }
public bool IsShowInMap { get; set; }
#endregion
///
/// 保存-按钮
///
///
///
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
try
{
IsSave = false;
btnSave.IsEnabled = false;
btnDele.IsEnabled = false;
if (pEditor.EditState != esriEngineEditState.esriEngineStateEditing)
{
MessageHelper.ShowTips("请先开启图层编辑!");
return;
}
this.ShowLoading("正在进行增量更新数据准备........", 0, 0);
if (_curDLTBGX_FL == null)
_curDLTBGX_FL = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGX");
if (string.IsNullOrWhiteSpace(MaxBSM))
MaxBSM = GetMaxBSM(new List() { _curDLTBGX_FL.FeatureClass, _curDLTBGXGC_FL.FeatureClass, jcdltb_Layer.FeatureClass });
IFeature GX_f = null;
SaveDataBySaveCommand();//执行变更前保存因外部修改
if (SaveFeatureOID != -1)
{
try
{
GX_f = _curDLTBGX_FL.FeatureClass.GetFeature(SaveFeatureOID);
}
catch (Exception)
{
MessageHelper.ShowError("当前数据获取失败,请重新选择数据!");
return;
}
}
else return;
int BSMGXIndex = _curDLTBGX_FL.FeatureClass.FindField("BSM");
ITable tableGC = _curDLTBGXGC_FL.FeatureClass as ITable;
ITable tableGX = _curDLTBGX_FL.FeatureClass as ITable;
if (GX_f != null)
{
if (DataSpecificationCheck(GX_f) == false) return;
}
else
{
MessageHelper.ShowTips("当前图斑获取失败_OID:" + SaveFeatureOID);
return;
}
string GX_BSM = GX_f.Value[BSMGXIndex].ToString().Trim();
IQueryFilter queryFilter = new QueryFilterClass
{
WhereClause = string.Format("BGHTBBSM='{0}'", GX_BSM)
};
#region 图层字段
if (jc_FieldsIndex == null || jc_FieldsIndex.Count == 0)
jc_FieldsIndex = GetFieldsIndex(jcdltb_Layer.FeatureClass.Fields);
if (gx_FieldsIndex == null || gx_FieldsIndex.Count == 0)
gx_FieldsIndex = GetFieldsIndex(_curDLTBGX_FL.FeatureClass.Fields);
if (gxgc_FieldsIndex == null || gxgc_FieldsIndex.Count == 0)
gxgc_FieldsIndex = GetFieldsIndex(_curDLTBGXGC_FL.FeatureClass.Fields);
#endregion
this.UpdateMsg("正在进行增量数据更新........");
queryFilter.WhereClause = string.Format("BSM='{0}'", GX_BSM);
if (tableGX.RowCount(queryFilter) > 1)//存在重复BSM,默认是分割图斑造成
{
IFeatureCursor featureCursorGX = _curDLTBGX_FL.FeatureClass.Update(queryFilter, false);
IFeature featureGX = null;
while ((featureGX = featureCursorGX.NextFeature()) != null)
{
if (featureGX.OID == GX_f.OID)
{
ExeZLDataGeneration(featureGX, jcdltb_Layer, null, _curDLTBGX_FL, _curDLTBGXGC_FL, XZQCode);
}
else
{ //切割的其余部分要重新赋值BSM
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9));
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
featureGX.Value[BSMGXIndex] = MaxBSM;
featureGX.Store();
ExeZLDataGeneration(featureGX, jcdltb_Layer, null, _curDLTBGX_FL, _curDLTBGXGC_FL, XZQCode);
}
}
}
else//新增/BSM唯一
{
if (string.IsNullOrWhiteSpace(GX_BSM))//BSM为空,默认为新增图斑
{ //新增图斑重新编BSM
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9));
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
GX_f.Value[BSMGXIndex] = MaxBSM;
GX_f.Store();
}
ExeZLDataGeneration(GX_f, jcdltb_Layer, null, _curDLTBGX_FL, _curDLTBGXGC_FL, XZQCode);
}
refresh.OnClick();
this.CloseLoading();
IsSave = true;
MessageHelper.ShowTips("增量数据更新成功!");
}
catch (Exception ex)
{
IsSave = false;
LogAPI.Debug("增量数据更新失败!");
LogAPI.Debug(ex);
this.CloseLoading();
MessageHelper.ShowError("保存失败:" + ex.Message);
SaveFeatureOID = -1;
_FeatureInfo.BindData(_curDLTBGX_FL.FeatureClass.CreateFeatureBuffer() as IFeature);
}
finally
{
#region 注释(调用保存)
#endregion
IsSave = false;
btnSave.IsEnabled = true;
btnDele.IsEnabled = true;
this.CloseLoading();
}
}
//系统保存,避免最终非常规关闭,导致所有修改项保存失败
private ControlsEditingSaveCommandClass saveCmd = null;
private void SaveDataBySaveCommand()
{
if (saveCmd == null)
{
saveCmd = new ControlsEditingSaveCommandClass();
saveCmd.OnCreate(MapsManager.Instance.MapService.Hook);
}
if (saveCmd.Enabled)
{
saveCmd.OnClick();
}
}
public void ExeBatchModifying(IFeatureLayer _curDLTBGX_FL, IQueryFilter queryFilter)
{
try
{
this.ShowLoading("正在进行增量更新数据准备........", 0, 0);
if (_curDLTBGXGC_FL == null)
_curDLTBGXGC_FL = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGXGC");
if (jcdltb_Layer == null)
jcdltb_Layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
XZQCode = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE;
refresh.OnCreate(MapsManager.Instance.MapService.Hook);
#region 图层字段
if (jc_FieldsIndex == null || jc_FieldsIndex.Count == 0)
jc_FieldsIndex = GetFieldsIndex(jcdltb_Layer.FeatureClass.Fields);
if (gx_FieldsIndex == null || gx_FieldsIndex.Count == 0)
gx_FieldsIndex = GetFieldsIndex(_curDLTBGX_FL.FeatureClass.Fields);
if (gxgc_FieldsIndex == null || gxgc_FieldsIndex.Count == 0)
gxgc_FieldsIndex = GetFieldsIndex(_curDLTBGXGC_FL.FeatureClass.Fields);
#endregion
if (_curDLTBGX_FL == null)
_curDLTBGX_FL = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGX");
if (string.IsNullOrWhiteSpace(MaxBSM))
MaxBSM = GetMaxBSM(new List() { _curDLTBGX_FL.FeatureClass, _curDLTBGXGC_FL.FeatureClass, jcdltb_Layer.FeatureClass });
IFeature GX_f = null;
IFeatureCursor feature = _curDLTBGX_FL.FeatureClass.Update(queryFilter, true);
int BSMGXIndex = _curDLTBGX_FL.FeatureClass.FindField("BSM");
ITable tableGC = _curDLTBGXGC_FL.FeatureClass as ITable;
ITable tableGX = _curDLTBGX_FL.FeatureClass as ITable;
this.UpdateMsg("正在进行增量数据更新........");
while ((GX_f = feature.NextFeature()) != null)
{
string GX_BSM = GX_f.Value[BSMGXIndex].ToString().Trim();
queryFilter.WhereClause = string.Format("BSM='{0}'", GX_BSM);
if (tableGX.RowCount(queryFilter) > 1)//存在重复BSM,默认是分割图斑造成
{
IFeatureCursor featureCursorGX = _curDLTBGX_FL.FeatureClass.Update(queryFilter, false);
IFeature featureGX = null;
while ((featureGX = featureCursorGX.NextFeature()) != null)
{
if (featureGX.OID == GX_f.OID)
{
ExeZLDataGeneration(featureGX, jcdltb_Layer, null, _curDLTBGX_FL, _curDLTBGXGC_FL, XZQCode);
}
else
{ //切割的其余部分要重新赋值BSM
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9));
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
featureGX.Value[BSMGXIndex] = MaxBSM;
featureGX.Store();
ExeZLDataGeneration(featureGX, jcdltb_Layer, null, _curDLTBGX_FL, _curDLTBGXGC_FL, XZQCode);
}
}
}
else//新增/BSM唯一
{
if (string.IsNullOrWhiteSpace(GX_BSM))//BSM为空,默认为新增图斑
{ //新增图斑重新编BSM
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9));
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
GX_f.Value[BSMGXIndex] = MaxBSM;
GX_f.Store();
}
ExeZLDataGeneration(GX_f, jcdltb_Layer, null, _curDLTBGX_FL, _curDLTBGXGC_FL, XZQCode);
}
}
refresh.OnClick();
this.CloseLoading();
MessageHelper.ShowTips("增量数据批量更新成功!");
}
catch (Exception ex)
{
LogAPI.Debug("增量数据批量更新失败!");
LogAPI.Debug(ex);
this.CloseLoading();
MessageHelper.ShowError("保存失败:" + ex.Message);
}
finally
{
this.CloseLoading();
}
}
///
/// 增量数据变更前数据检查
///
/// 修改过得更新图斑
///
private bool DataSpecificationCheck(IFeature GX_f)
{
IFeature feature = GX_f;
string dbpath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
if (rdbHelper == null)
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbpath, DatabaseType.SQLite);
if (rdbHelper == null)
{
throw new Exception("数据库连接打开失败:" + dbpath);
}
this.UpdateMsg("正在进行增量数据变更数据规范性检查.........");
if (dtDict == null)
dtDict = rdbHelper.ExecuteDatatable("Sys_DicType", $"SELECT CODE,NAME FROM Sys_DicDetail WHERE OWNERDIC='2' ", true);
List DicsZZSX = Platform.Instance.DicHelper.GetDic(DicTypeEnum.ZZSX);
List DicsXHLX = Platform.Instance.DicHelper.GetDic(DicTypeEnum.TBXHLX);
try
{
#region 属性
int iQSDWDM = _curDLTBGX_FL.FeatureClass.Fields.FindField("QSDWDM");//权属单位代码
int iQSDWMC = _curDLTBGX_FL.FeatureClass.Fields.FindField("QSDWMC");//权属单位名称
int iZLDWDM = _curDLTBGX_FL.FeatureClass.Fields.FindField("ZLDWDM");//坐落单位代码
int iZLDWMC = _curDLTBGX_FL.FeatureClass.Fields.FindField("ZLDWMC");//坐落单位名称
int iMSSM = _curDLTBGX_FL.FeatureClass.Fields.FindField("MSSM");//描述说明
int iDLBM = _curDLTBGX_FL.FeatureClass.Fields.FindField("DLBM");//地类编码
int iDLMC = _curDLTBGX_FL.FeatureClass.Fields.FindField("DLMC");//地类名称
int iQSXZ = _curDLTBGX_FL.FeatureClass.Fields.FindField("QSXZ");//权属性质
int iGDPDJB = _curDLTBGX_FL.FeatureClass.Fields.FindField("GDPDJB");//耕地坡度级别
int iKCDLXS = _curDLTBGX_FL.FeatureClass.Fields.FindField("KCXS");//扣除地类系数
int iKCDLBM = _curDLTBGX_FL.FeatureClass.Fields.FindField("KCDLBM");//扣除地类编码
int iGDLX = _curDLTBGX_FL.FeatureClass.Fields.FindField("GDLX");//耕地类型
int iGDDB = _curDLTBGX_FL.FeatureClass.Fields.FindField("GDDB");//耕地等别
int iTBXHDM = _curDLTBGX_FL.FeatureClass.Fields.FindField("TBXHDM");//图斑细化代码
int iTBXHMC = _curDLTBGX_FL.FeatureClass.Fields.FindField("TBXHMC");//图斑细化名称
int iZZSXDM = _curDLTBGX_FL.FeatureClass.Fields.FindField("ZZSXDM");//种植属性代码
int iZZSXMC = _curDLTBGX_FL.FeatureClass.Fields.FindField("ZZSXMC");//种植属性名称
int iCZCSXM = _curDLTBGX_FL.FeatureClass.Fields.FindField("CZCSXM");//城镇村属性码
int iXZDWKD = _curDLTBGX_FL.FeatureClass.Fields.FindField("XZDWKD");//线状地物宽度
int iBZ = _curDLTBGX_FL.FeatureClass.Fields.FindField("BZ");//备注
int iFRDBS = _curDLTBGX_FL.FeatureClass.Fields.FindField("FRDBS");//飞入地标识
int iBSM = _curDLTBGX_FL.FeatureClass.Fields.FindField("BSM");//标识码
#endregion
string strDLBM = feature.Value[iDLBM].ToTrim();
if (!string.IsNullOrEmpty(strDLBM) && strDLBM.Length > 2)
{
strDLBM = strDLBM.Substring(0, 2);
}
LogAPI.Debug("增量数据变更数据规范性检查开始.........OID:" + GX_f.OID);
string ErrLogs = string.Empty;
if (string.IsNullOrEmpty(feature.Value[iQSDWDM].ToTrim()) || string.IsNullOrEmpty(feature.Value[iQSDWMC].ToTrim()) || string.IsNullOrEmpty(feature.Value[iZLDWDM].ToTrim()) || string.IsNullOrEmpty(feature.Value[iZLDWMC].ToTrim()))
{
ErrLogs += "权属/坐落不可为空!\r\n";
LogAPI.Debug("权属/坐落不可为空!");
}
if (string.IsNullOrEmpty(feature.Value[iMSSM].ToTrim()))
{
ErrLogs += "描述说明不可为空!\r\n";
LogAPI.Debug("描述说明不可为空!");
}
//地类名称/代码
if (string.IsNullOrEmpty(feature.Value[iDLBM].ToTrim()) || string.IsNullOrEmpty(feature.Value[iDLMC].ToTrim()))
{
ErrLogs += "地类名称/代码不可为空!\r\n";
LogAPI.Debug("地类名称/代码不可为空!");
}
else
{
var dtrow = dtDict.Select($"CODE = '{feature.Value[iDLBM].ToString()}'");
if (dtrow.Length > 0 && feature.Value[iDLMC].ToTrim() != dtrow[0]["NAME"].ToTrim())
{
ErrLogs += "当前的地类名称填写错误!\r\n";
LogAPI.Debug("当前的地类名称填写错误!" + feature.Value[iDLMC].ToString());
}
else if (dtrow.Length <= 0)
{
ErrLogs += "当前的地类编码在字典中不存在!\r\n";
LogAPI.Debug("当前的地类编码在字典中不存在!" + feature.Value[iDLBM].ToString());
}
}
//权属性质
if ((feature.Value[iQSXZ].ToString() == "21" || feature.Value[iQSXZ].ToString() == "41") && feature.Value[iMSSM].ToTrim() != "01")
{
ErrLogs += "权属性质为21/41,描述说明应该为01!\r\n";
LogAPI.Debug("权属性质为21/41,描述说明应该为01!");
}
//耕地坡度级别/扣除地类系数/扣除地类编码
if (!string.IsNullOrEmpty(feature.Value[iDLBM].ToTrim()))
{
if (strDLBM != "01" && !(string.IsNullOrWhiteSpace(feature.Value[iKCDLXS].ToTrim()) || feature.Value[iKCDLXS].ToTrim() == "0"))
{
ErrLogs += "地类为非01类图斑,扣除地类系数应该为0!\r\n";
LogAPI.Debug("地类为非01类图斑,扣除地类系数应该为0!");
}
if (strDLBM != "01" && !string.IsNullOrWhiteSpace(feature.Value[iKCDLBM].ToTrim()))
{
ErrLogs += "地类为非01类图斑,扣除地类编码应该为空!\r\n";
LogAPI.Debug("地类为非01类图斑,扣除地类编码应该为空!");
}
if (strDLBM != "01" && !string.IsNullOrWhiteSpace(feature.Value[iGDPDJB].ToTrim()))
{
ErrLogs += "地类为非01类图斑,耕地坡度级别应该为空!\r\n";
LogAPI.Debug("地类为非01类图斑,耕地坡度级别应该为空!");
}
}
//耕地类型/耕地等别
if (!string.IsNullOrEmpty(feature.Value[iDLBM].ToTrim()))
{
if (strDLBM != "01" && !string.IsNullOrWhiteSpace(feature.Value[iGDLX].ToTrim()))
{
ErrLogs += "地类为非01类图斑,耕地类型应该为空!\r\n";
LogAPI.Debug("地类为非01类图斑,耕地类型应该为空!");
}
if (strDLBM != "01" && !(string.IsNullOrWhiteSpace(feature.Value[iGDDB].ToTrim()) || feature.Value[iGDDB].ToTrim() == "0"))
{
ErrLogs += "地类为非01类图斑,耕地等别应该为空!\r\n";
LogAPI.Debug("地类为非01类图斑,耕地等别应该为空!");
}
}
List liststr = new List() { "HDGD", "HQGD", "LQGD", "MQGD", "SHGD", "SMGD", "YJGD" };
//图斑细化代码/图斑细化名称
if (!string.IsNullOrEmpty(feature.Value[iDLBM].ToTrim()))
{
//非01类图斑,图斑细化代码标注HDGD、HQGD、LQGD、MQGD、SHGD、SMGD、YJGD的需清空。
if (strDLBM != "01" && liststr.Contains(feature.Value[iTBXHDM].ToString()))
{
if (feature.Value[iTBXHDM].ToTrim() == "" || feature.Value[iTBXHMC].ToTrim() == "")
{
ErrLogs += "地类为非01类图斑,图斑细化代码不应该为HDGD,HQGD,LQGD,MQGD,SHGD,SMGD,YJGD中的其一,应清空图斑细化代码、名称!\r\n";
LogAPI.Debug("地类为非01类图斑,图斑细化代码不应该为HDGD,HQGD,LQGD,MQGD,SHGD,SMGD,YJGD中的其一,应清空图斑细化代码、名称!");
}
}
//非06类用地,TBXHDM字段为HDGY、GTGY、MTGY、SNGY、BLGY、DLGY的需清空。
liststr = new List() { "HDGY", "GTGY", "MTGY", "SNGY", "BLGY", "DLGY" };
if (strDLBM != "06" && liststr.Contains(feature.Value[iTBXHDM].ToString()))
{
if (feature.Value[iTBXHDM].ToTrim() == "" || feature.Value[iTBXHMC].ToTrim() == "")
{
ErrLogs += "地类为非06类图斑,图斑细化代码不应该为HDGY,GTGY,MTGY,SNGY,BLGY,DLGY中的其一,应清空图斑细化代码、名称!\r\n";
LogAPI.Debug("地类为非06类图斑,图斑细化代码不应该为HDGY,GTGY,MTGY,SNGY,BLGY,DLGY中的其一,应清空图斑细化代码、名称!");
}
}
//非04类图斑,标注GCCD的需清除。
if (strDLBM != "04" && feature.Value[iTBXHDM].ToString() == "GCCD")
{
if (feature.Value[iTBXHDM].ToTrim() == "" || feature.Value[iTBXHMC].ToTrim() == "")
{
ErrLogs += "地类为非04类,图斑细化代码不应该为GCCD,应清空图斑细化代码、名称!\r\n";
LogAPI.Debug("地类为非04类,图斑细化代码不应该为GCCD,应清空图斑细化代码、名称!");
}
}
//非03类,0404的图斑,标注LJTM的需要清除。
if ((strDLBM != "03" || feature.Value[iDLBM].ToString() == "0404") && feature.Value[iTBXHDM].ToString() == "LJTM")
{
if (feature.Value[iTBXHDM].ToTrim() == "" || feature.Value[iTBXHMC].ToTrim() == "")
{
ErrLogs += "地类为非03类或非0404,图斑细化代码不应该为LJTM,应清空图斑细化代码、名称!\r\n";
LogAPI.Debug("地类为非03类或非0404,图斑细化代码不应该为LJTM,应清空图斑细化代码、名称!");
}
}
//地类编码字段前2位非01、02、03、04,且不等于0601、0602、1001、1003,或属于湿地的,不能进行图斑细化标注
liststr = new List() { "01", "02", "03", "04", "0601", "0602", "1001", "1003", "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
if (!liststr.Contains(strDLBM) && !liststr.Contains(feature.Value[iDLBM].ToString()))
{
if (feature.Value[iTBXHDM].ToTrim() != "" || feature.Value[iTBXHMC].ToTrim() != "")
{
ErrLogs += "地类编码字段为非‘01类,02类,03类,04类,0601,0602,1001,1003,0303,0304,0306,0402,0603,1105,1106,1108’,不能进行图斑细化标注,应清空图斑细化代码、名称!\r\n";
LogAPI.Debug("地类编码字段为非‘01类,02类,03类,04类,0601,0602,1001,1003,0303,0304,0306,0402,0603,1105,1106,1108’,不能进行图斑细化标注,应清空图斑细化代码、名称!");
}
}
}
//种植属性代码/种植属性名称
if (!string.IsNullOrEmpty(feature.Value[iDLBM].ToTrim()))
{
//非01类图斑,种植属性代码标注LS、FLS、LYFL、XG、LLJZ、WG的需要清空;
liststr = new List() { "LS", "FLS", "LYFL", "XG", "LLJZ", "WG" };
if (strDLBM != "01" && !strDLBM.StartsWith("01") && liststr.Contains(feature.Value[iZZSXDM].ToTrim()))
{
if (feature.Value[iZZSXDM].ToTrim() == "" || feature.Value[iZZSXMC].ToTrim() == "")
{
ErrLogs += "地类为非01类图斑,种植属性代码标注LS、FLS、LYFL、XG、LLJZ、WG,应清空种植属性代码、名称!\r\n";
LogAPI.Debug("地类为非01类图斑,种植属性代码标注LS、FLS、LYFL、XG、LLJZ、WG,应清空种植属性代码、名称!");
}
}
//非0301、0302、0305、0307、0404、1104、1104A,0201、0202、0203、0204、0201K、0202K、0203K、0204K、0301K、0302K、0307K、0403K、1104K的种植属性代码填写JKHF、GCHF的需清空。
liststr = new List() { "0301", "0302", "0305", "0307", "0404", "1104", "1104A", "0201", "0202", "0203", "0204", "0201K", "0202K", "0203K", "0204K", "0301K", "0302K", "0307K", "0403K", "1104K" };
if (!liststr.Contains(feature.Value[iDLBM].ToTrim()) && (feature.Value[iZZSXDM].ToTrim() == "JKHF" || feature.Value[iZZSXDM].ToTrim() == "GCHF"))
{
if (feature.Value[iZZSXDM].ToTrim() == "" || feature.Value[iZZSXMC].ToTrim() == "")
{
ErrLogs += "地类为非0301、0302、0305、0307、0404、1104、1104A,0201、0202、0203、0204、0201K、0202K、0203K、0204K、0301K、0302K、0307K、0403K、1104K的图斑,种植属性代码标注JKHF、GCHF,应清空种植属性代码、名称!\r\n";
LogAPI.Debug("地类为非0301、0302、0305、0307、0404、1104、1104A,0201、0202、0203、0204、0201K、0202K、0203K、0204K、0301K、0302K、0307K、0403K、1104K的图斑,种植属性代码标注JKHF、GCHF,应清空种植属性代码、名称!");
}
}
//地类编码字段前2位为04(不包括0404、0403K)、05、06、07、08、09、10、11(不包括1104、1104A、1104K)、12,或属于湿地的,不能进行种植属性标注或恢复属性标注;
liststr = new List() { "04", "05", "06", "07", "08", "09", "10", "11", "12", "0303", "0304", "0306", "0402", "0603", "1105", "1106", "1108" };
var liststr1 = new List() { "0404", "0403K", "1104", "1104A", "1104K" };
if ((liststr.Contains(strDLBM) || liststr.Contains(feature.Value[iDLBM].ToTrim())) && !liststr1.Contains(feature.Value[iDLBM].ToTrim()))
{
if (feature.Value[iZZSXDM].ToTrim() != "" || feature.Value[iZZSXMC].ToTrim() != "")
{
ErrLogs += "地类编码字段前2位为04(不包括0404、0403K)、05、06、07、08、09、10、11(不包括1104、1104A、1104K)、12,或属于湿地的图斑,应清空种植属性代码、名称!\r\n";
LogAPI.Debug("地类编码字段前2位为04(不包括0404、0403K)、05、06、07、08、09、10、11(不包括1104、1104A、1104K)、12,或属于湿地的图斑,应清空种植属性代码、名称!");
}
}
}
//城镇村属性码
if (!string.IsNullOrEmpty(feature.Value[iDLBM].ToTrim()))
{
//1001、1002、1003、1007、1008、1009、1109的图斑,城镇村属性码应为空
liststr = new List() { "1001", "1002", "1003", "1007", "1008", "1009", "1109" };
if (liststr.Contains(feature.Value[iDLBM].ToString()))
{
if (feature.Value[iCZCSXM].ToTrim() != "")
{
ErrLogs += "地类为1001、1002、1003、1007、1008、1009、1109的图斑,城镇村属性码应为空!\r\n";
LogAPI.Debug("地类为1001、1002、1003、1007、1008、1009、1109的图斑,城镇村属性码应为空!");
}
}
}
//线状地物宽度
if (!string.IsNullOrEmpty(feature.Value[iDLBM].ToTrim()))
{
//非线性图斑要清除线状地物宽度
liststr = new List() { "1001", "1002", "1003", "1004", "1006", "1009", "1101", "1107", "1107A", "1203" };
if (!liststr.Contains(feature.Value[iDLBM].ToString()) && feature.Value[iXZDWKD].ToString() != "0")
{
if (feature.Value[iXZDWKD].ToTrim() != "0")
{
ErrLogs += "地类为1001、1002、1003、1007、1008、1009、1109、1101、1107、1107A、1203的图斑,线状地物宽度应为0!\r\n";
LogAPI.Debug("地类为1001、1002、1003、1007、1008、1009、1109、1101、1107、1107A、1203的图斑,线状地物宽度应为0!");
}
}
}
//飞入地标识
if (string.IsNullOrEmpty(feature.Value[iFRDBS].ToTrim()))
{
ErrLogs += "飞入地标识不能为空!";
LogAPI.Debug("飞入地标识不能为空!");
}
LogAPI.Debug("增量数据变更数据规范性检查结束.........");
if (!string.IsNullOrEmpty(ErrLogs))
{
MessageHelper.ShowTips(string.Format("数据检查过程中出现填写不规范!\r\n{0}", ErrLogs));
return false;
}
else
{
return true;
}
}
catch (Exception ex)
{
LogAPI.Debug("增量变更数据规范性检查报错,详情如下:");
LogAPI.Debug(ex);
MessageHelper.ShowError("增量变更数据规范性检查报错,请查看日志!");
return false;
}
}
///
/// 删除增量数据
///
///
///
private void BtnDele_Click(object sender, RoutedEventArgs e)
{
try
{
if (pEditor.EditState != esriEngineEditState.esriEngineStateEditing)
{
MessageHelper.ShowTips("请先开启图层编辑!");
return;
}
if (_curDLTBGX_FL == null)
_curDLTBGX_FL = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGX");
IFeature DeleGX_f = null;
if (SaveFeatureOID != -1)
{
try
{
DeleGX_f = _curDLTBGX_FL.FeatureClass.GetFeature(SaveFeatureOID);
}
catch (Exception)
{
MessageHelper.ShowError("获取当前图斑失败,请刷新后再尝试!");
return;
}
}
else return;
#region 图层字段
int BGQBSMGXGCIndex = _curDLTBGXGC_FL.FeatureClass.FindField("BGQTBBSM");
int BGHBSMGXGCIndex = _curDLTBGXGC_FL.FeatureClass.FindField("BGHTBBSM");
int BSMGXIndex = _curDLTBGX_FL.FeatureClass.FindField("BSM");
int BGMJIndex = _curDLTBGX_FL.FeatureClass.FindField("TBMJ");
int JCBSMGXIndex = jcdltb_Layer.FeatureClass.FindField("BSM");
ITable tableGC = _curDLTBGXGC_FL.FeatureClass as ITable;
ITable tableGX = _curDLTBGX_FL.FeatureClass as ITable;
if (jc_FieldsIndex == null || jc_FieldsIndex.Count == 0)
jc_FieldsIndex = GetFieldsIndex(jcdltb_Layer.FeatureClass.Fields);
if (gx_FieldsIndex == null || gx_FieldsIndex.Count == 0)
gx_FieldsIndex = GetFieldsIndex(_curDLTBGX_FL.FeatureClass.Fields);
if (gxgc_FieldsIndex == null || gxgc_FieldsIndex.Count == 0)
gxgc_FieldsIndex = GetFieldsIndex(_curDLTBGXGC_FL.FeatureClass.Fields);
#endregion
string GXBSM = DeleGX_f.Value[BSMGXIndex].ToString().Trim();
if (string.IsNullOrWhiteSpace(GXBSM))
MessageHelper.ShowTips("当前数据标识码为空!");
else
{
this.ShowLoading("正在进行变更数据还原操作........", 0, 0);
IQueryFilter queryFilter = new QueryFilterClass
{
WhereClause = string.Format("BGHTBBSM='{0}'", GXBSM)
};
DLTBGXAttribute temp_De = new DLTBGXAttribute(gx_FieldsIndex);
temp_De.OID = DeleGX_f.OID;
temp_De.Shape2 = DeleGX_f.ShapeCopy;//删除增量数据,属性还原成基础图斑属性
temp_De.GCDataList.AddRange(GetDLTBGXGCs(temp_De, DeleGX_f));
if (temp_De.GCDataList.Count == 1)
{
List JC_Fs = FeatureAPI.Identify2(temp_De.GCDataList[0].Shape, jcdltb_Layer);
int length = JC_Fs.Count;
if (JC_Fs.Count == 1 && FeatureAPI.IsContains(JC_Fs[0].ShapeCopy, temp_De.Shape2))
{
DLTBGXAttribute dLTBGXAttribute = new DLTBGXAttribute(gx_FieldsIndex);
dLTBGXAttribute.SetAttribure(JC_Fs[0], jc_FieldsIndex);
temp_De.SetAttribure(DeleGX_f);//被动变更图斑不需要还原
if (dLTBGXAttribute.IsEqual(temp_De)) return;
}
else
{
for (int i = 0; i < length; i++)
{
if (!FeatureAPI.IsContains(JC_Fs[i].ShapeCopy, temp_De.GCDataList[0].Shape))
{ JC_Fs.Remove(JC_Fs[i]); i--; length--; }//剔除边界压盖基础图斑
}
}
temp_De.SetAttribure(JC_Fs[0], jc_FieldsIndex);//还原更新数据为基础数据属性
temp_De.GCDataList[0].SetBGHAttribure(temp_De);//对应过程数据还原为基础图斑
temp_De.GCDataList[0].SetBGQAttribure(JC_Fs[0], gxgc_FieldsIndex);//对应过程数据还原为基础图斑
//当前更新图斑与基础图斑边界保持一致,直接删除
if (FeatureAPI.IsContains(DeleGX_f.ShapeCopy, JC_Fs[0].ShapeCopy) || FeatureAPI.GetEqual(DeleGX_f.ShapeCopy, JC_Fs[0].ShapeCopy))
{
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = DeleGX_f.OID, MsgType = "RefreshViewAttrTable", Extend = "DelDataByOID" });
DeleGX_f.Delete();
tableGC.DeleteSearchedRows(queryFilter);
return;
}
else if (FeatureAPI.IsContains(JC_Fs[0].ShapeCopy, DeleGX_f.ShapeCopy) && !FeatureAPI.GetEqual(DeleGX_f.ShapeCopy, JC_Fs[0].ShapeCopy))
{
List GX_Fs = FeatureAPI.Identify(DeleGX_f.ShapeCopy, _curDLTBGX_FL);
foreach (IFeature ZBGX_Fitem in GX_Fs)
{
if (ZBGX_Fitem.OID == DeleGX_f.OID) continue;
if (!FeatureAPI.IsContains(JC_Fs[0].ShapeCopy, ZBGX_Fitem.ShapeCopy)) continue;
DLTBGXAttribute tempgx = new DLTBGXAttribute(gx_FieldsIndex);
tempgx.SetAttribure(ZBGX_Fitem, gx_FieldsIndex);//周边更新数据属性
tempgx.Shape2 = ZBGX_Fitem.ShapeCopy;
if (temp_De.IsEqual(tempgx))//存在周边更新图斑与基础图斑一致时,才删除当前更新数据
{
tempgx.GCDataList.AddRange(GetDLTBGXGCs(tempgx, ZBGX_Fitem));
foreach (DLTBGXGCAttribute GC_item in temp_De.GCDataList)
{
//验证数据的准确性
DLTBGXGCAttribute dLTBGXGC = tempgx.GCDataList.FirstOrDefault(x => x.FieldsValue["BGQTBBSM"].ToString() == JC_Fs[0].Value[JCBSMGXIndex].ToString());
if (dLTBGXGC != null)
{
temp_De.IsUpdate = true;
temp_De.BSM = "";
GC_item.BGMJ += dLTBGXGC.BGMJ;
GC_item.Shape = FeatureAPI.Union(GC_item.Shape, dLTBGXGC.Shape);
queryFilter.WhereClause = string.Format("BGHTBBSM='{0}'", ZBGX_Fitem.Value[BSMGXIndex].ToTrim());
tableGC.DeleteSearchedRows(queryFilter);
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = ZBGX_Fitem.OID, MsgType = "RefreshViewAttrTable", Extend = "DelDataByOID" });
ZBGX_Fitem.Delete();
}
}
}
}
if (temp_De.IsUpdate == true)//存在合并状况
{
queryFilter.WhereClause = string.Format("BGHTBBSM='{0}'", DeleGX_f.Value[BSMGXIndex].ToTrim());
tableGC.DeleteSearchedRows(queryFilter);
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = DeleGX_f.OID, MsgType = "RefreshViewAttrTable", Extend = "DelDataByOID" });
DeleGX_f.Delete();
if (string.IsNullOrWhiteSpace(MaxBSM))
MaxBSM = GetMaxBSM(new List() { _curDLTBGX_FL.FeatureClass, _curDLTBGXGC_FL.FeatureClass });
//与基础图斑边界一致,默认还原变更
if (!FeatureAPI.GetEqual(temp_De.Shape, JC_Fs[0].ShapeCopy))
{
InsertGXFeature(temp_De, _curDLTBGX_FL);
foreach (DLTBGXGCAttribute GCItem in temp_De.GCDataList)
{
InsertGXGCFeature(GCItem, temp_De, _curDLTBGXGC_FL);
}
}
}
else//仅当前更新数据及变更层作修改
{
UpdateGXFeature(DeleGX_f, temp_De, false);
foreach (DLTBGXGCAttribute GCItem in temp_De.GCDataList)
{
IFeature feature = _curDLTBGXGC_FL.FeatureClass.GetFeature(GCItem.UpdateOID);
UpdateGCFeature(feature, GCItem);
}
}
}
}
else
{
//存储周边更新数据改的
List NewGXAtts = new List();//被修改的图斑
List OldZBGXGCAtts = new List();//被合并的图斑
DLTBGXAttribute temp_DelPart = new DLTBGXAttribute(gx_FieldsIndex);
temp_DelPart.Shape2 = DeleGX_f.ShapeCopy;//增量数据
temp_DelPart.GCDataList.AddRange(GetDLTBGXGCs(temp_DelPart, DeleGX_f));
foreach (DLTBGXGCAttribute DelGCAttriitem in temp_DelPart.GCDataList)
{
List JCFsByGC = FeatureAPI.Identify(DelGCAttriitem.Shape, jcdltb_Layer);
if (JCFsByGC != null && JCFsByGC.Count != 0)//过程层只能压盖到对应的基础图斑
{
int length = JCFsByGC.Count;
for (int i = 0; i < length; i++)
{
if (JCFsByGC[i].Value[JCBSMGXIndex].ToString().Trim() != DelGCAttriitem.FieldsValue["BGQTBBSM"].ToString())
{ JCFsByGC.Remove(JCFsByGC[i]); i--; length--; }//剔除边界压盖基础图斑
}
DLTBGXAttribute NewGXAttribute = new DLTBGXAttribute(gx_FieldsIndex);
NewGXAttribute.SetAttribure(JCFsByGC[0], jc_FieldsIndex);
List ZBGCs = FeatureAPI.Identify(DelGCAttriitem.Shape, _curDLTBGXGC_FL);
foreach (IFeature ZBGC_Fitem in ZBGCs)
{
if (DelGCAttriitem.UpdateOID == ZBGC_Fitem.OID)
{
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = ZBGC_Fitem.OID, MsgType = "RefreshViewAttrTable", Extend = "DelDataByOID" });
ZBGC_Fitem.Delete();
continue;
}
DLTBGXGCAttribute dLTBGXGC = new DLTBGXGCAttribute(gxgc_FieldsIndex);//ZB
dLTBGXGC.SetAttribure(ZBGC_Fitem, gxgc_FieldsIndex);
dLTBGXGC.Shape = ZBGC_Fitem.ShapeCopy;
if (JCFsByGC[0].Value[JCBSMGXIndex].ToString().Trim() != dLTBGXGC.FieldsValue["BGQTBBSM"].ToString()) continue;
//if (!FeatureAPI.IsContains(JCFsByGC[0].ShapeCopy, ZBGC_Fitem.ShapeCopy)) continue;
//temp_DelPart.SetAttribure(JCFsByGC[0], jc_FieldsIndex);
double GCBGMJ = DelGCAttriitem.BGMJ;//还原之前的过程图斑面积
DelGCAttriitem.SetBGHAttribure(JCFsByGC[0], jc_FieldsIndex);
if (dLTBGXGC.BGHAttribureIsEqual(DelGCAttriitem))//相邻的过程层属性一致
{
DelGCAttriitem.Shape = FeatureAPI.Union(dLTBGXGC.Shape, DelGCAttriitem.Shape);
DelGCAttriitem.BGMJ += dLTBGXGC.BGMJ;
DelGCAttriitem.IsUpdate = true;
NewGXAttribute.Shape2 = DelGCAttriitem.Shape;
NewGXAttribute.TBMJ += DelGCAttriitem.BGMJ;
NewGXAttribute.BSM = "";
NewGXAttribute.GCDataList.Add(DelGCAttriitem);
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = ZBGC_Fitem.OID, MsgType = "RefreshViewAttrTable", Extend = "DelDataByOID" });
ZBGC_Fitem.Delete();
OldZBGXGCAtts.Add(dLTBGXGC);//参与合并,
}
else
{
NewGXAttribute.Shape2 = DelGCAttriitem.Shape;//最开始的图形赋值
NewGXAttribute.GCDataList.Add(DelGCAttriitem);//本身作为被动变更
}
}
if (NewGXAttribute.GCDataList.Count != 0)
{
if (!FeatureAPI.GetEqual(NewGXAttribute.Shape, JCFsByGC[0].ShapeCopy))
{
NewGXAtts.Add(NewGXAttribute);//还原为基础图斑属性(无论修改,覆盖/未改变)
}
}
}
}
if (string.IsNullOrWhiteSpace(MaxBSM) && NewGXAtts.Count != 0)
MaxBSM = GetMaxBSM(new List() { _curDLTBGX_FL.FeatureClass, _curDLTBGXGC_FL.FeatureClass });
foreach (DLTBGXAttribute GXItem in NewGXAtts)
{
InsertGXFeature(GXItem, _curDLTBGX_FL);
foreach (DLTBGXGCAttribute GCItem in GXItem.GCDataList)
{
InsertGXGCFeature(GCItem, GXItem, _curDLTBGXGC_FL);
}
}
foreach (DLTBGXGCAttribute item in OldZBGXGCAtts)
{
queryFilter.WhereClause = string.Format("BSM='{0}'", item.BGHTBBSM);
IFeatureCursor featureCursor = _curDLTBGX_FL.FeatureClass.Update(queryFilter, false);
IFeature feature = null;
if ((feature = featureCursor.NextFeature()) != null)
{
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = feature.OID, MsgType = "RefreshViewAttrTable", Extend = "DelDataByOID" });
feature.Delete();
}
}
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = DeleGX_f.OID, MsgType = "RefreshViewAttrTable", Extend = "DelDataByOID" });
DeleGX_f.Delete();
}//默认不存在压盖不到基础图斑
this.CloseLoading();
refresh.OnClick();
MessageHelper.ShowTips("增量数据还原成功!");
}
}
catch (Exception ex)
{
LogAPI.Debug("增量数据更新还原失败,原因如下:");
LogAPI.Debug(ex);
this.CloseLoading();
MessageHelper.ShowTips("增量数据更新还原失败,请重新选择!");
}
finally
{
this.CloseLoading();
SaveFeatureOID = -1;
_FeatureInfo.BindData(_curDLTBGX_FL.FeatureClass.CreateFeatureBuffer() as IFeature);
}
}
private List GetDLTBGXGCs(DLTBGXAttribute DLTBGXAttribute, IFeature Temp_F)
{
List TempGCs = new List();
int indexGX = _curDLTBGX_FL.FeatureClass.FindField("BSM");
IQueryFilter queryFilter = new QueryFilterClass
{
WhereClause = string.Format("BGHTBBSM='{0}'", Temp_F.Value[indexGX].ToTrim())
};
IFeatureCursor featureCursor_GC = _curDLTBGXGC_FL.FeatureClass.Update(queryFilter, false);
IFeature featureGC = null;//当前更新图斑对应过程层数据
while ((featureGC = featureCursor_GC.NextFeature()) != null)
{
DLTBGXGCAttribute TempGC = new DLTBGXGCAttribute(gxgc_FieldsIndex);
TempGC.SetAttribure(featureGC, gxgc_FieldsIndex);
TempGC.Shape = featureGC.ShapeCopy;
TempGC.UpdateOID = featureGC.OID;
TempGCs.Add(TempGC);
}
return TempGCs;
}
List gxDataList = null;
///
/// 过程层数据生成
///
///
///
///
///
///
///
///
private bool ExeZLDataGeneration(IFeature pGXFeature, IFeatureLayer pJC_Layer, IFeatureLayer pJC_Layer2, IFeatureLayer pGX_Layer, IFeatureLayer pGXGC_Layer, string pTempBSMPrefix)
{
bool result = false;
try
{
this.UpdateMsg("正在进行更新过程数据.......");
gxDataList = new List();
//获取更新数据过程数据
gxDataList = GetGXGCData2(pGXFeature, pJC_Layer, pGXGC_Layer, pGX_Layer);
gxDataList.ForEach(x => x.TBMJ = x.GCDataList.Sum(k => k.BGMJ));//平差后的过程面积求和
try
{
//修改更新数据
foreach (DLTBGXAttribute pGXData in gxDataList)
{
if (pGXData.IsAdd == true)//产生多环图形,全部按照新增操作
{
InsertGXFeature(pGXData, pGX_Layer, false);
continue;
}
IFeature featureGX = null;
try
{
featureGX = pGX_Layer.FeatureClass.GetFeature(pGXData.InheritOID);
}
catch (Exception)
{
InsertGXFeature(pGXData, pGX_Layer, false);
continue;
}
if (featureGX != null)
{
featureGX.Shape = pGXData.Shape;
foreach (var fieldName in gx_FieldsIndex.Keys)
{
if (fieldName == "TBMJ")
{
featureGX.Value[gx_FieldsIndex[fieldName]] = pGXData.TBMJ;
continue;
}
if (fieldName == "YSDM")
{
featureGX.Value[gx_FieldsIndex[fieldName]] = "2001010100";
continue;
}
if (fieldName == "TBBH")
{
featureGX.Value[gx_FieldsIndex[fieldName]] = pGXData.FieldsValue[fieldName];
continue;
}
if (fieldName == "TBDLMJ")
{
double dKCMJ_Temp = Math.Round(pGXData.TBMJ * pGXData.KCXS, 2);
featureGX.Value[gx_FieldsIndex[fieldName]] = Math.Round(pGXData.TBMJ - dKCMJ_Temp, 2);
continue;
}
featureGX.Value[gx_FieldsIndex[fieldName]] = pGXData.FieldsValue[fieldName];
}
featureGX.Store();
}
}
//最终数据和基础图标一致,则做清除,反之插入数据;(不放在添加前判断,是先获取逻辑过程数据,作为数据验证)
foreach (DLTBGXAttribute gx in gxDataList)
{
foreach (var gxgc in gx.GCDataList)
{
if (gxgc.BGXW == "1")
{
IQueryFilter queryFilter = new QueryFilterClass
{
WhereClause = string.Format("BSM='{0}'", gxgc.BGHTBBSM)
};
IFeatureCursor featureCursor = jcdltb_Layer.FeatureClass.Search(queryFilter, true);
IFeature jc = featureCursor.NextFeature();
DLTBGXAttribute jcData = new DLTBGXAttribute(gx_FieldsIndex);
jcData.SetAttribure(jc, jc_FieldsIndex);
if (gx.IsEqual(jcData))
{
queryFilter.WhereClause = string.Format("BSM='{0}'", gxgc.BGHTBBSM);
featureCursor = pGX_Layer.FeatureClass.Update(queryFilter, true);
IFeature featureGX = featureCursor.NextFeature();
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = featureGX.OID, MsgType = "RefreshViewAttrTable", Extend = "DelDataByOID" });
featureGX.Delete();
featureCursor.Flush();
continue;
}
}
int oid = InsertGXGCFeature(gxgc, gx, pGXGC_Layer);
LogAPI.Debug("增量数据变更-插入过程数据OID:" + oid);
}
}
}
catch (Exception ex)
{
LogAPI.Debug("增量数据变更-过程数据生成异常:" + ex.Message);
LogAPI.Debug(ex);
}
result = true;
}
catch (Exception ex)
{
LogAPI.Debug("图斑变更发生异常!异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("异常信息结束");
}
return result;
}
#region 获取最新标识码
private string GetMaxBSM(List fcList)
{
//System.Windows.Forms.Application.DoEvents();
int xh = 0;
string MaxBSM = "";
string leftStr = string.Empty;
foreach (var fc in fcList)
{
string BSM = string.Empty;
int BSMIndex = fc.FindField("BSM");
if (BSMIndex == -1) return BSM;
ITable table = (ITable)fc;
// 创建一个ITableSort接口对象
ITableSort tableSort = new TableSortClass
{
Table = table,
Fields = "BSM"
};
tableSort.set_Ascending("BSM", false);
tableSort.Sort(null);
ICursor cursor = tableSort.Rows;
IRow row = cursor.NextRow();
if (row != null)
{
int maxBSM = 0;
int currBSM = 0;
string BSMStr = row.Value[BSMIndex].ToString();
if (BSMStr.Length != 18 && !string.IsNullOrWhiteSpace(BSMStr.Trim())) return BSM;
if (string.IsNullOrWhiteSpace(BSMStr)) continue;
string subBSMStr = BSMStr.Substring(9);
try
{
currBSM = Convert.ToInt32(subBSMStr);
}
catch (Exception)
{
return BSM;
}
if (currBSM > maxBSM) maxBSM = currBSM;
if (BSMStr.Length != 18) return BSM;
string maxStr = maxBSM.ToString();
int zeroNum = 9 - maxStr.Length;
for (int i = 0; i < zeroNum; i++)
{
maxStr = 0 + maxStr;
}
BSM = BSMStr.Substring(0, 9) + maxStr;
}
if (BSM.Length != 18)
continue;
int xh2 = Convert.ToInt32(BSM.Substring(10));
leftStr = BSM.Substring(0, 10);
if (xh < xh2)
{
xh = xh2;
MaxBSM = BSM;
}
}
return MaxBSM;
}
#endregion
public void UpdateGXFeature(IFeature pFeature, DLTBGXAttribute pData, bool IsUpdateBSM = false)
{
try
{
pFeature.Shape = pData.Shape;
foreach (var key in pData.FieldsIndex.Keys)
{
if (pData.FieldsValue == null)
{
break;
}
if (key == "JCTBBSM")
continue;
if (key == "BSM" && IsUpdateBSM == false)
continue;
if (key == "TBBH")
{
pFeature.Value[pData.FieldsIndex[key]] = pData.TBBH;
continue;
}
if (key == "SJNF")
{
pFeature.Value[pData.FieldsIndex[key]] = "2023";
continue;
}
if (key == "TBMJ")
{
pFeature.Value[pData.FieldsIndex[key]] = pData.TBMJ;
continue;
}
if (key == "BGTBOID")
{
pFeature.Value[pData.FieldsIndex[key]] = pData.BGTBOID;
continue;
}
if (key == "YSDM")
{
pFeature.Value[pData.FieldsIndex[key]] = "2001010100";
continue;
}
if (key == "GXSJ")
{
pFeature.Value[pData.FieldsIndex[key]] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31);
continue;
}
if (pData.FieldsValue.Keys.Contains(key))
{
pFeature.Value[pData.FieldsIndex[key]] = pData.FieldsValue[key];
}
}
}
catch (Exception ex)
{
LogAPI.Debug("更新地类团更新数据异常:" + ex);
LogAPI.Debug("更新地类团更新数据异常:" + ex.Message);
LogAPI.Debug("更新地类团更新数据异常:" + ex.StackTrace);
throw ex;
}
}
public void UpdateGCFeature(IFeature pFeature, DLTBGXGCAttribute pData)
{
try
{
pFeature.Shape = pData.Shape;
foreach (var key in pData.FieldsIndex.Keys)
{
if (pData.FieldsValue == null)
{
break;
}
if (key == "JCTBBSM")
continue;
if (key == "SJNF")
{
pFeature.Value[pData.FieldsIndex[key]] = "2022";
continue;
}
if (key == "TBMJ")
{
pFeature.Value[pData.FieldsIndex[key]] = pData.BGMJ;
continue;
}
if (key == "BGTBOID")
{
pFeature.Value[pData.FieldsIndex[key]] = pData.BGTBOID;
continue;
}
if (key == "YSDM")
{
pFeature.Value[pData.FieldsIndex[key]] = "2001010100";
continue;
}
if (key == "GXSJ")
{
pFeature.Value[pData.FieldsIndex[key]] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31);
continue;
}
if (pData.FieldsValue.Keys.Contains(key))
{
pFeature.Value[pData.FieldsIndex[key]] = pData.FieldsValue[key];
}
}
}
catch (Exception ex)
{
LogAPI.Debug("更新过程数据异常:" + ex);
LogAPI.Debug("更新过程数据异常:" + ex.Message);
LogAPI.Debug("更新过程数据异常:" + ex.StackTrace);
throw ex;
}
}
///
/// 插入更新层数据
///
///
///
///
public void InsertGXFeature(DLTBGXAttribute pGXData, IFeatureLayer pGX_Layer, bool isUpdateTBBH = false)
{
IFeatureCursor updateCursor = null;
IFeatureCursor gx_cursor = null;
IFeatureBuffer gx_buffer = null;
try
{
if (pGXData.GCDataList.Count == 1)
{
//新增不需要合并的,判断BSM是否为空,为空认为是图形变更,需进行重新编号
if (string.IsNullOrWhiteSpace(pGXData.BSM))
{
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9));
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
pGXData.BSM = MaxBSM;
pGXData.GCDataList[0].BGHTBBSM = pGXData.BSM;
pGXData.GCDataList[0].BGHTBBH = pGXData.TBBH;
}
}
else if (pGXData.GCDataList.Count > 1)
{
//新增需要合并的,认为图形变更
if (string.IsNullOrWhiteSpace(pGXData.BSM))
{
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9));
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
pGXData.BSM = MaxBSM;
pGXData.GCDataList.ForEach(f => { f.BGXW = "2"; f.BGHTBBSM = pGXData.BSM; });
}
}
else
{
return;
}
gx_cursor = pGX_Layer.FeatureClass.Insert(true);
gx_buffer = pGX_Layer.FeatureClass.CreateFeatureBuffer();
gx_buffer.Shape = pGXData.Shape;
foreach (var fieldName in gx_FieldsIndex.Keys)
{
if (fieldName == "TBMJ")
{
gx_buffer.Value[gx_FieldsIndex[fieldName]] = pGXData.TBMJ;
continue;
}
if (fieldName == "GXSJ")
{
gx_buffer.Value[gx_FieldsIndex[fieldName]] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31);
continue;
}
if (fieldName == "TBBH")
{
if (pGXData.GCDataList.Count == 1 && pGXData.GCDataList[0].BGXW == "1")
{
if (!isUpdateTBBH)
{
if (!string.IsNullOrWhiteSpace(pGXData.GCDataList[0].BGHTBBH))
gx_buffer.Value[gx_FieldsIndex[fieldName]] = pGXData.GCDataList[0].BGHTBBH;
else
gx_buffer.Value[gx_FieldsIndex[fieldName]] = pGXData.FieldsValue[fieldName];
}
else
{
gx_buffer.Value[gx_FieldsIndex[fieldName]] = pGXData.FieldsValue[fieldName];
}
}
else
{
gx_buffer.Value[gx_FieldsIndex[fieldName]] = pGXData.FieldsValue[fieldName];
}
continue;
}
if (fieldName == "YSDM")
{
gx_buffer.Value[gx_FieldsIndex[fieldName]] = "2001010100";
continue;
}
if (fieldName == "SJNF")
{
gx_buffer.Value[gx_FieldsIndex[fieldName]] = "2022";
continue;
}
if (fieldName == "KCMJ")
{
gx_buffer.Value[gx_FieldsIndex[fieldName]] = Math.Round(pGXData.TBMJ * pGXData.KCXS, 2);
continue;
}
if (fieldName == "TBDLMJ")
{
double dKCMJ_Temp = Math.Round(pGXData.TBMJ * pGXData.KCXS, 2);
gx_buffer.Value[gx_FieldsIndex[fieldName]] = Math.Round(pGXData.TBMJ - dKCMJ_Temp, 2);
continue;
}
if (fieldName == "BGTBOID")
{
gx_buffer.Value[gx_FieldsIndex[fieldName]] = pGXData.BGTBOID;
continue;
}
if (pGXData.FieldsValue.Keys.Contains(fieldName))
gx_buffer.Value[gx_FieldsIndex[fieldName]] = pGXData.FieldsValue[fieldName];
}
object oid = gx_cursor.InsertFeature(gx_buffer);
gx_cursor.Flush();
pGXData.OID = Convert.ToInt32(oid);
Marshal.ReleaseComObject(gx_buffer);
}
catch (Exception ex)
{
LogAPI.Debug("写入更新层数据时发生异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("异常信息结束");
}
finally
{
if (updateCursor != null)
Marshal.ReleaseComObject(updateCursor);
if (gx_cursor != null)
Marshal.ReleaseComObject(gx_cursor);
if (gx_buffer != null)
Marshal.ReleaseComObject(gx_buffer);
}
}
public int InsertGXGCFeature(DLTBGXGCAttribute pGxgc, DLTBGXAttribute pGx, IFeatureLayer pFC)
{
IFeatureCursor gxgc_cursor = null;
IFeatureBuffer gxgc_buffer = null;
try
{
gxgc_cursor = pFC.FeatureClass.Insert(true);
gxgc_buffer = pFC.FeatureClass.CreateFeatureBuffer();
gxgc_buffer.Shape = pGxgc.Shape;
foreach (var fieldName in gxgc_FieldsIndex.Keys)
{
if (fieldName == "BSM")
{
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9));
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
gxgc_buffer.Value[gxgc_FieldsIndex[fieldName]] = MaxBSM;
continue;
}
if (fieldName == "TBBGMJ")
{
gxgc_buffer.Value[gxgc_FieldsIndex[fieldName]] = pGxgc.BGMJ;
continue;
}
if (fieldName == "BGXW")
{
gxgc_buffer.Value[gxgc_FieldsIndex[fieldName]] = pGxgc.BGXW;
continue;
}
if (fieldName == "GXSJ")
{
gxgc_buffer.Value[gxgc_FieldsIndex[fieldName]] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31);
continue;
}
if (fieldName == "BGTBOID")
{
gxgc_buffer.Value[gxgc_FieldsIndex[fieldName]] = pGxgc.BGTBOID;
continue;
}
if (fieldName == "BGHTBBSM")
{
gxgc_buffer.Value[gxgc_FieldsIndex[fieldName]] = pGx.BSM;
continue;
}
if (pGxgc.FieldsValue.Keys.Contains(fieldName) && fieldName.Contains("BGH") && pGx.FieldsValue.ContainsKey(GetRemovePrefixString(fieldName, "BGH")))
{
gxgc_buffer.Value[gxgc_FieldsIndex[fieldName]] = pGx.FieldsValue[GetRemovePrefixString(fieldName, "BGH")];
}
if (pGxgc.FieldsValue.Keys.Contains(fieldName) && !fieldName.Contains("BGH"))
gxgc_buffer.Value[gxgc_FieldsIndex[fieldName]] = pGxgc.FieldsValue[fieldName];
}
#region 变更前_面积维护
double kcxs = 0;
//获取变更前扣除系数
int buffer_F_Index = gxgc_buffer.Fields.FindField("BGQKCXS");
if (buffer_F_Index != -1)
{
if (!(gxgc_buffer.Value[buffer_F_Index] is DBNull))
kcxs = (double)gxgc_buffer.Value[buffer_F_Index];
}
//变更前扣除面积
double kcmj = 0;
buffer_F_Index = gxgc_buffer.Fields.FindField("BGQKCMJ");
if (buffer_F_Index != -1)
{
kcmj = Math.Round(pGxgc.BGMJ * kcxs, 2);
gxgc_buffer.Value[buffer_F_Index] = kcmj;
}
//变更前图斑地类面积
buffer_F_Index = gxgc_buffer.Fields.FindField("BGQTBDLMJ");
if (buffer_F_Index != -1)
{
gxgc_buffer.Value[buffer_F_Index] = pGxgc.BGMJ - kcmj;
}
#endregion
#region 变更后_面积维护
kcxs = 0;
//获取变更后扣除系数
buffer_F_Index = gxgc_buffer.Fields.FindField("BGHKCXS");
if (buffer_F_Index != -1)
{
if (!(gxgc_buffer.Value[buffer_F_Index] is DBNull))
kcxs = (double)gxgc_buffer.Value[buffer_F_Index];
}
//变更后扣除面积
kcmj = 0;
buffer_F_Index = gxgc_buffer.Fields.FindField("BGHKCMJ");
if (buffer_F_Index != -1)
{
kcmj = Math.Round(pGxgc.BGMJ * kcxs, 2);
gxgc_buffer.Value[buffer_F_Index] = kcmj;
}
//变更后图斑地类面积
buffer_F_Index = gxgc_buffer.Fields.FindField("BGHTBDLMJ");
if (buffer_F_Index != -1)
{
gxgc_buffer.Value[buffer_F_Index] = pGxgc.BGMJ - kcmj;
}
#endregion
object oid = gxgc_cursor.InsertFeature(gxgc_buffer);
gxgc_cursor.Flush();
Marshal.ReleaseComObject(gxgc_buffer);
return (int)oid;
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
throw;
}
finally
{
if (gxgc_cursor != null)
Marshal.ReleaseComObject(gxgc_cursor);
}
}
private bool BGQ_BGH_AttrEqual(IFeature pf, ref string UnEqualAttr)
{
bool result = true;
for (int i = 0; i < pf.Fields.FieldCount; i++)
{
IField field = pf.Fields.Field[i];
if ("BSM".Contains(field.Name.ToUpper()) || field.Name.ToUpper().Contains("MJ")) continue;
int bghIdx = pf.Fields.FindField(field.Name.Replace("BGQ", "BGH"));
if (bghIdx == -1) continue;
if ("BGQTBBSM,BGQTBBH,BGQZLDWDM,BGQZLDWMC,BGQQSDWDM,BGQQSDWMC".Contains(field.Name.ToUpper()))
{
if (pf.Value[i].ToTrim() != pf.Value[bghIdx].ToTrim())
{
UnEqualAttr += field.Name.ToUpper() + ",";
}
continue;
}
if (!Equals(pf.Value[i].ToTrim(), pf.Value[bghIdx].ToTrim()))
{
result = false;
break;
}
}
return result;
}
///
/// 移除前缀字符串
///
///原字符串
///前缀字符串
///
public string GetRemovePrefixString(string val, string str)
{
string strRegex = @"^(" + str + ")";
return Regex.Replace(val, strRegex, "");
}
///
/// 获取更新过程数据
///
/// 勾选得变更数据
/// 基础_地类图斑/行政区调整前基础图斑
/// 地类图斑更新过程层
/// 地类图斑更新层
///
private List GetGXGCData2(IFeature pGXFeature, IFeatureLayer pJC_Layer, IFeatureLayer pGXGC_Layer, IFeatureLayer pGX_Layer)
{
try
{
//当前更新图斑pGXFeature
DLTBGXAttribute Save_GXData = new DLTBGXAttribute(gx_FieldsIndex);
Save_GXData.SetAttribure(pGXFeature);
Save_GXData.InheritOID = pGXFeature.OID;
Save_GXData.Shape2 = pGXFeature.ShapeCopy;
IQueryFilter queryFilter = new QueryFilterClass();
ITable tableGXGC = pGXGC_Layer.FeatureClass as ITable;
int BSMGXIndex = pGX_Layer.FeatureClass.FindField("BSM");
#region 从更新层里判断(判断该图斑是否压盖其他更新图斑)
List gx_Features = FeatureAPI.Identify(pGXFeature.ShapeCopy, pGX_Layer);
if (gx_Features.Count != 0)
{
foreach (var gxItem_ZB in gx_Features)//ZB-周边
{
if (gxItem_ZB.OID == pGXFeature.OID) continue;//压盖到自身
DLTBGXAttribute tempGX_ZB = new DLTBGXAttribute(gx_FieldsIndex)
{
UpdateOID = gxItem_ZB.OID,
InheritOID = gxItem_ZB.OID,
IsUpdate = true
};
tempGX_ZB.SetAttribure(gxItem_ZB);
tempGX_ZB.Shape2 = gxItem_ZB.ShapeCopy;
if (FeatureAPI.IsAdjacent(gxItem_ZB.ShapeCopy, pGXFeature.ShapeCopy))
{
if (tempGX_ZB.IsEqual(Save_GXData))//是否相邻比对属性数据
{
queryFilter.WhereClause = string.Format("BGHTBBSM='{0}'", gxItem_ZB.Value[BSMGXIndex].ToString().Trim());
tableGXGC.DeleteSearchedRows(queryFilter);
gxItem_ZB.Delete();//合并周边更新图斑(过程层?删除)
Save_GXData.Shape2 = FeatureAPI.Union(tempGX_ZB.Shape2, Save_GXData.Shape2);
Save_GXData.TBMJ += tempGX_ZB.TBMJ;
}
}
else if (FeatureAPI.IsContains(pGXFeature.ShapeCopy, gxItem_ZB.ShapeCopy))
{
queryFilter.WhereClause = string.Format("BGHTBBSM='{0}'", gxItem_ZB.Value[BSMGXIndex].ToString().Trim());
tableGXGC.DeleteSearchedRows(queryFilter);
gxItem_ZB.Delete();
}
else if (FeatureAPI.IsInterSect(gxItem_ZB.ShapeCopy, pGXFeature.ShapeCopy))
{
if (tempGX_ZB.IsEqual(Save_GXData))//相交且属性相同
{
Save_GXData.Shape2 = FeatureAPI.Union(tempGX_ZB.Shape2, Save_GXData.Shape2);
Save_GXData.TBMJ += tempGX_ZB.TBMJ;
queryFilter.WhereClause = string.Format("BGHTBBSM='{0}'", gxItem_ZB.Value[BSMGXIndex].ToString().Trim());
tableGXGC.DeleteSearchedRows(queryFilter);
gxItem_ZB.Delete();
}
else
{
tempGX_ZB.Shape2 = FeatureAPI.Difference(tempGX_ZB.Shape2, Save_GXData.Shape2);//留存的部分
if (!tempGX_ZB.Shape2.IsEmpty)
{
List subGX_Items = FeatureAPI.DissolveGeometryByRing(tempGX_ZB.Shape2);
foreach (var item in subGX_Items)
{
if (subGX_Items.IndexOf(item) == 0)
{
tempGX_ZB.Shape2 = item;
tempGX_ZB.InheritOID = gxItem_ZB.OID;
gxDataList.Add(tempGX_ZB);
continue;
}
tempGX_ZB = new DLTBGXAttribute(gx_FieldsIndex);
tempGX_ZB.SetAttribure(gxItem_ZB);
tempGX_ZB.Shape2 = item;
tempGX_ZB.IsAdd = true;
gxDataList.Add(tempGX_ZB);
}
}
}
}
}
}
gxDataList.Add(Save_GXData);//若是更新层没有数据
foreach (DLTBGXAttribute gxItem in gxDataList)//当前更新层周边基础库(未发生变更的),是否产生合并情况
{
List jc_Features = FeatureAPI.Identify(gxItem.Shape2, pJC_Layer);
foreach (var jc in jc_Features)
{
DLTBGXAttribute jcData = new DLTBGXAttribute(gx_FieldsIndex);
jcData.SetAttribure(jc, jc_FieldsIndex);
if (FeatureAPI.IsAdjacent(gxItem.Shape2, jc.ShapeCopy))
{
if (gxItem.IsEqual(jcData))
{
List list = FeatureAPI.Identify2(jc.ShapeCopy, pGX_Layer);
if (list.Count > 0) continue;
gxItem.Shape2 = FeatureAPI.Union(gxItem.Shape2, jc.ShapeCopy);
}
}
}
}
List newGXDataList = new List();
//压盖到其他更新图斑,经过一系列操作,产生新的更新图斑(被动变更)
foreach (DLTBGXAttribute gxItem in gxDataList)//根据更新图斑获取更新过程数据
{
gxItem.GCDataList.AddRange(GetGXGCData(gxItem, gxItem.Shape2, pGXGC_Layer, pJC_Layer, ref newGXDataList));//已存在的过程数据
if (gxItem.Shape == null)//从基础库获取过程数据
{
gxItem.GCDataList.AddRange(GetGXGCDataForJCLayer(gxItem, gxItem.Shape2, pJC_Layer, ref newGXDataList));
}
IRelationalOperator relational = gxItem.Shape as IRelationalOperator;
if (!relational.Equals(gxItem.Shape2))
{
List gcList = GetGXGCDataForJCLayer(gxItem, FeatureAPI.Difference(gxItem.Shape2, gxItem.Shape), pJC_Layer, ref newGXDataList);
foreach (var gc in gcList)
{
if (FeatureAPI.IsInterSect(gxItem.Shape, gc.Shape) || FeatureAPI.IsInterSect(gc.Shape, gxItem.Shape))
continue;
gxItem.GCDataList.Add(gc);
}
}
}
//擦除(更新)和相交(过程)的是否相交的部分
foreach (DLTBGXAttribute item in newGXDataList)
{
if (item.GCDataList.Count > 0)
{
if (gxDataList.FirstOrDefault(f => FeatureAPI.IsInterSect(f.Shape2, item.Shape)) == null)
{
gxDataList.Add(item);
}
}
}
#endregion
if (gxDataList.Count > 1)//多个更新数据
{
gxDataList = gxDataList.OrderByDescending(f => f.TBMJ).ToList();
List result = new List();
foreach (var item in gxDataList)
{
if (item.Shape == null)
continue;
if (item.GCDataList.Count == 1)//更新对应一个过程层
{
List jc_Features = new List();
jc_Features = FeatureAPI.Identify2(item.GCDataList[0].Shape, pJC_Layer);
if (jc_Features.Count == 1)
{
IRelationalOperator relational = item.GCDataList[0].Shape as IRelationalOperator;
if (relational.Equals(jc_Features[0].ShapeCopy))//属性变化(过程数据与基础库数据图形相同)
{
item.GCDataList[0].BGXW = "1";
item.BSM = jc_Features[0].Value[jc_Features[0].Fields.FindField("BSM")].ToTrim();
item.GCDataList[0].BGHTBBSM = item.BSM;
item.TBBH = jc_Features[0].Value[jc_Features[0].Fields.FindField("TBBH")].ToTrim();
result.Add(item);
continue;
}
}
}
ShapeInfo InterShape = new ShapeInfo(item.Shape);
DLTBAreaHandle InterHandle = new DLTBAreaHandle(InterShape);
List InterShapes = InterHandle.GetFeatures();
if (InterShapes.Count > 1)
{
foreach (var subItem in InterShapes)
{
DLTBGXAttribute gx = new DLTBGXAttribute(gx_FieldsIndex, item.GCDataList[0]);
if (InterShapes.IndexOf(subItem) == 0)
{
gx.UpdateOID = item.UpdateOID;
gx.IsUpdate = item.IsUpdate;
}
else
{
gx.IsUpdate = false;
}
gx.GCDataList.AddRange(item.GCDataList.FindAll(f => FeatureAPI.IsContains(subItem.Shape, f.Shape)));
gx.BSM = "";
gx.TBBH = "";
gx.GCDataList.ForEach(f =>
{
if (f.IsUpdate && !string.IsNullOrWhiteSpace(f.BGHTBBSM))
{
gx.TBBH = f.BGHTBBH;
gx.BSM = f.BGHTBBSM;
}
f.BGXW = "2";
});
if (string.IsNullOrWhiteSpace(gx.BSM))
{
gx.IsUpdate = false;
}
if (gx.GCDataList.Count > 1 && !gx.IsUpdate)
gx.BSM = "";
result.Add(gx);
}
}
else
{
if (result.Count == 0)
{
result.Add(item);
}
else
{
if (result.FirstOrDefault(f => FeatureAPI.IsContains(f.Shape, item.Shape)) != null)
{
continue;
}
else
{
if (result.FirstOrDefault(f => f.BSM == item.BSM) != null)
{
item.BSM = "";
item.GCDataList.ForEach(f => f.BGHTBBSM = "");
}
result.Add(item);
}
}
item.GCDataList.ForEach(f =>
{
f.BGHTBBH = item.TBBH;
f.BGHTBBSM = item.BSM;
f.BGXW = "2";
});
}
}
return result;
}
if (gxDataList.Count == 1)
{
if (gxDataList[0].GCDataList.Count == 1)
{
List jc_Features = new List();
jc_Features = FeatureAPI.Identify2(gxDataList[0].GCDataList[0].Shape, pJC_Layer);
if (jc_Features.Count == 1)
{
IRelationalOperator relational = gxDataList[0].GCDataList[0].Shape as IRelationalOperator;
if (relational.Equals(jc_Features[0].ShapeCopy))//属性变化(过程数据与基础库数据图形相同)
{
gxDataList[0].GCDataList[0].BGXW = "1";
gxDataList[0].BSM = jc_Features[0].Value[jc_Features[0].Fields.FindField("BSM")].ToTrim();
gxDataList[0].GCDataList[0].BGHTBBSM = gxDataList[0].BSM;
gxDataList[0].TBBH = jc_Features[0].Value[jc_Features[0].Fields.FindField("TBBH")].ToTrim();
}
else
{
gxDataList[0].GCDataList[0].BGHTBBSM = gxDataList[0].BSM;
gxDataList[0].GCDataList[0].BGXW = "2";
}
}
}
else
{
gxDataList[0].GCDataList.ForEach(f =>
{
f.BGXW = "2";
f.BGHTBBSM = gxDataList[0].BSM;
});
}
}
return gxDataList;
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
throw ex;
}
}
///
/// 获取字段名称及下标值
///
/// 要素类字段集合
///
private Dictionary GetFieldsIndex(IFields pFields)
{
Dictionary result = new Dictionary();
for (int i = 0; i < pFields.FieldCount; i++)
{
IField field = pFields.Field[i];
if (!field.Editable || field.Name.ToUpper().Contains("SHAPE") || field.Name.ToUpper() == "SJNF") continue;
result.Add(field.Name.ToUpper(), i);
Marshal.ReleaseComObject(field);
}
return result;
}
///
/// 从更新过程层获取过程数据
///
/// 勾选的变更数据
/// 变更图形
///
///
///
///
private List GetGXGCData(DLTBGXAttribute pBGFeature, IGeometry pGXShape, IFeatureLayer pGXGC_Layer, IFeatureLayer pJC_Layer, ref List newGXData)
{
List result = new List();
//foreach (var gx in newGXData)
int gxCount = newGXData.Count;
for (int num = 0; num < gxCount; num++)
{
var gx = newGXData[num];
foreach (var gc in gx.GCDataList)
{
if (FeatureAPI.IsContains(gc.Shape, pGXShape))
{
double jc_MJ = gc.BGMJ;
//相交部分图形
IGeometry IntersectGeo = FeatureAPI.InterSect(gc.Shape, pGXShape);
if (IntersectGeo.IsEmpty)
continue;
#region 图斑分割/合并/拆分多部件后进行面积平差
List Area_GXGCAttribure = new List();
ShapeInfo InterShape = new ShapeInfo(IntersectGeo);
DLTBAreaHandle InterHandle = new DLTBAreaHandle(InterShape);
List InterShapes = InterHandle.GetFeatures();
List areaOperationData = new List();
int id = 0;
foreach (var item in InterShapes)
{
id++;
item.ID = id;
areaOperationData.Add(item);
}
IGeometry DiffGeo = FeatureAPI.Difference(gc.Shape, pGXShape);
List DiffShapes = null;
if (DiffGeo != null && !DiffGeo.IsEmpty)
{
ShapeInfo DiffShape = new ShapeInfo(DiffGeo);
DLTBAreaHandle DiffHandle = new DLTBAreaHandle(DiffShape);
DiffShapes = DiffHandle.GetFeatures();
foreach (var item in DiffShapes)
{
id++;
item.ID = id;
areaOperationData.Add(item);
}
}
AreaAdjustment2(areaOperationData, jc_MJ);
foreach (var item in areaOperationData)
{
if (InterShapes != null)
{
if (InterShapes.FirstOrDefault(f => f.ID == item.ID) != null)
{
InterShapes.FirstOrDefault(f => f.ID == item.ID).SetArea(item.Area);
}
else if (DiffShapes != null)
{
if (DiffShapes.FirstOrDefault(f => f.ID == item.ID) != null)
{
DiffShapes.FirstOrDefault(f => f.ID == item.ID).SetArea(item.Area);
}
}
}
}
#endregion
for (int i = 0; i < InterShapes.Count; i++)
{
DLTBGXGCAttribute gxgc2 = new DLTBGXGCAttribute(gxgc_FieldsIndex);
gxgc2.SetBGQAttribure(gc);
gxgc2.SetBGHAttribure(pBGFeature);
gxgc2.BGMJ = InterShapes[i].Area;
if (i == 0)
{
gxgc2.Shape = InterShapes[i].Shape;
result.Add(gxgc2);
}
else
{
gc.BGMJ = InterShapes[i].Area;
gc.Shape = InterShapes[i].Shape;
}
}
if (DiffShapes != null)
{
for (int j = 0; j < DiffShapes.Count; j++)
{
if (j == 0)
{
gc.Shape = DiffShapes[j].Shape;
gc.BGMJ = DiffShapes[j].Area;
}
else
{
DLTBGXGCAttribute gxgc2 = new DLTBGXGCAttribute(gxgc_FieldsIndex);
gxgc2.SetBGQAttribure(gc);
gxgc2.SetBGHAttribure(pBGFeature);
gxgc2.Shape = DiffShapes[j].Shape;
gxgc2.BGMJ = DiffShapes[j].Area;
DLTBGXAttribute newGXData3 = new DLTBGXAttribute(gx_FieldsIndex, gxgc2)
{
BSM = gc.BGHTBBSM
};
newGXData3.GCDataList.Add(gxgc2);
newGXData.Add(newGXData3);
}
}
}
else
{
gx.GCDataList.Remove(gc);
}
break;
}
else if (FeatureAPI.GetEqual(gc.Shape, pGXShape) || FeatureAPI.IsContains(pGXShape, gc.Shape))
{
gc.SetBGHAttribure(pBGFeature);
result.Add(gc);
gx.GCDataList.Remove(gc);
break;
}
else
{
double jc_MJ = gc.BGMJ;
//相交部分图形
IGeometry IntersectGeo = FeatureAPI.InterSect(gc.Shape, pGXShape);
if (IntersectGeo.IsEmpty)
continue;
#region 图斑分割/合并/拆分多部件后进行面积平差
List Area_GXGCAttribure = new List();
ShapeInfo InterShape = new ShapeInfo(IntersectGeo);
DLTBAreaHandle InterHandle = new DLTBAreaHandle(InterShape);
List InterShapes = InterHandle.GetFeatures();
List areaOperationData = new List();
int id = 0;
foreach (var item in InterShapes)
{
id++;
item.ID = id;
areaOperationData.Add(item);
}
IGeometry DiffGeo = FeatureAPI.Difference(gc.Shape, pGXShape);
List DiffShapes = null;
if (DiffGeo != null && !DiffGeo.IsEmpty)
{
ShapeInfo DiffShape = new ShapeInfo(DiffGeo);
DLTBAreaHandle DiffHandle = new DLTBAreaHandle(DiffShape);
DiffShapes = DiffHandle.GetFeatures();
foreach (var item in DiffShapes)
{
id++;
item.ID = id;
areaOperationData.Add(item);
}
}
AreaAdjustment2(areaOperationData, jc_MJ);
foreach (var item in areaOperationData)
{
if (InterShapes != null)
{
if (InterShapes.FirstOrDefault(f => f.ID == item.ID) != null)
{
InterShapes.FirstOrDefault(f => f.ID == item.ID).SetArea(item.Area);
}
else if (DiffShapes != null)
{
if (DiffShapes.FirstOrDefault(f => f.ID == item.ID) != null)
{
DiffShapes.FirstOrDefault(f => f.ID == item.ID).SetArea(item.Area);
}
}
}
}
#endregion
for (int i = 0; i < InterShapes.Count; i++)
{
DLTBGXGCAttribute gxgc2 = new DLTBGXGCAttribute(gxgc_FieldsIndex);
gxgc2.SetBGQAttribure(gc);
gxgc2.SetBGHAttribure(pBGFeature);
gxgc2.BGMJ = InterShapes[i].Area;
if (i == 0)
{
IRelationalOperator relational = InterShapes[i].Shape as IRelationalOperator;
if (result.Count > 0)
{
bool x = false;
foreach (var item in result)
{
if (relational.Equals(item.Shape))
{
x = true;
}
}
if (!x)
{
gxgc2.Shape = InterShapes[i].Shape;
result.Add(gxgc2);
}
}
else
{
gxgc2.Shape = InterShapes[i].Shape;
result.Add(gxgc2);
}
}
else
{
gc.BGMJ = InterShapes[i].Area;
gc.Shape = InterShapes[i].Shape;
}
}
if (DiffShapes != null)
{
for (int j = 0; j < DiffShapes.Count; j++)
{
if (j == 0)
{
gc.Shape = DiffShapes[j].Shape;
gc.BGMJ = DiffShapes[j].Area;
}
else
{
DLTBGXGCAttribute gxgc2 = new DLTBGXGCAttribute(gxgc_FieldsIndex);
gxgc2.SetBGQAttribure(gc);
gxgc2.SetBGHAttribure(pBGFeature);
gxgc2.Shape = DiffShapes[j].Shape;
gxgc2.BGMJ = DiffShapes[j].Area;
DLTBGXAttribute newGXData3 = new DLTBGXAttribute(gx_FieldsIndex, gxgc2);
newGXData3.BSM = gc.BGHTBBSM;
newGXData3.GCDataList.Add(gxgc2);
newGXData.Add(newGXData3);
}
//gc.Shape = DiffShapes[j].Shape;
//gc.BGMJ = DiffShapes[j].Area;
}
}
break;
}
}
gxCount = newGXData.Count;
}
List gxgc_Features = FeatureAPI.Identify2(pGXShape, pGXGC_Layer);
foreach (IFeature gxgcItem in gxgc_Features)
{
if (result.FirstOrDefault(f => FeatureAPI.IsInterSect(f.Shape, gxgcItem.ShapeCopy)) != null)
{ gxgcItem.Delete(); continue; }//变更层生成更新层数据相交到过程层数据直接略过
DLTBGXGCAttribute gxgc = new DLTBGXGCAttribute(gxgc_FieldsIndex);
gxgc.SetAttribure(gxgcItem, gxgc_FieldsIndex);
gxgc.Shape = gxgcItem.ShapeCopy;
gxgc.IsUpdate = true;
gxgc.UpdateOID = gxgcItem.OID;
gxgc.BGMJ = gxgcItem.Value[gxgcItem.Fields.FindField("TBBGMJ")].ToDouble();
//扩张的更新数据
if (FeatureAPI.GetEqual(pGXShape, gxgcItem.ShapeCopy))
{//更新层与过程层图形是否相等/包含
List jc_Features = FeatureAPI.Identify2(pGXShape, pJC_Layer);
if (jc_Features.Count == 1 && FeatureAPI.Difference(jc_Features[0].ShapeCopy, gxgcItem.ShapeCopy).IsEmpty)
{
gxgc.BGHTBBSM = jc_Features[0].Value[jc_Features[0].Fields.FindField("BSM")].ToString();
gxgc.BGHTBBH = jc_Features[0].Value[jc_Features[0].Fields.FindField("TBBH")].ToString();
}
result.Add(gxgc);
}
else if (FeatureAPI.IsContains(pGXShape, gxgcItem.ShapeCopy))
{
List jc_Features = FeatureAPI.Identify2(gxgcItem.ShapeCopy, pJC_Layer);
IGeometry geomey = FeatureAPI.InterSect(jc_Features[0].ShapeCopy, pGXShape);
if (jc_Features.Count == 1 && !FeatureAPI.Difference(geomey, gxgcItem.ShapeCopy).IsEmpty)
{
gxgc.Shape = geomey;
gxgc.BGMJ = pBGFeature.TBMJ;
result.Add(gxgc);
}
else if (FeatureAPI.GetEqual(geomey, gxgcItem.ShapeCopy))
{
gxgc.BGMJ = pBGFeature.TBMJ;
gxgc.BGHTBBSM = pBGFeature.BSM;
result.Add(gxgc);
}
}
else
{
double jc_MJ = gxgc.BGMJ;
//相交部分图形
IGeometry IntersectGeo = FeatureAPI.InterSect(gxgcItem.ShapeCopy, pGXShape);
#region 图斑分割/合并/拆分多部件后进行面积平差
List Area_GXGCAttribure = new List();
ShapeInfo InterShape = new ShapeInfo(IntersectGeo);
DLTBAreaHandle InterHandle = new DLTBAreaHandle(InterShape);
List InterShapes = InterHandle.GetFeatures();
List areaOperationData = new List();
int id = 0;
foreach (var item in InterShapes)
{
id++;
item.ID = id;
areaOperationData.Add(item);
}
IGeometry DiffGeo = FeatureAPI.Difference(gxgcItem.ShapeCopy, pGXShape);
List DiffShapes = null;
if (DiffGeo != null && !DiffGeo.IsEmpty)
{
ShapeInfo DiffShape = new ShapeInfo(DiffGeo);
DLTBAreaHandle DiffHandle = new DLTBAreaHandle(DiffShape);
DiffShapes = DiffHandle.GetFeatures();
foreach (var item in DiffShapes)
{
id++;
item.ID = id;
areaOperationData.Add(item);
}
}
AreaAdjustment2(areaOperationData, jc_MJ);
foreach (var item in areaOperationData)
{
if (InterShapes != null)
{
if (InterShapes.FirstOrDefault(f => f.ID == item.ID) != null)
{
InterShapes.FirstOrDefault(f => f.ID == item.ID).SetArea(item.Area);
}
else if (DiffShapes != null)
{
if (DiffShapes.FirstOrDefault(f => f.ID == item.ID) != null)
{
DiffShapes.FirstOrDefault(f => f.ID == item.ID).SetArea(item.Area);
}
}
}
}
#endregion
for (int i = 0; i < InterShapes.Count; i++)
{
DLTBGXGCAttribute gxgc2 = new DLTBGXGCAttribute(gxgc_FieldsIndex);
gxgc2.SetAttribure(gxgcItem, gxgc_FieldsIndex);
gxgc2.SetBGHAttribure(pBGFeature);
gxgc2.BGMJ = InterShapes[i].Area;
gxgc2.Shape = InterShapes[i].Shape;
if (i == 0)
{
gxgc2.IsUpdate = true;
gxgc2.UpdateOID = gxgc.UpdateOID;
gxgc2.BGHTBBSM = gxgc.BGHTBBSM;
bool IsUnion = false;
foreach (DLTBGXGCAttribute itemGCNew in result)
{
if (FeatureAPI.IsAdjacent(itemGCNew.Shape, gxgc2.Shape) && itemGCNew.FieldsValue["BGQTBBSM"] == gxgc2.FieldsValue["BGQTBBSM"])
{
itemGCNew.UnionDLTBGXGCAttr(gxgc2);
IsUnion = true;
break;
}
}
if (IsUnion == false)
result.Add(gxgc2);
}
else
{
result.Add(gxgc2);
continue;
}
}
List jc_Features = FeatureAPI.Identify(gxgcItem.ShapeCopy, pJC_Layer);
for (int j = 0; j < DiffShapes.Count; j++)
{
IFeature GX_f = _curDLTBGX_FL.FeatureClass.GetFeature(SaveFeatureOID);
IFeature JC_F = jc_Features.FirstOrDefault(x => x.Value[pJC_Layer.FeatureClass.FindField("BSM")].ToString() == gxgc.FieldsValue["BGQTBBSM"].ToString());
if (JC_F == null || GX_f.Value[_curDLTBGX_FL.FeatureClass.FindField("BSM")].ToString() != pBGFeature.BSM) continue;
DLTBGXGCAttribute gxgc2 = new DLTBGXGCAttribute(gxgc_FieldsIndex);
//额外增量数据赋值
gxgc2.Shape = DiffShapes[j].Shape;
gxgc2.SetAttribure(gxgcItem, gxgc_FieldsIndex);//更新图斑外扩
if (gxgc.BGHTBBSM == pBGFeature.BSM)//更新图斑内缩
{
gxgc2.SetBGHAttribure(JC_F, jc_FieldsIndex);
List gc_Features = FeatureAPI.Identify(gxgc2.Shape, _curDLTBGXGC_FL);
bool isUnioned = false;
for (int i = 0; i < gc_Features.Count; i++)//内缩被动变更操作
{
if (FeatureAPI.IsAdjacent(gxgc2.Shape, gc_Features[i].ShapeCopy) && !FeatureAPI.IsInterSect(gxgc2.Shape, gc_Features[i].ShapeCopy))
{
DLTBGXGCAttribute dLTBGXGC = new DLTBGXGCAttribute(gxgc_FieldsIndex);
dLTBGXGC.SetAttribure(gc_Features[i], gxgc_FieldsIndex);
dLTBGXGC.Shape = gc_Features[i].ShapeCopy;
if (dLTBGXGC.BGHAttribureIsEqual(gxgc2))
{
int GCBGMJ = _curDLTBGXGC_FL.FeatureClass.FindField("TBBGMJ");
int GXBGMJ = _curDLTBGX_FL.FeatureClass.FindField("TBMJ");
int GXBSM = _curDLTBGX_FL.FeatureClass.FindField("BSM");
gc_Features[i].Value[GCBGMJ] = Convert.ToDouble(gc_Features[i].Value[GCBGMJ]) + DiffShapes[j].Area;
List GX_Fs = FeatureAPI.Identify2(gc_Features[i].ShapeCopy, _curDLTBGX_FL);
GX_Fs[0].Shape = FeatureAPI.Union(gxgc2.Shape, GX_Fs[0].ShapeCopy);
if (GXBGMJ != -1)
GX_Fs[0].Value[GXBGMJ] = Convert.ToDouble(GX_Fs[0].Value[GXBGMJ]) + DiffShapes[j].Area;
GX_Fs[0].Store();
gc_Features[i].Shape = FeatureAPI.Union(gxgc2.Shape, gc_Features[i].ShapeCopy);
gc_Features[i].Store();
isUnioned = true;
}
}
}
if (isUnioned == true) continue;
}
gxgc2.BGMJ = DiffShapes[j].Area;
DLTBGXAttribute newGXData3 = new DLTBGXAttribute(gx_FieldsIndex, gxgc2)
{
BSM = gxgc.BGHTBBSM,
Shape2 = gxgc2.Shape
};
newGXData3.GCDataList.Add(gxgc2);
if (FeatureAPI.IsAdjacent(pGXShape, newGXData3.Shape) && pBGFeature.IsEqual(newGXData3))
{
result.Add(gxgc2);
}
else
newGXData.Add(newGXData3);
}
}
gxgcItem.Delete();
}
return result;
}
private List GetGXGCDataForJCLayer(DLTBGXAttribute pBGFeature, IGeometry pGXShape, IFeatureLayer pJC_Layer, ref List newGXData)
{
List result = new List();
List jc_Features = new List();
jc_Features = FeatureAPI.Identify(pGXShape, pJC_Layer);
foreach (var jc in jc_Features)
{
DLTBGXGCAttribute gxgc = new DLTBGXGCAttribute(gxgc_FieldsIndex);
//gxgc.BGTBOID = pBGFeature.OID.ToString();
gxgc.SetBGQAttribure(jc, jc_FieldsIndex);
gxgc.SetBGHAttribure(jc, jc_FieldsIndex);
gxgc.BGMJ = jc.Value[jc.Fields.FindField("TBMJ")].ToDouble();
gxgc.BGHTBBH = jc.Value[jc.Fields.FindField("TBBH")].ToTrim();
if (FeatureAPI.IsAdjacent(jc.ShapeCopy, pGXShape))
{
DLTBGXAttribute tempgx = new DLTBGXAttribute(gx_FieldsIndex);
tempgx.SetAttribure(jc, jc_FieldsIndex);
if (pBGFeature.IsEqual(tempgx))
{
gxgc.Shape = jc.ShapeCopy;
result.Add(gxgc);
}
}
else if (FeatureAPI.IsContains(pGXShape, jc.ShapeCopy))
{
gxgc.Shape = jc.ShapeCopy;
gxgc.SetBGHAttribure(pBGFeature);
if (pBGFeature.FieldsValue.ContainsKey("XZQTZLX"))
{
gxgc.SetXZQTZLX(pBGFeature.FieldsValue["XZQTZLX"].ToTrim());
}
if (FeatureAPI.IsContains(jc.ShapeCopy, pGXShape))
{
gxgc.BGHTBBSM = jc.Value[jc.Fields.FindField("BSM")].ToTrim();
}
result.Add(gxgc);
}
else
{
double jc_MJ = gxgc.BGMJ;
//相交部分图形
IGeometry IntersectGeo = FeatureAPI.InterSect(jc.ShapeCopy, pGXShape);
if (IntersectGeo.IsEmpty || IntersectGeo.GetEllipseArea() <= 0.1)
continue;
#region 图斑分割/合并/拆分多部件后进行面积平差
List Area_GXGCAttribure = new List();
ShapeInfo InterShape = new ShapeInfo(IntersectGeo);
DLTBAreaHandle InterHandle = new DLTBAreaHandle(InterShape);
List InterShapes = InterHandle.GetFeatures();
List areaOperationData = new List();
int id = 0;
foreach (var item in InterShapes)
{
id++;
item.ID = id;
areaOperationData.Add(item);
}
IGeometry DiffGeo = FeatureAPI.Difference(jc.ShapeCopy, pGXShape);
List DiffShapes = null;
if (DiffGeo != null && !DiffGeo.IsEmpty)
{
ShapeInfo DiffShape = new ShapeInfo(DiffGeo);
DLTBAreaHandle DiffHandle = new DLTBAreaHandle(DiffShape);
DiffShapes = DiffHandle.GetFeatures();
foreach (var item in DiffShapes)
{
id++;
item.ID = id;
areaOperationData.Add(item);
}
}
AreaAdjustment2(areaOperationData, jc_MJ);//过程数据平差
foreach (var item in areaOperationData)
{
if (InterShapes != null)
{
if (InterShapes.FirstOrDefault(f => f.ID == item.ID) != null)
{
InterShapes.FirstOrDefault(f => f.ID == item.ID).SetArea(item.Area);
}
else if (DiffShapes != null)
{
if (DiffShapes.FirstOrDefault(f => f.ID == item.ID) != null)
{
DiffShapes.FirstOrDefault(f => f.ID == item.ID).SetArea(item.Area);
}
}
}
}
#endregion
foreach (var item in InterShapes)//return 过程数据
{
DLTBGXGCAttribute gxgc2 = new DLTBGXGCAttribute(gxgc_FieldsIndex);
gxgc2.SetBGQAttribure(jc, jc_FieldsIndex);
gxgc2.SetBGHAttribure(pBGFeature);
gxgc2.BGMJ = item.Area;
gxgc2.Shape = item.Shape;
result.Add(gxgc2);
}
for (int j = 0; j < DiffShapes.Count; j++)//ref newGXData更新数据
{
if (FeatureAPI.Identify2(DiffShapes[j].Shape, _curDLTBGX_FL).Count <= 0)//被动变更部分
{ //验证当前是切割的,还是被动变更部分
DLTBGXGCAttribute gxgc2 = new DLTBGXGCAttribute(gxgc_FieldsIndex);
gxgc2.SetBGQAttribure(jc, jc_FieldsIndex);
gxgc2.SetBGHAttribure(jc, jc_FieldsIndex);
string bsmPrefix = MaxBSM.Substring(0, 10);
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9));
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0');
gxgc2.BGHTBBSM = MaxBSM;
gxgc2.Shape = DiffShapes[j].Shape;
gxgc2.BGMJ = DiffShapes[j].Area;
DLTBGXAttribute newGXData3 = new DLTBGXAttribute(gx_FieldsIndex, gxgc2);
newGXData3.BSM = gxgc2.BGHTBBSM;
//newGXData3.TBBH = gxgc.BGHTBBH;
newGXData3.GCDataList.Add(gxgc2);
newGXData.Add(newGXData3);
}
}
}
}
return result;
}
///
/// 面积平差
///
/// 需要平差的对象集合
/// 控制面积
public void AreaAdjustment2(List shpList, double pKZMJ)
{
if (shpList.Count == 1)
{
shpList[0].SetArea(pKZMJ);
return;
}
//如果面积=0,计算椭球面积
shpList.ForEach(f =>
{
if (f.Area == 0)
f.CalculationArea();
});
shpList = shpList.OrderByDescending(o => o.Area).ToList();
double mjc = Math.Round(shpList.Sum(s => s.Area) - pKZMJ, 2);
//平差
while (Math.Round(mjc, 2) != 0)
{
int tpsm = (int)(Math.Abs(Math.Round(mjc, 2)) / (double)0.01);
int e = tpsm / shpList.Count;
int f = tpsm % shpList.Count;
if (f != 0)
{
double tpmj = (e + 1) * 0.01;
for (int i = 0; i < f; i++)
{
if (mjc < 0)
shpList[i].SetArea(shpList[i].Area + tpmj);
else
shpList[i].SetArea(shpList[i].Area - tpmj);
}
}
if (e != 0)
{
double tpmj = e * 0.01;
for (int i = f; i < shpList.Count; i++)
{
if (mjc < 0)
shpList[i].SetArea(shpList[i].Area + tpmj);
else
shpList[i].SetArea(shpList[i].Area - tpmj);
}
}
mjc = Math.Round(shpList.Sum(s => s.Area), 2) - pKZMJ;
}
}
private void InitView()
{
if (_Elements == null)
_Elements = BundleRuntime.Instance.GetService();
if (_FeatureInfo == null && _Elements != null)
_FeatureInfo = _Elements.FirstOrDefault(f => f.Title == "要素属性");
if ((_FeatureInfo as UserControl).Parent != null)
((_FeatureInfo as UserControl).Parent as Grid).Children.Clear();
if (_FeatureInfo != null)
TBInfo.Children.Add(_FeatureInfo as UIElement);
}
public void ShowPanel()
{
Platform.Instance.OpenView(this, false);
}
public void ClosePanel()
{
_FeatureInfo.BindData(null);
_FeatureInfo = null;
MapsManager.Instance.MapService.OnSelectionChanged -= MapService_OnSelectionChanged;
Platform.Instance.CloseView(this);
}
public void ClosePanelInvoke()
{
CloseViewHandler?.Invoke(this, null);
}
}
}