年度变更建库软件5.0版本
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.
 
 

1108 lines
56 KiB

using DevExpress.Xpf.Editors.Settings;
using DevExpress.Xpf.Grid;
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.ThreadManager;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Views;
using KUI.Windows;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace Kingo.Plugin.AttributeMaintain.View
{
public partial class FrmCZCPatchwork : UserControl, IDockPanel2
{
private static int SHAPE_Area = 30;
private IFeatureClass czcdydgx = null;
private IFeatureClass czcdydgxgc = null;
private IFeatureClass dltbgx = null;
private IFeatureClass dltbgxgc = null;
private string WhereClause = string.Empty;
private DataTable IntoData { get; set; }
public FrmCZCPatchwork()
{
InitializeComponent();
DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray);
_MapService = MapsManager.Instance.MapService;
//this.Loaded += ViewXZQInto_Loaded;
IsShowInMap = true;
DockAreas = DockStyle.DockBottom;
DockHeight = 380;
DefaultArea = DockStyle.DockBottom;
ShowCloseButton = true;
ShowAutoHideButton = false;
Title = "城镇村更新层图斑";
LoadData();
}
private void ViewXZQInto_Loaded(object sender, RoutedEventArgs e)
{
ThreadManager.Instance.QueueUserWorkItem(new System.Threading.WaitCallback(Init), null);
}
private void Init(object parm)
{
try
{
this.Dispatcher.Invoke(() =>
{
loading.Visibility = Visibility.Visible;
});
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
this.Dispatcher.Invoke(() =>
{
loading.Visibility = Visibility.Collapsed;
});
}
}
#region IDockPanel2接口
public bool IsShowInMap { 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 event EventHandler CloseViewHandler;
public void ClosePanel()
{
Platform.Instance.CloseView(this);
}
public void ClosePanelInvoke()
{
CloseViewHandler?.Invoke(null, null);
}
public void ShowPanel()
{
Platform.Instance.OpenView(this, false);
MapsManager.Instance.MapService.ProjectClosed += (s, e) =>
{
this.ClosePanel();
};
}
#endregion
private void CheckBox_Click_1(object sender, RoutedEventArgs e)
{
try
{
if (dgInto.SelectedItem != null)
{
DataRowView dr = (dgInto.SelectedItem as DataRowView);
if ((sender as CheckBox).IsChecked == true)
{
dr["IsValid"] = true;
}
else
{
dr["IsValid"] = false;
}
}
int length = 0;
foreach (DataRow item in (dgInto.ItemsSource as DataTable).Rows)
{
if (item[0].ToString() == "True")
{
length++;
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
private void DgInto_CustomColumnGroup(object sender, DevExpress.Xpf.Grid.CustomColumnSortEventArgs e)
{
}
private void LoadData()
{
czcdydgx = MapsManager.Instance.MapService.GetFeatureClassByName("CZCDYDGX");
if (czcdydgx == null)
return;
IntoData = new DataTable();
if (!string.IsNullOrEmpty(SArea.Text))
{
if (SArea.Text.ToTrim().ToInt() > 0)
SHAPE_Area = SArea.Text.ToTrim().ToInt();
}
else
{
SHAPE_Area = 30;
}
WhereClause = $" SHAPE_Area<{SHAPE_Area} ";
IFeatureCursor cursor = czcdydgx.Search(new QueryFilter() { WhereClause = WhereClause }, true);
try
{
ConstructColumn(czcdydgx.Fields);
IFeature f = null;
while ((f = cursor.NextFeature()) != null)
{
DataRow dr = IntoData.NewRow();
bool IsInto = true;
for (int i = 0; i < IntoData.Columns.Count; i++)
{
//if (i == 0)
//{
// dr[i] = false;
// continue;
//}
object obj = f.get_Value((int)IntoData.Columns[i].ExtendedProperties["index"]);
if (obj == null)
{
continue;
}
else
{
if ((obj.ToString()).Contains("1899/12/30 0:00:00"))
{
obj = System.DBNull.Value;
}
}
if (obj is string)
{
obj = obj.ToString().Trim();//字符串时,去空格
}
dr[i] = obj;
}
if (IsInto)
IntoData.Rows.Add(dr);
}
this.Dispatcher.Invoke(() =>
{
dgInto.ItemsSource = null;
dgInto.ItemsSource = IntoData;
dgInto.Columns[0].AllowEditing = DevExpress.Utils.DefaultBoolean.True;
});
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 构造列获取记录条数
/// </summary>
/// <param name="fields"></param>
private void ConstructColumn(IFields fields)
{
if (fields != null)
{
IntoData = new DataTable();
//DataColumn col1 = new DataColumn();
//col1.ColumnName = "IsValid";
//col1.Caption = "选中";
//col1.DataType = typeof(bool);
//IntoData.Columns.Add(col1);
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.get_Field(i);
if (field.Name.ToUpper().EndsWith("SHAPE"))
continue;
DataColumn col = new DataColumn();
col.ExtendedProperties.Add("index", i);
col.ColumnName = field.Name;
col.Caption = field.AliasName;
switch (field.Type)
{
case esriFieldType.esriFieldTypeSmallInteger:
col.DataType = typeof(short);
break;
case esriFieldType.esriFieldTypeInteger:
col.DataType = typeof(int);
break;
case esriFieldType.esriFieldTypeSingle:
break;
case esriFieldType.esriFieldTypeDouble:
col.DataType = typeof(double);
break;
case esriFieldType.esriFieldTypeString:
col.DataType = typeof(string);
break;
case esriFieldType.esriFieldTypeDate:
col.DataType = typeof(DateTime);
break;
case esriFieldType.esriFieldTypeOID:
col.DataType = typeof(Int32);
break;
case esriFieldType.esriFieldTypeGeometry:
break;
case esriFieldType.esriFieldTypeBlob:
break;
case esriFieldType.esriFieldTypeRaster:
break;
case esriFieldType.esriFieldTypeGUID:
break;
case esriFieldType.esriFieldTypeGlobalID:
break;
case esriFieldType.esriFieldTypeXML:
break;
default:
break;
}
col.ReadOnly = true; //!field.Editable;//编辑状态启用默认是否可以编辑
IntoData.Columns.Add(col);
System.Runtime.InteropServices.Marshal.ReleaseComObject(field);
}
}
}
private void DgInto_AutoGeneratedColumns(object sender, RoutedEventArgs e)
{
GridControl grid = sender as GridControl;
foreach (GridColumn column in grid.Columns)
{
if (IntoData.Columns.Contains(column.FieldName))
{
string caption = IntoData.Columns[column.FieldName].Caption;
if (caption != null)
{
column.EditSettings = new TextEditSettings() { HorizontalContentAlignment = EditSettingsHorizontalAlignment.Left };
column.Header = caption;
}
}
}
}
#region 定位选中图斑
private IMapService _MapService { get; set; }
private void TvAttr2_RowDoubleClick(object sender, RowDoubleClickEventArgs e)
{
try
{
DataRowView obj = e.Source.FocusedRowData.Row as DataRowView;
if (obj != null)
{
_MapService.SelectFeature("CZCDYDGX", obj["OBJECTID"].ToTrim(), true);
}
}
catch (Exception ex)
{
MessageHelper.Show("定位失败!" + ex.Message);
}
}
#endregion
#region 刷新数据
private void BtnRefreshData_Click(object sender, RoutedEventArgs e)
{
LoadData();
}
#endregion
#region 修复
//1.由于补充城镇村等用地空洞或与地类图斑之间的缝隙,造成的城镇村等用地更新层存在碎面(上图面积不足30平方米),建议合并至周边城镇村等用地(周边城镇村等用地未变更的,应将其提出至更新成果进行图形变更);
//2.由于城镇村等用地灭失后剩余部分面积不足30平方米(周边没有城镇村等用地,同时对应图斑为非建设用地),建议进行灭失处理。
private void btnMergeData_Click(object sender, RoutedEventArgs e)
{
IFeatureLayer JC_CZCDYDLayer = null;
IFeatureLayer JC_DLTB = null;
IFeatureLayer GXGC_DLTBLayer = null;
IFeature f = null;
IFeature feature = null;
try
{
if (IntoData.Rows.Count == 0)
{
MessageHelper.ShowTips("未检测要修复的数据");
return;
}
czcdydgx = MapsManager.Instance.MapService.GetFeatureClassByName("CZCDYDGX");
czcdydgxgc = MapsManager.Instance.MapService.GetFeatureClassByName("CZCDYDGXGC");
dltbgx = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGX");
dltbgxgc = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGXGC");
GXGC_DLTBLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGXGC");
JC_CZCDYDLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("城镇村等用地");
JC_DLTB = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
JC_CZCDYDLayer.SpatialReference = (czcdydgx as IGeoDataset).SpatialReference;
if (czcdydgx == null || czcdydgxgc == null)
return;
var gxgc_bgxw = czcdydgxgc.FindField("BGXW");
var gx_CZCMJ = czcdydgx.FindField("CZCMJ");
var gx_CZCLX = czcdydgx.FindField("CZCLX");
var jc_CZCMJ = JC_CZCDYDLayer.FeatureClass.FindField("CZCMJ");
var jc_CZCLX = JC_CZCDYDLayer.FeatureClass.FindField("CZCLX");
var jc_CZCDM = JC_CZCDYDLayer.FeatureClass.FindField("CZCDM");
var jc_CZCMC = JC_CZCDYDLayer.FeatureClass.FindField("CZCMC");
var gx_BSM = czcdydgx.FindField("BSM");
var gxgc_BSM = czcdydgxgc.FindField("BSM");
var gxgc_BGHBSM = czcdydgxgc.FindField("BGHBSM");
var gxgc_BGHCZCDM = czcdydgxgc.FindField("BGHCZCDM");
var gxgc_BGHCZCMC = czcdydgxgc.FindField("BGHCZCMC");
var gxgc_BGHCZCLX = czcdydgxgc.FindField("BGHCZCLX");
var gxgc_BGMJ = czcdydgxgc.FindField("BGMJ");
var gx_CZCDM = czcdydgx.FindField("CZCDM");
var gx_CZCMC = czcdydgx.FindField("CZCMC");
WhereClause = $" SHAPE_Area<{SHAPE_Area} and BGXW='3' and BGHCZCLX='203' ";
IFeatureCursor cursor = czcdydgxgc.Search(new QueryFilter() { WhereClause = WhereClause }, true);
List<int> delid = new List<int>();
this.ShowLoading("正在进行城镇村等用地更新层数据维护...", 0, 0);
while ((f = cursor.NextFeature()) != null)
{
if (f.OID == 33050)
{
//continue;
}
//与相邻更新层合并,继承最大图形的属性
List<IFeature> listFc = FeatureAPI.Identify2(f.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgx });
if (listFc.Count > 0)
{
feature = listFc[0];
if (delid.Contains(feature.OID)) continue;
listFc = FeatureAPI.Identify(feature.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgx });
if (listFc.Count > 0)
{
//存在相邻图斑 取共边长的同属性合并
IFeature gxfeature = null;
var Unionlength = 0.00;
foreach (IFeature feature1 in listFc.OrderByDescending(x => x.Value[gx_CZCMJ]))
{
if (feature1.OID == feature.OID) continue;
var thisczcdm = feature.Value[gx_CZCDM].ToString();
var thisczcmc = feature.Value[gx_CZCMC].ToString();
var gxczcdm = feature1.Value[gx_CZCDM].ToString();
var gxczcmc = feature1.Value[gx_CZCMC].ToString();
if (feature1.Value[gx_CZCLX].ToString() == "203" && thisczcdm == gxczcdm && thisczcmc == gxczcmc)
{
var length = FeatureAPI.LengthOfSide(feature.ShapeCopy, feature1.ShapeCopy);
if (length > Unionlength)
{
Unionlength = length;
gxfeature = feature1;
}
}
}
if (gxfeature != null && !FeatureAPI.GetEqual(feature.ShapeCopy, gxfeature.ShapeCopy))
{
var jcmj = gxfeature.Value[gx_CZCMJ].ToDouble();
var gxmj = feature.Value[gx_CZCMJ].ToDouble();
var strBSM = GetMaxBSM(new List<IFeatureClass>() { czcdydgx });
var strbsm = strBSM.Substring(0, 10);
var Maxbsm = strBSM.Substring(10).ToInt() + 1;
strBSM = strbsm + Maxbsm.ToString().PadLeft(8, '0');//最新标识码
gxfeature.Shape = FeatureAPI.Union(gxfeature.ShapeCopy, feature.ShapeCopy);
gxfeature.Value[gx_CZCMJ] = jcmj + gxmj;
gxfeature.Value[gx_BSM] = strBSM;
gxfeature.Store();
if (!delid.Contains(feature.OID))
delid.Add(feature.OID);
var gxgc = FeatureAPI.Identify2(gxfeature.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgxgc });
foreach (var item in gxgc)
{
item.Value[gxgc_BGHBSM] = gxfeature.Value[gx_BSM];
item.Store();
}
}
else
{
listFc = FeatureAPI.Identify(feature.ShapeCopy, JC_CZCDYDLayer);
//foreach (IFeature feature1 in listFc.OrderByDescending(x => x.Value[jc_CZCMJ]))
//{
// if (feature1.Value[jc_CZCLX].ToString() == "203")
// {
// gxfeature = feature1;
// break;
// }
//}
foreach (IFeature feature1 in listFc.OrderByDescending(x => x.Value[jc_CZCMJ]))
{
var thisczcdm = feature.Value[gx_CZCDM].ToString();
var thisczcmc = feature.Value[gx_CZCMC].ToString();
var jcczcdm = feature1.Value[jc_CZCDM].ToString();
var jcczcmc = feature1.Value[jc_CZCMC].ToString();
if (feature1.Value[jc_CZCLX].ToString() == "203" && thisczcdm == jcczcdm && thisczcmc == jcczcmc)
{
var length = FeatureAPI.LengthOfSide(feature.ShapeCopy, feature1.ShapeCopy);
if (length > Unionlength)
{
Unionlength = length;
gxfeature = feature1;
}
}
}
if (feature != null && gxfeature != null)
{
var jcmj = gxfeature.Value[jc_CZCMJ].ToDouble();
var gxmj = feature.Value[gx_CZCMJ].ToDouble();
feature.Shape = FeatureAPI.Union(gxfeature.ShapeCopy, feature.ShapeCopy);
feature.Value[gx_CZCMJ] = jcmj + gxmj;
feature.Store();
var gxgc = FeatureAPI.Identify2(feature.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgxgc });
if (gxgc.Count > 0)
{
gxgc[0].Value[gxgc_bgxw] = "3";
gxgc[0].Store();
InsertCZCGXGC(gxgc[0], gxfeature, czcdydgxgc);
}
}
}
}
}
}
if (cbIsMs.IsChecked == true)
{
WhereClause = $" SHAPE_Area<{SHAPE_Area} and BGXW='2' and BGQCZCLX='203' and BGHCZCLX='203' ";
cursor = czcdydgxgc.Search(new QueryFilter() { WhereClause = WhereClause }, true);
int idxCZCBGMJ = czcdydgxgc.FindField("BGMJ");
while ((f = cursor.NextFeature()) != null)
{
if (f.OID == 3676)
{
}
double bgmj = f.Value[idxCZCBGMJ].ToDouble(2);
//与相邻更新层合并,继承最大图形的属性
List<IFeature> listFc = FeatureAPI.Identify2(f.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgx });
if (listFc.Count > 0)
{
for (int i = 0; i < listFc.Count; i++)
{
feature = listFc[i];
if (feature.Value[gx_CZCMJ].ToDouble(2) > SHAPE_Area) continue;
feature.Delete();
}
f.Value[gxgc_BGHBSM] = "";
f.Value[gxgc_BGHCZCDM] = "";
f.Value[gxgc_BGHCZCMC] = "";
f.Value[gxgc_BGHCZCLX] = "";
f.Value[gxgc_bgxw] = "0";
f.Store();
if (bgmj < 0.1) continue;
//提取地类图斑数据,作为无变化数据
listFc = FeatureAPI.Identify2(f.ShapeCopy, GXGC_DLTBLayer);
if (listFc.Count == 0)
{
listFc = FeatureAPI.Identify2(f.ShapeCopy, JC_DLTB);
if (listFc.Count == 0) continue;
IFeature jctb_F = listFc[0];
int idxTBMJ = jctb_F.Fields.FindField("TBMJ");
#region 地类图斑更新过程层
IFeatureCursor insertCur = dltbgxgc.Insert(true);
IFeatureBuffer gcBuf = dltbgxgc.CreateFeatureBuffer();
gcBuf.Shape = jctb_F.ShapeCopy;
for (int i = 0; i < dltbgxgc.Fields.FieldCount; i++)
{
IField field = dltbgxgc.Fields.Field[i];
if (!field.Editable || field.Name.Contains("SHAPE")) continue;
string sFieldName = field.Name.Replace("BGQ", "").Replace("BGH", "");
int idx = jctb_F.Fields.FindField(sFieldName);
if (idx == -1)
{
sFieldName = field.Name.Replace("BGQTB", "").Replace("BGHTB", "");
idx = jctb_F.Fields.FindField(sFieldName);
}
if (idx != -1)
gcBuf.Value[i] = jctb_F.Value[idx];
}
int idxBGXW = dltbgxgc.FindField("BGXW");
int idxBGMJ = dltbgxgc.FindField("TBBGMJ");
int idxXZQTZLX = dltbgxgc.FindField("XZQTZLX");
int idxGXSJ = dltbgxgc.FindField("GXSJ");
gcBuf.Value[idxBGMJ] = jctb_F.Value[idxTBMJ];
gcBuf.Value[idxBGXW] = "4";
gcBuf.Value[idxXZQTZLX] = "0";
gcBuf.Value[idxGXSJ] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31);
insertCur.InsertFeature(gcBuf);
insertCur.Flush();
#endregion
#region 地类图斑更新层
insertCur = dltbgx.Insert(true);
gcBuf = dltbgx.CreateFeatureBuffer();
gcBuf.Shape = jctb_F.ShapeCopy;
for (int i = 0; i < dltbgx.Fields.FieldCount; i++)
{
IField field = dltbgx.Fields.Field[i];
if (!field.Editable || field.Name.Contains("SHAPE")) continue;
string sFieldName = field.Name.Replace("BGQ", "").Replace("BGH", "");
int idx = jctb_F.Fields.FindField(sFieldName);
if (idx == -1)
{
sFieldName = field.Name.Replace("BGQTB", "").Replace("BGHTB", "");
idx = jctb_F.Fields.FindField(sFieldName);
}
if (idx != -1)
gcBuf.Value[i] = jctb_F.Value[idx];
}
//int idxBGXW = dltbgxgc.FindField("BGXW");
//int idxXZQTZLX = dltbgxgc.FindField("XZQTZLX");
idxGXSJ = dltbgx.FindField("GXSJ");
//gcBuf.Value[idxBGXW] = "4";
gcBuf.Value[idxGXSJ] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31);
insertCur.InsertFeature(gcBuf);
insertCur.Flush();
#endregion
//listFc = FeatureAPI.Identify2(jctb_F.ShapeCopy, JC_CZCDYDLayer);
//int idxCZCMJ = JC_CZCDYDLayer.FeatureClass.FindField("CZCMJ");
//int idxBSM = JC_CZCDYDLayer.FeatureClass.FindField("BSM");
//int idxCZCDM = JC_CZCDYDLayer.FeatureClass.FindField("CZCDM");
//int idxCZCMC = JC_CZCDYDLayer.FeatureClass.FindField("CZCMC");
//int idxCZCLX = JC_CZCDYDLayer.FeatureClass.FindField("CZCLX");
//int gxgc_BGQBSM = czcdydgxgc.FindField("BGQBSM");
//int gxgc_BGQCZCDM = czcdydgxgc.FindField("BGQCZCDM");
//int gxgc_BGQCZCMC = czcdydgxgc.FindField("BGQCZCMC");
//int gxgc_BGQCZCLX = czcdydgxgc.FindField("BGQCZCLX");
//IFeatureCursor czcInsCur = null;
//IFeatureCursor gxCzcInsCur = null;
//var strBSM = string.Empty;
//if (listFc.Count > 0)
//{
// czcInsCur = czcdydgxgc.Insert(true);
// gxCzcInsCur = czcdydgx.Insert(true);
// strBSM = GetMaxBSM(new List<IFeatureClass>() { czcdydgx });
//}
//foreach (var item in listFc)
//{
// decimal czcMJ = item.Value[idxCZCMJ].ToDecimal();
// IGeometry MsGeo = FeatureAPI.InterSect(item.ShapeCopy, jctb_F.ShapeCopy);
// if (MsGeo.IsEmpty)
// continue;
// IGeometry OtrGeo = FeatureAPI.Difference(item.ShapeCopy, jctb_F.ShapeCopy);
// var strbsm = strBSM.Substring(0, 10);
// var Maxbsm = strBSM.Substring(10).ToInt() + 1;
// strBSM = strbsm + Maxbsm.ToString().PadLeft(8, '0');//最新标识码
// if (OtrGeo.IsEmpty)
// {
// IFeatureBuffer gxgcBuff = czcdydgxgc.CreateFeatureBuffer();
// gxgcBuff.Value[gxgc_BGQBSM] = item.Value[idxBSM].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCDM] = item.Value[idxCZCDM].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCMC] = item.Value[idxCZCMC].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCLX] = item.Value[idxCZCLX].ToTrim();
// gxgcBuff.Value[gxgc_BGHBSM] = "";
// gxgcBuff.Value[gxgc_BGHCZCDM] = "";
// gxgcBuff.Value[gxgc_BGHCZCMC] = "";
// gxgcBuff.Value[gxgc_BGHCZCLX] = "";
// gxgcBuff.Value[gxgc_bgxw] = "0";
// gxgcBuff.Value[gxgc_BGMJ] = czcMJ;
// czcInsCur.InsertFeature(gxgcBuff);
// }
// else
// {
// IFeatureBuffer gxgcBuff = czcdydgxgc.CreateFeatureBuffer();
// gxgcBuff.Value[gxgc_BGQBSM] = item.Value[idxBSM].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCDM] = item.Value[idxCZCDM].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCMC] = item.Value[idxCZCMC].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCLX] = item.Value[idxCZCLX].ToTrim();
// gxgcBuff.Value[gxgc_BGHBSM] = "";
// gxgcBuff.Value[gxgc_BGHCZCDM] = "";
// gxgcBuff.Value[gxgc_BGHCZCMC] = "";
// gxgcBuff.Value[gxgc_BGHCZCLX] = "";
// gxgcBuff.Value[gxgc_bgxw] = "0";
// gxgcBuff.Value[gxgc_BGMJ] = MsGeo.GetEllipseArea().ToDecimal(2);
// czcInsCur.InsertFeature(gxgcBuff);
// gxgcBuff = czcdydgxgc.CreateFeatureBuffer();
// gxgcBuff.Value[gxgc_BGQBSM] = item.Value[idxBSM].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCDM] = item.Value[idxCZCDM].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCMC] = item.Value[idxCZCMC].ToTrim();
// gxgcBuff.Value[gxgc_BGQCZCLX] = item.Value[idxCZCLX].ToTrim();
// gxgcBuff.Value[gxgc_BGHBSM] = strBSM;
// gxgcBuff.Value[gxgc_BGHCZCDM] = item.Value[idxCZCDM].ToTrim(); ;
// gxgcBuff.Value[gxgc_BGHCZCMC] = item.Value[idxCZCMC].ToTrim();
// gxgcBuff.Value[gxgc_BGHCZCLX] = item.Value[idxCZCLX].ToTrim();
// gxgcBuff.Value[gxgc_bgxw] = "2";
// gxgcBuff.Value[gxgc_BGMJ] = Math.Round(czcMJ - MsGeo.GetEllipseArea().ToDecimal(2), 2);
// czcInsCur.InsertFeature(gxgcBuff);
// IFeatureBuffer gxBuff = czcdydgx.CreateFeatureBuffer();
// gxBuff.Value[gx_BSM] = strBSM;
// gxBuff.Value[gx_CZCDM] = item.Value[idxCZCDM].ToTrim();
// gxBuff.Value[gx_CZCMC] = item.Value[idxCZCMC].ToTrim();
// gxBuff.Value[gx_CZCLX] = item.Value[idxCZCLX].ToTrim();
// gxBuff.Value[gx_CZCMJ]= Math.Round(czcMJ - MsGeo.GetEllipseArea().ToDecimal(2), 2);
// gxCzcInsCur.InsertFeature(gxBuff);
// }
//}
//if (czcInsCur != null)
// czcInsCur.Flush();
//if (gxCzcInsCur != null)
// gxCzcInsCur.Flush();
}
}
}
}
if (delid.Count > 0)
(czcdydgx as ITable).DeleteSearchedRows(new QueryFilter() { WhereClause = $"OBJECTID in ({string.Join(",", delid)})" });
SetBGMJ();
LoadData();
this.CloseLoading();
MessageHelper.Show("城镇村碎图斑修复完成!");
}
catch (Exception ex)
{
this.CloseLoading();
LogAPI.Debug(ex.Message);
MessageHelper.Show("城镇村碎图斑修复失败" + ex.Message);
}
finally
{
}
}
private void SetBGMJ()
{
try
{
IFeatureCursor cursor = czcdydgxgc.Search(new QueryFilter() { WhereClause = "BGXW='0' and BGMJ=0" }, true);
IFeature feature = null;
var gxgc_CZCMJ = czcdydgxgc.FindField("BGMJ");
var gx_CZCMJ = czcdydgx.FindField("CZCMJ");
var idxBGQBSM = czcdydgxgc.FindField("BGQBSM");
while ((feature = cursor.NextFeature()) != null)
{
string bgqBSM = feature.Value[idxBGQBSM].ToTrim();
IFeatureClassAPI fcAPI = new FeatureClassAPI(czcdydgxgc);
List<IFeature> listFc = fcAPI.QueryFeatures(new QueryFilter() { WhereClause = $"BGQBSM='{bgqBSM}'" });
if (listFc.Count == 1) continue;
//List<IFeature> listFc = FeatureAPI.Identify(feature.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgxgc });
IFeature gxgcfeature = listFc.OrderByDescending(x => x.Value[gxgc_CZCMJ]).FirstOrDefault();
if (gxgcfeature != null)
{
if (gxgcfeature.Value[gxgc_CZCMJ].ToDouble(2) <= 0.01) continue;
var mj = gxgcfeature.Value[gxgc_CZCMJ].ToDouble() - 0.01;
gxgcfeature.Value[gxgc_CZCMJ] = mj;
gxgcfeature.Store();
feature.Value[gxgc_CZCMJ] = 0.01;
feature.Store();
listFc = FeatureAPI.Identify2(gxgcfeature.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgx });
if (listFc.Count > 0)
{
listFc[0].Value[gx_CZCMJ] = (listFc[0].Value[gx_CZCMJ].ToDouble() - 0.01).ToDouble(2);
listFc[0].Store();
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("变更面积为零的图斑赋值错误:" + ex.Message);
}
}
private void old()
{
IFeatureLayer JC_CZCDYDLayer = null;
IFeatureLayer JC_DLTB = null;
IFeature f = null;
IFeature feature = null;
try
{
if (IntoData.Rows.Count == 0)
{
MessageHelper.ShowTips("未检测要修复的数据");
return;
}
czcdydgx = MapsManager.Instance.MapService.GetFeatureClassByName("CZCDYDGX");
dltbgx = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGX");
dltbgxgc = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGXGC");
czcdydgxgc = MapsManager.Instance.MapService.GetFeatureClassByName("CZCDYDGXGC");
JC_CZCDYDLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("城镇村等用地");
JC_DLTB = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
JC_CZCDYDLayer.SpatialReference = (czcdydgx as IGeoDataset).SpatialReference;
if (czcdydgx == null || czcdydgxgc == null)
return;
var gxgc_bgxw = czcdydgxgc.FindField("BGXW");
var gx_CZCMJ = czcdydgx.FindField("CZCMJ");
var jc_CZCMJ = JC_CZCDYDLayer.FeatureClass.FindField("CZCMJ");
var gx_BSM = czcdydgx.FindField("BSM");
var gxgc_BSM = czcdydgxgc.FindField("BSM");
var gxgc_BGHBSM = czcdydgxgc.FindField("BGHBSM");
var gxgc_BGMJ = czcdydgxgc.FindField("BGMJ");
IFeatureCursor cursor = czcdydgx.Search(new QueryFilter() { WhereClause = WhereClause }, true);
List<int> delid = new List<int>();
this.ShowLoading("正在进行城镇村等用地更新层数据维护...", 0, 0);
while ((f = cursor.NextFeature()) != null)
{
//与相邻更新层合并,继承最大图形的属性
List<IFeature> listFc = FeatureAPI.Identify(f.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgx });
if (listFc.Count > 0)
{
//存在相邻图斑 取面积最大的进行合并
feature = listFc.OrderByDescending(x => x.Value[gx_CZCMJ]).FirstOrDefault();
if (feature != null && !FeatureAPI.GetEqual(feature.ShapeCopy, f.ShapeCopy) && !delid.Contains(f.OID))
{
feature.Shape = FeatureAPI.Union(f.ShapeCopy, feature.ShapeCopy);
feature.Value[gx_CZCMJ] = feature.Shape.GetEllipseArea();
feature.Store();
if (!delid.Contains(f.OID))
delid.Add(f.OID);
var gxgc = FeatureAPI.Identify2(feature.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgxgc });
foreach (var item in gxgc)
{
item.Value[gxgc_BGHBSM] = feature.Value[gx_BSM];
item.Store();
}
}
else
{
//无相邻更新层数据 判断更新过程层是否为灭失
if (FeatureAPI.GetEqual(feature.ShapeCopy, f.ShapeCopy))
{
var gxgc = FeatureAPI.Identify(f.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgxgc });
var ms = gxgc.FirstOrDefault(x => x.Value[gxgc_bgxw].ToString() == "0");
if (ms != null)
{
foreach (var item in gxgc)
{
if (item.Value[gxgc_bgxw].ToString() == "0") continue;
item.Value[gxgc_bgxw] = "0";
item.Value[czcdydgxgc.FindField("BGHBSM")] = "";
item.Value[czcdydgxgc.FindField("BGHCZCLX")] = "";
item.Value[czcdydgxgc.FindField("BGHCZCDM")] = "";
item.Value[czcdydgxgc.FindField("BGHCZCMC")] = "";
item.Store();
}
if (!delid.Contains(f.OID))
{
delid.Add(f.OID);
}
var iddltbgx = FeatureAPI.Identify2(f.ShapeCopy, new FeatureLayerClass { FeatureClass = dltbgx });
if (iddltbgx.Count == 0)
{
var dltb = FeatureAPI.Identify2(f.ShapeCopy, new FeatureLayerClass { FeatureClass = JC_DLTB.FeatureClass });
if (dltb.Count > 0)
{
InsertDLTBGX(dltb[0], dltbgx);
InsertDLTBGXGC(dltb[0], dltbgxgc);
}
}
}
else
{
listFc = FeatureAPI.Identify(f.ShapeCopy, JC_CZCDYDLayer);
feature = listFc.OrderByDescending(x => x.Value[jc_CZCMJ]).FirstOrDefault();
if (feature != null)
{
f.Shape = FeatureAPI.Union(f.ShapeCopy, feature.ShapeCopy);
f.Value[gx_CZCMJ] = f.Shape.GetEllipseArea();
f.Store();
gxgc = FeatureAPI.Identify2(f.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgxgc });
if (gxgc.Count > 0)
{
gxgc[0].Value[gxgc_bgxw] = "3";
gxgc[0].Store();
//InsertCZCGXGC(gxgc[0], f, feature, czcdydgxgc);
}
}
}
}
else
{
listFc = FeatureAPI.Identify(f.ShapeCopy, JC_CZCDYDLayer);
feature = listFc.OrderByDescending(x => x.Value[jc_CZCMJ]).FirstOrDefault();
if (feature != null)
{
f.Shape = FeatureAPI.Union(f.ShapeCopy, feature.ShapeCopy);
f.Value[gx_CZCMJ] = f.Shape.GetEllipseArea();
f.Store();
var gxgc = FeatureAPI.Identify2(f.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgxgc });
if (gxgc.Count > 0)
{
gxgc[0].Value[gxgc_bgxw] = "3";
gxgc[0].Store();
//InsertCZCGXGC(gxgc[0], f, feature, czcdydgxgc);
}
}
}
}
}
else
{
//listFc = FeatureAPI.Identify2(f.ShapeCopy, new FeatureLayerClass { FeatureClass = dltbgx });
//int iDLBM = dltbgx.FindField("DLBM");
//List<string> JSYD = new List<string>() { "05H1", "0508", "0601", "0602", "0603", "0701", "0702", "08H1", "08H2", "0809", "0810", "09", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201" };
//if (listFc.Count > 0)
//{
// string dlbm = listFc[0].Value[iDLBM].ToString();
// if (!JSYD.Contains(dlbm))
// {
// listFc = FeatureAPI.Identify2(f.ShapeCopy, new FeatureLayerClass { FeatureClass = czcdydgxgc });
// if (listFc.Count > 0)
// {
// listFc[0].Value[czcdydgxgc.FindField("BGXW")] = "0";
// listFc[0].Value[czcdydgxgc.FindField("BGHBSM")] = "";
// listFc[0].Value[czcdydgxgc.FindField("BGHCZCLX")] = "";
// listFc[0].Value[czcdydgxgc.FindField("BGHCZCDM")] = "";
// listFc[0].Value[czcdydgxgc.FindField("BGHCZCMC")] = "";
// listFc[0].Store();
// }
// if (!delid.Contains(f.OID))
// {
// delid.Add(f.OID);
// }
// }
//}
}
}
(czcdydgx as ITable).DeleteSearchedRows(new QueryFilter() { WhereClause = $"OBJECTID in ({string.Join(",", delid)})" });
LoadData();
this.CloseLoading();
}
catch (Exception ex)
{
this.CloseLoading();
LogAPI.Debug(ex.Message);
MessageHelper.Show("城镇村碎图斑修复失败" + ex.Message);
}
finally
{
}
}
public bool InsertCZCGXGC(IFeature gxgcfeature, IFeature jcfeature, IFeatureClass featureClass)
{
IFeatureCursor T_Cursor = null;
try
{
int index = -1;
IFeatureBuffer buffer = featureClass.CreateFeatureBuffer();
buffer.Shape = jcfeature.ShapeCopy;
var strBSM = GetMaxBSM(new List<IFeatureClass>() { featureClass });
var strbsm = strBSM.Substring(0, 10);
var Maxbsm = strBSM.Substring(10).ToInt() + 1;
strBSM = strbsm + Maxbsm.ToString().PadLeft(8, '0');//最新标识码
for (int i = 0; i < gxgcfeature.Fields.FieldCount; i++)
{
IField field = gxgcfeature.Fields.Field[i];
if (field.Name == featureClass.ShapeFieldName || field.Name.Contains(featureClass.ShapeFieldName) || field.Name == featureClass.OIDFieldName || !field.Editable) continue;
index = gxgcfeature.Fields.FindField(field.Name);
if (index == -1) continue;
if (field.Name == "BGXW")
{
buffer.Value[index] = "2";
continue;
}
if (field.Name == "BSM")
{
buffer.Value[index] = strBSM;
continue;
}
if (field.Name == "BGQBSM")
{
buffer.Value[index] = jcfeature.Value[jcfeature.Fields.FindField("BSM")];
continue;
}
if (field.Name == "BGQCZCLX")
{
buffer.Value[index] = jcfeature.Value[jcfeature.Fields.FindField("CZCLX")];
continue;
}
if (field.Name == "BGQCZCDM")
{
buffer.Value[index] = jcfeature.Value[jcfeature.Fields.FindField("CZCDM")];
continue;
}
if (field.Name == "BGQCZCMC")
{
buffer.Value[index] = jcfeature.Value[jcfeature.Fields.FindField("CZCMC")];
continue;
}
if (field.Name == "BGMJ")
{
buffer.Value[index] = jcfeature.Value[jcfeature.Fields.FindField("CZCMJ")];//jcfeature.ShapeCopy.GetEllipseArea();
continue;
}
buffer.Value[index] = gxgcfeature.Value[index];
}
T_Cursor = featureClass.Insert(true);
T_Cursor.InsertFeature(buffer);
T_Cursor.Flush();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
public bool InsertDLTBGX(IFeature jcfeature, IFeatureClass dltbgxfc)
{
IFeatureCursor T_Cursor = null;
try
{
if (dltbgxfc == null || jcfeature == null) return false;
Dictionary<int, int> dicField = new Dictionary<int, int>();
int index = -1;
for (int i = 0; i < dltbgxfc.Fields.FieldCount; i++)
{
IField field = dltbgxfc.Fields.Field[i];
if (field.Name == dltbgxfc.ShapeFieldName || field.Name.Contains(dltbgxfc.ShapeFieldName) || field.Name == dltbgxfc.OIDFieldName || !field.Editable || field.Name == "ONLYZLBG" || field.Name == "XZQTZLX") continue;
index = jcfeature.Fields.FindField(field.Name);
if (index == -1) continue;
dicField.Add(i, index);
}
IFeatureClassLoad pFclsLoad = dltbgxfc as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
T_Cursor = dltbgxfc.Insert(true);
IFeatureBuffer buffer = dltbgxfc.CreateFeatureBuffer();
buffer.Shape = jcfeature.ShapeCopy;
var gxsj = dltbgxfc.FindField("GXSJ");
buffer.Value[gxsj] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31);
var xzqtzlx = dltbgxfc.FindField("XZQTZLX");
buffer.Value[xzqtzlx] = "0";
foreach (int item in dicField.Keys)
{
buffer.Value[item] = jcfeature.Value[dicField[item]];
}
T_Cursor.InsertFeature(buffer);
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception ex)
{
throw ex;
}
}
public bool InsertDLTBGXGC(IFeature jcfeature, IFeatureClass dltbgxgcfc)
{
IFeatureCursor T_Cursor = null;
try
{
if (dltbgxgcfc == null || jcfeature == null) return false;
Dictionary<int, int> dicField = new Dictionary<int, int>();
int index = -1;
for (int i = 0; i < dltbgxgcfc.Fields.FieldCount; i++)
{
IField field = dltbgxgcfc.Fields.Field[i];
if (field.Name == dltbgxgcfc.ShapeFieldName || field.Name.Contains(dltbgxgcfc.ShapeFieldName) || field.Name == dltbgxgcfc.OIDFieldName || !field.Editable || field.Name == "ONLYZLBG" || field.Name == "XZQTZLX") continue;
index = jcfeature.Fields.FindField(field.Name);
if (field.Name.Contains("BGQTB") || field.Name.Contains("BGHTB") || field.Name.Contains("BGQ") || field.Name.Contains("BGH"))
index = jcfeature.Fields.FindField(field.Name.Replace("BGQTB", "").Replace("BGHTB", "").Replace("BGQ", "").Replace("BGH", ""));
if (field.Name == "TBBGMJ")
index = jcfeature.Fields.FindField("TBMJ");
if (index == -1) continue;
dicField.Add(i, index);
}
IFeatureClassLoad pFclsLoad = dltbgxgcfc as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
T_Cursor = dltbgxgcfc.Insert(true);
IFeatureBuffer buffer = dltbgxgcfc.CreateFeatureBuffer();
buffer.Shape = jcfeature.ShapeCopy;
var bgxw = dltbgxgcfc.FindField("BGXW");
buffer.Value[bgxw] = "4";
var gxsj = dltbgxgcfc.FindField("GXSJ");
buffer.Value[gxsj] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31);
var xzqtzlx = dltbgxgcfc.FindField("XZQTZLX");
buffer.Value[xzqtzlx] = "0";
foreach (int item in dicField.Keys)
{
buffer.Value[item] = jcfeature.Value[dicField[item]];
}
T_Cursor.InsertFeature(buffer);
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception ex)
{
throw ex;
}
}
private string GetMaxBSM(List<IFeatureClass> fcList)
{
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();
tableSort.Table = table;
tableSort.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) return BSM;
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
}
}