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

1565 lines
89 KiB

6 months ago
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.AE;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.AE.ExtensionMethod;
using KGIS.Framework.AE.GPHelper;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using Kingo.PluginServiceInterface;
using KUI.Windows;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace Kingo.Plugin.DLTB_IDG.Helper
{
public class DLTB_IDGHelper : IDataChange
{
public string IDataChangeName { get => "DLTB_IDGHelper"; }
private IFeatureClass BGFeatureClass = null;
private IFeatureLayer JCFeatureLayer = null;
#region ExecuteDataChange
public void ExecuteDataChange(DataChangeParameter pParm)
{
BGFeatureClass = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBBG");
JCFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
ObservableCollection<ZLXXInfo> ListZLXXInfo = null;
if (pParm == null)
ListZLXXInfo = new ObservableCollection<ZLXXInfo>();
else
ListZLXXInfo = pParm.ListZLXXInfo;
Implement(BGFeatureClass, JCFeatureLayer, ListZLXXInfo);
}
#endregion
#region Implement
public void Implement(IFeatureClass BGFeatureClass, IFeatureLayer JCFeatureLayer, ObservableCollection<ZLXXInfo> ListZLXXInfo, IFeatureLayer SelLocation_Layer = null)
{
IFeatureLayer Temp_DLTBGXGC = null;
IFeatureLayer BGFeatureClass_Dissolve = null;//变更图斑融合
IFeatureClass GXFC = null;//更新层
IFeatureClass GXGCFC = null;//更新过程层
IFeatureLayer multipartToSingleFeatureLayer = null;//打散后的更新过程层
IFeatureLayer DissolveAnalysisFeatureLayer = null;//更新层融合后的图层
IFeatureLayer SelectFeatureLayer = null;//变更图斑在基础库中选择
IFeatureLayer GXGCFC_Layer = null;//变更图斑在基础库中选择
IFeatureLayer EraseAnalysisLayer = null;
IFeatureLayer IntersectAnalysisLayer = null;
IWorkspaceFactory pFtWsFct = null;
IFeature feature = null;
IFeatureCursor pCursor = null;
IFeatureClassAPI fcAPI = null;
IRow irow = null;
ITable itable = null;
ICursor iCursor = null;
try
{
LogAPI.Debug($"地类图斑数据提取_开始时间:{DateTime.Now}");
GXGCFC = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGXGC"); //地类图斑更新过程
GXGCFC_Layer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGXGC"); //地类图斑更新过程
GXFC = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGX"); //地类图斑更新层
#region 初始化数据
string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\DLTBGXGCTempFile";
if (!Directory.Exists(gdbFolder))
Directory.CreateDirectory(gdbFolder);
try
{ DelectDirect(gdbFolder); }
catch
{
//删除临时数据异常 不做处理
}
pFtWsFct = new FileGDBWorkspaceFactory();
string gdbFileName = Guid.NewGuid().ToString();
string path = System.IO.Path.Combine(gdbFolder, gdbFileName);
pFtWsFct.Create(path, "TempGDB", null, 0);
string TempfilePath = System.IO.Path.Combine(path, "TempGDB.gdb");//临时数据存放路径
//删除更新层更新过程层
ITable dltbgxTb = GXFC as ITable;
dltbgxTb.DeleteSearchedRows(null);
ITable dltbgxgcTb = GXGCFC as ITable;
dltbgxgcTb.DeleteSearchedRows(null);
GPParamClass paramClass = new GPParamClass();
#endregion
#region 判断是否存在坐落变更 提取相关数据
if ((SelLocation_Layer != null && SelLocation_Layer.FeatureClass.FeatureCount(null) != 0) || ListZLXXInfo.Count > 0)
{
this.UpdateMsg("坐落变更相关数据提取...");
IWorkspaceAPI wsAPI = new WorkspaceAPI(TempfilePath, WorkspaceTypeEnum.GDBFile);
IFeatureClassAPI DLTBBG_ZLBGAPI = wsAPI.CreateFeatureClass("DLTBBG", (BGFeatureClass as IGeoDataset).SpatialReference, BGFeatureClass.Fields);
foreach (var item in ListZLXXInfo)
{
if (string.IsNullOrWhiteSpace(item.BGQDM.ToTrim()) || string.IsNullOrWhiteSpace(item.BGHDM.ToTrim())) continue;
fcAPI = new FeatureClassAPI(JCFeatureLayer.FeatureClass);
fcAPI.FcToFc(DLTBBG_ZLBGAPI.FeatureClass, new QueryFilterClass() { WhereClause = $"ZLDWDM like '{item.BGQDM }%'" }, false);
}
#region 变更图斑擦除坐落变更的图斑
paramClass.FirstFeatureClass = DLTBBG_ZLBGAPI.FeatureClass;
paramClass.SecondFeatureClass = BGFeatureClass;
paramClass.OutFeatureClassPath = $"{TempfilePath}\\BGTB_Erase";
paramClass.IsGetOutPutFeature = true;
GeoprocessorHelper.EraseAnalysis(paramClass, ref EraseAnalysisLayer);
#endregion
ITable tempdltb = DLTBBG_ZLBGAPI.FeatureClass as ITable;
tempdltb.DeleteSearchedRows(null);
fcAPI = new FeatureClassAPI(EraseAnalysisLayer.FeatureClass);
fcAPI.FcToFc(DLTBBG_ZLBGAPI.FeatureClass, null, false);
fcAPI = new FeatureClassAPI(BGFeatureClass);
fcAPI.FcToFc(DLTBBG_ZLBGAPI.FeatureClass, null, false);
BGFeatureClass = DLTBBG_ZLBGAPI.FeatureClass;
}
#endregion
#region 空属性值 赋值
#region 变更图斑
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set DLBM ='' where DLBM is Null or DLBM=' ' or DLBM=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set DLMC ='' where DLMC is Null or DLMC=' ' or DLMC=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set QSXZ ='' where QSXZ is Null or QSXZ=' ' or QSXZ=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set QSDWDM ='' where QSDWDM is Null or QSDWDM=' ' or QSDWDM=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set QSDWMC ='' where QSDWMC is Null or QSDWMC=' ' or QSDWMC=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set ZLDWDM ='' where ZLDWDM is Null or ZLDWDM=' ' or ZLDWDM=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set ZLDWMC ='' where ZLDWMC is Null or ZLDWMC=' ' or ZLDWMC=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set KCDLBM ='' where KCDLBM is Null or KCDLBM=' ' or KCDLBM=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set KCXS=0 where KCXS is Null ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set GDLX ='' where GDLX is Null or GDLX=' ' or GDLX=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set GDPDJB ='' where GDPDJB is Null or GDPDJB=' ' or GDPDJB=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set XZDWKD=0 where XZDWKD is Null ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set TBXHDM ='' where TBXHDM is Null or TBXHDM=' ' or TBXHDM=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set TBXHMC ='' where TBXHMC is Null or TBXHMC=' ' or TBXHMC=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set ZZSXDM ='' where ZZSXDM is Null or ZZSXDM=' ' or ZZSXDM=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set ZZSXMC ='' where ZZSXMC is Null or ZZSXMC=' ' or ZZSXMC=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set GDDB =0 where GDDB is Null ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set FRDBS ='' where FRDBS is Null or FRDBS=' ' or FRDBS=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set CZCSXM ='' where CZCSXM is Null or CZCSXM=' ' or CZCSXM=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set MSSM ='' where MSSM is Null or MSSM=' ' or MSSM=' ' ");
//(BGFeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update DLTBBG set HDMC ='' where HDMC is Null or HDMC=' ' or HDMC=' ' ");
#endregion
#region 基础地类图斑
//string JC_DLTBName = JCFeatureLayer.FeatureClass.AliasName;
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set DLBM ='' where DLBM is Null or DLBM=' ' or DLBM=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set DLMC ='' where DLMC is Null or DLMC=' ' or DLMC=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set QSXZ ='' where QSXZ is Null or QSXZ=' ' or QSXZ=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set QSDWDM ='' where QSDWDM is Null or QSDWDM=' ' or QSDWDM=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set QSDWMC ='' where QSDWMC is Null or QSDWMC=' ' or QSDWMC=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set ZLDWDM ='' where ZLDWDM is Null or ZLDWDM=' ' or ZLDWDM=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set ZLDWMC ='' where ZLDWMC is Null or ZLDWMC=' ' or ZLDWMC=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set KCDLBM ='' where KCDLBM is Null or KCDLBM=' ' or KCDLBM=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set KCXS =0 where KCXS is Null");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDLX ='' where GDLX is Null or GDLX=' ' or GDLX=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDPDJB ='' where GDPDJB is Null or GDPDJB=' ' or GDPDJB=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set XZDWKD =0 where XZDWKD is Null");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set TBXHDM ='' where TBXHDM is Null or TBXHDM=' ' or TBXHDM=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set TBXHMC ='' where TBXHMC is Null or TBXHMC=' ' or TBXHMC=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set ZZSXDM ='' where ZZSXDM is Null or ZZSXDM=' ' or ZZSXDM=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set ZZSXMC ='' where ZZSXMC is Null or ZZSXMC=' ' or ZZSXMC=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDDB =0 where GDDB is Null");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set FRDBS ='' where FRDBS is Null or FRDBS=' ' or FRDBS=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set CZCSXM ='' where CZCSXM is Null or CZCSXM=' ' or CZCSXM=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set MSSM ='' where MSSM is Null or MSSM=' ' or MSSM=' ' ");
//(JCFeatureLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set HDMC ='' where HDMC is Null or HDMC=' ' or HDMC=' ' ");
#endregion
#endregion
#region 变更图斑与基础地类图斑相交 删除属性完全相同的部分
this.UpdateMsg("变更图斑数据处理...");
paramClass = new GPParamClass();
paramClass.FirstFeatureClass = BGFeatureClass;
paramClass.SecondFeatureClass = JCFeatureLayer.FeatureClass;
paramClass.OutFeatureClassPath = $"{TempfilePath}\\DLTBBG_Intersect";
paramClass.IsGetOutPutFeature = true;
GeoprocessorHelper.IntersectAnalysis(paramClass, ref IntersectAnalysisLayer);
(IntersectAnalysisLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($@" Delete From DLTBBG_Intersect WHERE (DLBM = DLBM_1 and DLMC = DLMC_1 and QSXZ = QSXZ_1 and QSDWDM = QSDWDM_1 and QSDWMC = QSDWMC_1 and ZLDWDM = ZLDWDM_1 and ZLDWMC = ZLDWMC_1 and
(KCDLBM = KCDLBM_1 or(KCDLBM is null and KCDLBM_1 is null)) and
(KCXS = KCXS_1 or(KCXS is null and KCXS_1 is null)) and
(GDLX = GDLX_1 or(GDLX is null and GDLX_1 is null)) and
(GDPDJB = GDPDJB_1 or(GDPDJB is null and GDPDJB_1 is null)) and
(XZDWKD = XZDWKD_1 or(XZDWKD is null and XZDWKD_1 is null)) and
(TBXHDM = TBXHDM_1 or(TBXHDM is null and TBXHDM_1 is null)) and
(TBXHMC = TBXHMC_1 or(TBXHMC is null and TBXHMC_1 is null)) and
(ZZSXDM = ZZSXDM_1 or(ZZSXDM is null and ZZSXDM_1 is null)) and
(ZZSXMC = ZZSXMC_1 or(ZZSXMC is null and ZZSXMC_1 is null)) and
(GDDB = GDDB_1 or(GDDB is null and GDDB_1 is null)) and
(FRDBS = FRDBS_1 or(FRDBS is null and FRDBS_1 is null)) and
(CZCSXM = CZCSXM_1 or(CZCSXM is null and CZCSXM_1 is null)) and
(MSSM = MSSM_1 or(MSSM is null and MSSM_1 is null)) and
(HDMC = HDMC_1 or(HDMC is null and HDMC_1 is null))
) ");
#endregion
#region 变更图斑 属性相同 图形相邻的合并
paramClass = new GPParamClass();
paramClass.FirstFeatureClass = IntersectAnalysisLayer.FeatureClass;
paramClass.OutFeatureClassPath = $"{TempfilePath}\\DLTBBG";
paramClass.IsGetOutPutFeature = true;
paramClass.ListDissolveFiledName = new List<string>() { "DLBM", "DLMC", "QSXZ", "QSDWDM", "QSDWMC", "ZLDWDM", "ZLDWMC", "KCDLBM", "KCXS", "GDLX", "GDPDJB", "XZDWKD", "TBXHDM", "TBXHMC", "ZZSXDM", "ZZSXMC", "GDDB", "FRDBS", "CZCSXM", "MSSM", "HDMC" };
GeoprocessorHelper.DissolveAnalysis(paramClass, ref BGFeatureClass_Dissolve);
ITable Dissolve = BGFeatureClass_Dissolve as ITable;
Dissolve.DeleteSearchedRows(new QueryFilterClass() { WhereClause = "DLBM ='1001' or DLBM ='1002' or DLBM ='1003' or DLBM='1004' or DLBM ='1006' or DLBM='1009' or DLBM='1101' or DLBM='1107' or DLBM='1107A'" });
IWorkspaceAPI wsAPI_temp = new WorkspaceAPI(TempfilePath, WorkspaceTypeEnum.GDBFile);
IFeatureClassAPI DLTBBG_temp1 = wsAPI_temp.OpenFeatureClass("DLTBBG");
FcToFc(BGFeatureClass, DLTBBG_temp1.FeatureClass, new QueryFilterClass() { WhereClause = "DLBM ='1001' or DLBM ='1002' or DLBM ='1003' or DLBM='1004' or DLBM ='1006' or DLBM='1009' or DLBM='1101' or DLBM='1107' or DLBM='1107A'" });
//添加字段
IFieldEdit _field = new FieldClass();
_field.Name_2 = "TBMJ";
_field.Type_2 = esriFieldType.esriFieldTypeDouble;
_field.Length_2 = 8;
if (BGFeatureClass_Dissolve.FeatureClass.FindField("TBMJ") == -1)
BGFeatureClass_Dissolve.FeatureClass.AddField(_field as IField);
#endregion
#region 设置基础地类图斑选中
if (JCFeatureLayer.FeatureClass.FeatureCount(null) != BGFeatureClass_Dissolve.FeatureClass.FeatureCount(null))
{
paramClass.Tolerance = "0.0001";
paramClass.FirstFeatureLayer = JCFeatureLayer;
paramClass.SecondFeatureClass = BGFeatureClass_Dissolve.FeatureClass;
paramClass.IsGetOutPutFeature = true;
GeoprocessorHelper.SelectLayerByLocationAnalysis(paramClass, "INTERSECT", ref SelectFeatureLayer);
}
#endregion
#region 变更层与基础地类图斑联合
paramClass = new GPParamClass()
{
FirstFeatureClass = BGFeatureClass_Dissolve.FeatureClass,
SecondFeatureLayer = JCFeatureLayer,
OutFeatureClassPath = $"{TempfilePath}\\BGTB_DLTBUnion",
IsGetOutPutFeature = true,
PreserveAttributes = "ALL"
};
GeoprocessorHelper.UnionAnalysis(paramClass, ref Temp_DLTBGXGC);
#endregion
#region 拆分多部件
paramClass = new GPParamClass();
paramClass.FirstFeatureClass = Temp_DLTBGXGC.FeatureClass;
paramClass.OutFeatureClassPath = $"{TempfilePath}\\GXGC_Multipart";
paramClass.IsGetOutPutFeature = true;
GeoprocessorHelper.MultipartToSinglePath(paramClass, ref multipartToSingleFeatureLayer);
#endregion
#region 面积计算
pCursor = multipartToSingleFeatureLayer.FeatureClass.Update(new QueryFilterClass() { SubFields = "TBMJ,SHAPE" }, true);
var _itbmj = multipartToSingleFeatureLayer.FeatureClass.FindField("TBMJ");
while ((feature = pCursor.NextFeature()) != null)
{
feature.Value[_itbmj] = feature.Shape.GetEllipseArea().ToDouble();
pCursor.UpdateFeature(feature);
if (feature != null)
Marshal.ReleaseComObject(feature);
}
pCursor.Flush();
#endregion
#region TableToTable
string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
IWorkspaceFactory pOutWorkFactory = null;
pOutWorkFactory = new SqlWorkspaceFactoryClass();
IWorkspace pOutWork = pOutWorkFactory.OpenFromFile(dbPath, 0);
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
rdbHelper.ExecuteSQL(" drop table GXGC_Multipart ");
IWorkspace ws = (multipartToSingleFeatureLayer.FeatureClass as FeatureClass).Workspace;
//添加字段
_field = new FieldClass();
_field.Name_2 = "BGXW";
_field.Type_2 = esriFieldType.esriFieldTypeString;
_field.Length_2 = 2;
if (multipartToSingleFeatureLayer.FeatureClass.FindField("BGXW") == -1)
multipartToSingleFeatureLayer.FeatureClass.AddField(_field as IField);
//矢量数据至db文件
TableToTable(ws as IFeatureWorkspace, pOutWork, "GXGC_Multipart");
#region BGXW=2
//变更图斑与基础库图斑一对多
rdbHelper.ExecuteSQL(" UPDATE GXGC_Multipart set BGXW='2' where FID_DLTBBG in (select FID_DLTBBG from GXGC_Multipart where FID_DLTBBG <> -1 GROUP BY FID_DLTBBG HAVING COUNT(FID_DLTBBG) > 1) ");
rdbHelper.ExecuteSQL(@" UPDATE GXGC_Multipart set BGXW='2' where BGXW ISNULL and FID_DLTB in (select FID_DLTB from GXGC_Multipart GROUP BY FID_DLTB HAVING COUNT(FID_DLTB) > 1 ) ");
#endregion
#region BGXW=1
rdbHelper.ExecuteSQL(@"UPDATE GXGC_Multipart set BGXW='1' where BGXW ISNULL and OBJECTID in (select OBJECTID from
(
select FID_DLTBBG,OBJECTID,BGXW,
case when DLBM ISNULL OR DLBM=' ' THEN '' ELSE DLBM END DLBM,
case when DLBM_1 ISNULL OR DLBM_1=' ' THEN '' ELSE DLBM_1 END DLBM_1,
case when DLMC ISNULL OR DLMC=' ' THEN '' ELSE DLMC END DLMC,
case when DLMC_1 ISNULL OR DLMC_1=' ' THEN '' ELSE DLMC_1 END DLMC_1,
case when QSXZ ISNULL OR QSXZ=' ' THEN '' ELSE QSXZ END QSXZ,
case when QSXZ_1 ISNULL OR QSXZ_1=' ' THEN '' ELSE QSXZ_1 END QSXZ_1,
case when QSDWDM ISNULL OR QSDWDM=' ' THEN '' ELSE QSDWDM END QSDWDM,
case when QSDWDM_1 ISNULL OR QSDWDM_1=' ' THEN '' ELSE QSDWDM_1 END QSDWDM_1,
case when QSDWMC ISNULL OR QSDWMC=' ' THEN '' ELSE QSDWMC END QSDWMC,
case when QSDWMC_1 ISNULL OR QSDWMC_1=' ' THEN '' ELSE QSDWMC_1 END QSDWMC_1,
case when ZLDWDM ISNULL OR ZLDWDM=' ' THEN '' ELSE ZLDWDM END ZLDWDM,
case when ZLDWDM_1 ISNULL OR ZLDWDM_1=' ' THEN '' ELSE ZLDWDM_1 END ZLDWDM_1,
case when ZLDWMC ISNULL OR ZLDWMC=' ' THEN '' ELSE ZLDWMC END ZLDWMC,
case when ZLDWMC_1 ISNULL OR ZLDWMC_1=' ' THEN '' ELSE ZLDWMC_1 END ZLDWMC_1,
case when KCDLBM ISNULL or KCDLBM=' ' THEN '' ELSE KCDLBM END KCDLBM,
case when KCDLBM_1 ISNULL or KCDLBM_1=' ' THEN '' ELSE KCDLBM_1 END KCDLBM_1,
case when KCXS ISNULL or KCXS=' ' THEN '' ELSE KCXS END KCXS,
case when KCXS_1 ISNULL or KCXS_1=' ' THEN '' ELSE KCXS_1 END KCXS_1,
case when GDLX ISNULL or GDLX=' ' THEN '' ELSE GDLX END GDLX,
case when GDLX_1 ISNULL or GDLX_1=' ' THEN '' ELSE GDLX_1 END GDLX_1,
case when GDPDJB ISNULL or GDPDJB=' ' THEN '' ELSE GDPDJB END GDPDJB,
case when GDPDJB_1 ISNULL or GDPDJB_1=' ' THEN '' ELSE GDPDJB_1 END GDPDJB_1,
case when XZDWKD ISNULL or XZDWKD=' ' or XZDWKD=0.0 THEN 0 ELSE XZDWKD END XZDWKD,
case when XZDWKD_1 ISNULL or XZDWKD_1=' ' or XZDWKD_1=0.0 THEN 0 ELSE XZDWKD_1 END XZDWKD_1,
case when TBXHDM ISNULL or TBXHDM=' ' THEN '' ELSE TBXHDM END TBXHDM,
case when TBXHDM_1 ISNULL or TBXHDM_1=' ' THEN '' ELSE TBXHDM_1 END TBXHDM_1,
case when TBXHMC ISNULL or TBXHMC=' ' THEN '' ELSE TBXHMC END TBXHMC,
case when TBXHMC_1 ISNULL or TBXHMC_1=' ' THEN '' ELSE TBXHMC_1 END TBXHMC_1,
case when ZZSXDM ISNULL or ZZSXDM=' ' THEN '' ELSE ZZSXDM END ZZSXDM,
case when ZZSXDM_1 ISNULL or ZZSXDM_1=' ' THEN '' ELSE ZZSXDM_1 END ZZSXDM_1,
case when ZZSXMC ISNULL or ZZSXMC=' ' THEN '' ELSE ZZSXMC END ZZSXMC,
case when ZZSXMC_1 ISNULL or ZZSXMC_1=' ' THEN '' ELSE ZZSXMC_1 END ZZSXMC_1,
case when GDDB ISNULL or GDDB=' ' or GDDB=0 THEN '' ELSE GDDB END GDDB,
case when GDDB_1 ISNULL or GDDB_1=' ' or GDDB_1=0 THEN '' ELSE GDDB_1 END GDDB_1,
case when FRDBS ISNULL or FRDBS=' ' THEN '' ELSE FRDBS END FRDBS,
case when FRDBS_1 ISNULL or FRDBS_1=' ' THEN '' ELSE FRDBS_1 END FRDBS_1,
case when CZCSXM ISNULL or CZCSXM=' ' THEN '' ELSE CZCSXM END CZCSXM,
case when CZCSXM_1 ISNULL or CZCSXM_1=' ' THEN '' ELSE CZCSXM_1 END CZCSXM_1,
case when MSSM ISNULL or MSSM=' ' THEN '' ELSE MSSM END MSSM,
case when MSSM_1 ISNULL or MSSM_1=' ' THEN '' ELSE MSSM_1 END MSSM_1,
case when HDMC ISNULL or HDMC=' ' THEN '' ELSE HDMC END HDMC,
case when HDMC_1 ISNULL or HDMC_1=' ' THEN '' ELSE HDMC_1 END HDMC_1
from GXGC_Multipart WHERE BGXW ISNULL and
FID_DLTBBG<>-1 and
FID_DLTB in (select FID_DLTB from GXGC_Multipart GROUP BY FID_DLTB HAVING COUNT(FID_DLTB) = 1) and
FID_DLTBBG in (select FID_DLTBBG from GXGC_Multipart GROUP BY FID_DLTBBG HAVING COUNT(FID_DLTBBG) = 1)
)
WHERE (DLBM != DLBM_1 or DLMC != DLMC_1 or QSXZ != QSXZ_1 or QSDWDM != QSDWDM_1 or QSDWMC != QSDWMC_1 or ZLDWDM != ZLDWDM_1 or ZLDWMC != ZLDWMC_1 or KCDLBM != KCDLBM_1 or KCXS != KCXS_1 or GDLX != GDLX_1 or GDPDJB != GDPDJB_1 or XZDWKD != XZDWKD_1 or TBXHDM != TBXHDM_1 or TBXHMC != TBXHMC_1 or ZZSXDM != ZZSXDM_1 or ZZSXMC != ZZSXMC_1 or GDDB != GDDB_1 or FRDBS != FRDBS_1 or CZCSXM != CZCSXM_1 or MSSM != MSSM_1 or HDMC != HDMC_1) )");
#endregion
#endregion
#region 变更图斑属性相同 图形相邻 且对应基础库相同
DataTable data_BGXW_2 = rdbHelper.ExecuteDatatable("tab", @"select OBJECTID,FID_DLTB,FID_DLTBBG,
case when DLBM ISNULL OR DLBM=' ' THEN '' ELSE DLBM END DLBM,
case when DLBM_1 ISNULL OR DLBM_1=' ' THEN '' ELSE DLBM_1 END DLBM_1,
case when DLMC ISNULL OR DLMC=' ' THEN '' ELSE DLMC END DLMC,
case when DLMC_1 ISNULL OR DLMC_1=' ' THEN '' ELSE DLMC_1 END DLMC_1,
case when QSXZ ISNULL OR QSXZ=' ' THEN '' ELSE QSXZ END QSXZ,
case when QSXZ_1 ISNULL OR QSXZ_1=' ' THEN '' ELSE QSXZ_1 END QSXZ_1,
case when QSDWDM ISNULL OR QSDWDM=' ' THEN '' ELSE QSDWDM END QSDWDM,
case when QSDWDM_1 ISNULL OR QSDWDM_1=' ' THEN '' ELSE QSDWDM_1 END QSDWDM_1,
case when QSDWMC ISNULL OR QSDWMC=' ' THEN '' ELSE QSDWMC END QSDWMC,
case when QSDWMC_1 ISNULL OR QSDWMC_1=' ' THEN '' ELSE QSDWMC_1 END QSDWMC_1,
case when ZLDWDM ISNULL OR ZLDWDM=' ' THEN '' ELSE ZLDWDM END ZLDWDM,
case when ZLDWDM_1 ISNULL OR ZLDWDM_1=' ' THEN '' ELSE ZLDWDM_1 END ZLDWDM_1,
case when ZLDWMC ISNULL OR ZLDWMC=' ' THEN '' ELSE ZLDWMC END ZLDWMC,
case when ZLDWMC_1 ISNULL OR ZLDWMC_1=' ' THEN '' ELSE ZLDWMC_1 END ZLDWMC_1,
case when KCDLBM ISNULL or KCDLBM=' ' THEN '' ELSE KCDLBM END KCDLBM,
case when KCDLBM_1 ISNULL or KCDLBM_1=' ' THEN '' ELSE KCDLBM_1 END KCDLBM_1,
case when KCXS ISNULL or KCXS=' ' THEN 0 ELSE KCXS END KCXS,
case when KCXS_1 ISNULL or KCXS_1=' ' THEN 0 ELSE KCXS_1 END KCXS_1,
case when GDLX ISNULL or GDLX=' ' THEN '' ELSE GDLX END GDLX,
case when GDLX_1 ISNULL or GDLX_1=' ' THEN '' ELSE GDLX_1 END GDLX_1,
case when GDPDJB ISNULL or GDPDJB=' ' THEN '' ELSE GDPDJB END GDPDJB,
case when GDPDJB_1 ISNULL or GDPDJB_1=' ' THEN '' ELSE GDPDJB_1 END GDPDJB_1,
case when XZDWKD ISNULL or XZDWKD=' ' or XZDWKD=0.0 THEN 0 ELSE XZDWKD END XZDWKD,
case when XZDWKD_1 ISNULL or XZDWKD_1=' ' or XZDWKD_1=0.0 THEN 0 ELSE XZDWKD_1 END XZDWKD_1,
case when TBXHDM ISNULL or TBXHDM=' ' THEN '' ELSE TBXHDM END TBXHDM,
case when TBXHDM_1 ISNULL or TBXHDM_1=' ' THEN '' ELSE TBXHDM_1 END TBXHDM_1,
case when TBXHMC ISNULL or TBXHMC=' ' THEN '' ELSE TBXHMC END TBXHMC,
case when TBXHMC_1 ISNULL or TBXHMC_1=' ' THEN '' ELSE TBXHMC_1 END TBXHMC_1,
case when ZZSXDM ISNULL or ZZSXDM=' ' THEN '' ELSE ZZSXDM END ZZSXDM,
case when ZZSXDM_1 ISNULL or ZZSXDM_1=' ' THEN '' ELSE ZZSXDM_1 END ZZSXDM_1,
case when ZZSXMC ISNULL or ZZSXMC=' ' THEN '' ELSE ZZSXMC END ZZSXMC,
case when ZZSXMC_1 ISNULL or ZZSXMC_1=' ' THEN '' ELSE ZZSXMC_1 END ZZSXMC_1,
case when GDDB ISNULL or GDDB=' ' or GDDB=0 THEN 0 ELSE GDDB END GDDB,
case when GDDB_1 ISNULL or GDDB_1=' ' or GDDB_1=0 THEN 0 ELSE GDDB_1 END GDDB_1,
case when FRDBS ISNULL or FRDBS=' ' THEN '' ELSE FRDBS END FRDBS,
case when FRDBS_1 ISNULL or FRDBS_1=' ' THEN '' ELSE FRDBS_1 END FRDBS_1,
case when CZCSXM ISNULL or CZCSXM=' ' THEN '' ELSE CZCSXM END CZCSXM,
case when CZCSXM_1 ISNULL or CZCSXM_1=' ' THEN '' ELSE CZCSXM_1 END CZCSXM_1,
case when MSSM ISNULL or MSSM=' ' THEN '' ELSE MSSM END MSSM,
case when MSSM_1 ISNULL or MSSM_1=' ' THEN '' ELSE MSSM_1 END MSSM_1,
case when HDMC ISNULL or HDMC=' ' THEN '' ELSE HDMC END HDMC,
case when HDMC_1 ISNULL or HDMC_1=' ' THEN '' ELSE HDMC_1 END HDMC_1
from GXGC_Multipart WHERE BGXW = 2 ", true);
DataTable data_FID_DLTB = rdbHelper.ExecuteDatatable("tab", @" select FID_DLTB,DLBM, DLMC, QSXZ, QSDWDM, QSDWMC, ZLDWDM, ZLDWMC, KCDLBM, KCXS, GDLX, GDPDJB, XZDWKD, TBXHDM, TBXHMC, ZZSXDM, ZZSXMC, GDDB, FRDBS, CZCSXM, MSSM, HDMC from GXGC_Multipart WHERE BGXW = 2 GROUP BY FID_DLTB HAVING count(FID_DLTB)>1
", true);
foreach (DataRow row in data_FID_DLTB.Rows)
{
var rows = data_BGXW_2.Select($"FID_DLTB ='{row["FID_DLTB"]}' and FID_DLTBBG<>-1 ");
bool isIdentical = true;
if (rows.Count() > 0)
{
if (rows.Count() == 1)
{
if (rows[0]["DLBM"].ToTrim() == rows[0]["DLBM_1"].ToTrim() &&
rows[0]["DLMC"].ToTrim() == rows[0]["DLMC_1"].ToTrim() &&
rows[0]["QSXZ"].ToTrim() == rows[0]["QSXZ_1"].ToTrim() &&
rows[0]["QSDWDM"].ToTrim() == rows[0]["QSDWDM_1"].ToTrim() &&
rows[0]["QSDWMC"].ToTrim() == rows[0]["QSDWMC_1"].ToTrim() &&
rows[0]["ZLDWDM"].ToTrim() == rows[0]["ZLDWDM_1"].ToTrim() &&
rows[0]["ZLDWMC"].ToTrim() == rows[0]["ZLDWMC_1"].ToTrim() &&
rows[0]["KCDLBM"].ToTrim() == rows[0]["KCDLBM_1"].ToTrim() &&
rows[0]["KCXS"].ToTrim() == rows[0]["KCXS_1"].ToTrim() &&
rows[0]["GDLX"].ToTrim() == rows[0]["GDLX_1"].ToTrim() &&
rows[0]["GDPDJB"].ToTrim() == rows[0]["GDPDJB_1"].ToTrim() &&
rows[0]["XZDWKD"].ToTrim() == rows[0]["XZDWKD_1"].ToTrim() &&
rows[0]["TBXHDM"].ToTrim() == rows[0]["TBXHDM_1"].ToTrim() &&
rows[0]["TBXHMC"].ToTrim() == rows[0]["TBXHMC_1"].ToTrim() &&
rows[0]["ZZSXDM"].ToTrim() == rows[0]["ZZSXDM_1"].ToTrim() &&
rows[0]["ZZSXMC"].ToTrim() == rows[0]["ZZSXMC_1"].ToTrim() &&
rows[0]["GDDB"].ToTrim() == rows[0]["GDDB_1"].ToTrim() &&
rows[0]["FRDBS"].ToTrim() == rows[0]["FRDBS_1"].ToTrim() &&
rows[0]["CZCSXM"].ToTrim() == rows[0]["CZCSXM_1"].ToTrim() &&
rows[0]["MSSM"].ToTrim() == rows[0]["MSSM_1"].ToTrim() &&
rows[0]["HDMC"].ToTrim() == rows[0]["HDMC_1"].ToTrim())
{
rdbHelper.ExecuteSQL($" UPDATE GXGC_Multipart set BGXW=NULL where FID_DLTB={row["FID_DLTB"]} ;");
continue;
}
}
else
{
for (int i = 0; i < rows.Count(); i++)
{
var j = i + 1;
foreach (DataColumn column in data_BGXW_2.Columns)
{
if (column.ColumnName == "FID_DLTB" || column.ColumnName == "OBJECTID" || column.ColumnName.Contains("_1") || column.ColumnName == "FID_DLTBBG") continue;
if (j > rows.Count() - 1) break;
if (rows[i][column.ColumnName].ToString().ToTrim() != rows[j][column.ColumnName].ToString().ToTrim())
{
isIdentical = false;
break;
}
}
}
if (isIdentical)
{
foreach (DataRow item in rows)
{
if (rows[0]["DLBM"].ToTrim() != rows[0]["DLBM_1"].ToTrim() ||
item["DLMC"].ToTrim() != item["DLMC_1"].ToTrim() ||
item["QSXZ"].ToTrim() != item["QSXZ_1"].ToTrim() ||
item["QSDWDM"].ToTrim() != item["QSDWDM_1"].ToTrim() ||
item["QSDWMC"].ToTrim() != item["QSDWMC_1"].ToTrim() ||
item["ZLDWDM"].ToTrim() != item["ZLDWDM_1"].ToTrim() ||
item["ZLDWMC"].ToTrim() != item["ZLDWMC_1"].ToTrim() ||
item["KCDLBM"].ToTrim() != item["KCDLBM_1"].ToTrim() ||
item["KCXS"].ToTrim() != item["KCXS_1"].ToTrim() ||
item["GDLX"].ToTrim() != item["GDLX_1"].ToTrim() ||
item["GDPDJB"].ToTrim() != item["GDPDJB_1"].ToTrim() ||
item["XZDWKD"].ToTrim() != item["XZDWKD_1"].ToTrim() ||
item["TBXHDM"].ToTrim() != item["TBXHDM_1"].ToTrim() ||
item["TBXHMC"].ToTrim() != item["TBXHMC_1"].ToTrim() ||
item["ZZSXDM"].ToTrim() != item["ZZSXDM_1"].ToTrim() ||
item["ZZSXMC"].ToTrim() != item["ZZSXMC_1"].ToTrim() ||
item["GDDB"].ToTrim() != item["GDDB_1"].ToTrim() ||
item["FRDBS"].ToTrim() != item["FRDBS_1"].ToTrim() ||
item["CZCSXM"].ToTrim() != item["CZCSXM_1"].ToTrim() ||
item["MSSM"].ToTrim() != item["MSSM_1"].ToTrim() ||
item["HDMC"].ToTrim() != item["HDMC_1"].ToTrim())
{
isIdentical = false;
break;
}
}
}
if (isIdentical)
{
rdbHelper.ExecuteSQL($" UPDATE GXGC_Multipart set BGXW=NULL where FID_DLTB={row["FID_DLTB"]} ;");
}
}
}
}
#endregion
#region 图形相邻 属性相同的 需要与基础库合并的数据
DataTable data = rdbHelper.ExecuteDatatable("tab", "select OBJECTID, DLBM_1, DLMC_1, QSXZ_1, QSDWDM_1, QSDWMC_1, ZLDWDM_1, ZLDWMC_1, KCDLBM_1, KCXS_1, GDLX_1, GDPDJB_1, XZDWKD_1, TBXHDM_1, TBXHMC_1, ZZSXDM_1, ZZSXMC_1, GDDB_1, FRDBS_1, CZCSXM_1, MSSM_1, HDMC_1 from GXGC_Multipart WHERE BGXW ISNULL", true);
if (data != null && data.Rows.Count > 0)
{
List<string> DLList = new List<string>() { "1001", "1002", "1003", "1004", "1006", "1009", "1101", "1107", "1107A" };
foreach (DataRow row in data.Rows)
{
IFeature f = multipartToSingleFeatureLayer.FeatureClass.GetFeature(row["OBJECTID"].ToInt());
if (DLList.Contains(row["DLBM_1"].ToTrim())) continue;
var IdentifyList = FeatureAPI.Identify(f.ShapeCopy, multipartToSingleFeatureLayer);
foreach (var ifeature in IdentifyList)
{
if (ifeature.OID == row["OBJECTID"].ToInt()) continue;//相同ID的不进行对比
if (ifeature.Value[ifeature.Fields.FindField("FID_DLTBBG")].ToString() == "-1") continue;
//图形相邻 属性相同且共边
var length = FeatureAPI.LengthOfSide(f.Shape, ifeature.Shape);
if (length == 0) continue;
bool isIdentical = true;
foreach (DataColumn column in data.Columns)
{
if (column.ColumnName == "OBJECTID") continue;
int index = ifeature.Fields.FindField(column.ColumnName.Replace("_1", ""));
if (index != -1)
{
var thisrow = row[column].ToString().ToTrim();
var thisfeature = ifeature.Value[index].ToString().ToTrim();
if (thisrow != thisfeature)
{
if ((thisrow == "0" && string.IsNullOrEmpty(thisfeature)) || (thisfeature == "0" && string.IsNullOrEmpty(thisrow)))
continue;
isIdentical = false;
break;
}
}
}
if (isIdentical)
{
//判断变更图斑与基础图斑属性是否相同
var FID_DLTB = ifeature.Value[ifeature.Fields.FindField("FID_DLTB")].ToString();
string sqlwhere = string.Empty;
DataTable contrast = null;
contrast = rdbHelper.ExecuteDatatable("tab", $@"select OBJECTID from GXGC_Multipart WHERE FID_DLTB={FID_DLTB}", true);
if (contrast != null && contrast.Rows.Count == 1)
{
rdbHelper.ExecuteSQL($" UPDATE GXGC_Multipart set BGXW='2' where OBJECTID={row["OBJECTID"]} ;");
break;
}
else
{
contrast = rdbHelper.ExecuteDatatable("tab", $@" select * from (select OBJECTID,FID_DLTB,FID_DLTBBG,case when DLBM ISNULL OR DLBM = ' ' THEN '' ELSE DLBM END DLBM,case when DLBM_1 ISNULL OR DLBM_1 = ' ' THEN '' ELSE DLBM_1 END DLBM_1,case when DLMC ISNULL OR DLMC = ' ' THEN '' ELSE DLMC END DLMC,case when DLMC_1 ISNULL OR DLMC_1 = ' ' THEN '' ELSE DLMC_1 END DLMC_1,case when QSXZ ISNULL OR QSXZ = ' ' THEN '' ELSE QSXZ END QSXZ,case when QSXZ_1 ISNULL OR QSXZ_1 = ' ' THEN '' ELSE QSXZ_1 END QSXZ_1,case when QSDWDM ISNULL OR QSDWDM = ' ' THEN '' ELSE QSDWDM END QSDWDM,case when QSDWDM_1 ISNULL OR QSDWDM_1 = ' ' THEN '' ELSE QSDWDM_1 END QSDWDM_1,case when QSDWMC ISNULL OR QSDWMC = ' ' THEN '' ELSE QSDWMC END QSDWMC,case when QSDWMC_1 ISNULL OR QSDWMC_1 = ' ' THEN '' ELSE QSDWMC_1 END QSDWMC_1,case when ZLDWDM ISNULL OR ZLDWDM = ' ' THEN '' ELSE ZLDWDM END ZLDWDM,case when ZLDWDM_1 ISNULL OR ZLDWDM_1 = ' ' THEN '' ELSE ZLDWDM_1 END ZLDWDM_1,case when ZLDWMC ISNULL OR ZLDWMC = ' ' THEN '' ELSE ZLDWMC END ZLDWMC,case when ZLDWMC_1 ISNULL OR ZLDWMC_1 = ' ' THEN '' ELSE ZLDWMC_1 END ZLDWMC_1,case when KCDLBM ISNULL or KCDLBM = ' ' THEN '' ELSE KCDLBM END KCDLBM,case when KCDLBM_1 ISNULL or KCDLBM_1 = ' ' THEN '' ELSE KCDLBM_1 END KCDLBM_1,case when KCXS ISNULL or KCXS = ' ' THEN '' ELSE KCXS END KCXS,case when KCXS_1 ISNULL or KCXS_1 = ' ' THEN '' ELSE KCXS_1 END KCXS_1,case when GDLX ISNULL or GDLX = ' ' THEN '' ELSE GDLX END GDLX,case when GDLX_1 ISNULL or GDLX_1 = ' ' THEN '' ELSE GDLX_1 END GDLX_1,case when GDPDJB ISNULL or GDPDJB = ' ' THEN '' ELSE GDPDJB END GDPDJB,case when GDPDJB_1 ISNULL or GDPDJB_1 = ' ' THEN '' ELSE GDPDJB_1 END GDPDJB_1,case when XZDWKD ISNULL or XZDWKD = ' ' or XZDWKD = 0.0 THEN 0 ELSE XZDWKD END XZDWKD,case when XZDWKD_1 ISNULL or XZDWKD_1 = ' ' or XZDWKD_1 = 0.0 THEN 0 ELSE XZDWKD_1 END XZDWKD_1,case when TBXHDM ISNULL or TBXHDM = ' ' THEN '' ELSE TBXHDM END TBXHDM,case when TBXHDM_1 ISNULL or TBXHDM_1 = ' ' THEN '' ELSE TBXHDM_1 END TBXHDM_1,case when TBXHMC ISNULL or TBXHMC = ' ' THEN '' ELSE TBXHMC END TBXHMC,case when TBXHMC_1 ISNULL or TBXHMC_1 = ' ' THEN '' ELSE TBXHMC_1 END TBXHMC_1,case when ZZSXDM ISNULL or ZZSXDM = ' ' THEN '' ELSE ZZSXDM END ZZSXDM,case when ZZSXDM_1 ISNULL or ZZSXDM_1 = ' ' THEN '' ELSE ZZSXDM_1 END ZZSXDM_1,case when ZZSXMC ISNULL or ZZSXMC = ' ' THEN '' ELSE ZZSXMC END ZZSXMC,case when ZZSXMC_1 ISNULL or ZZSXMC_1 = ' ' THEN '' ELSE ZZSXMC_1 END ZZSXMC_1,case when GDDB ISNULL or GDDB = ' ' or GDDB = 0 THEN 0 ELSE GDDB END GDDB,case when GDDB_1 ISNULL or GDDB_1 = ' ' or GDDB_1 = 0 THEN 0 ELSE GDDB_1 END GDDB_1,case when FRDBS ISNULL or FRDBS = ' ' THEN '' ELSE FRDBS END FRDBS,case when FRDBS_1 ISNULL or FRDBS_1 = ' ' THEN '' ELSE FRDBS_1 END FRDBS_1,case when CZCSXM ISNULL or CZCSXM = ' ' THEN '' ELSE CZCSXM END CZCSXM,case when CZCSXM_1 ISNULL or CZCSXM_1 = ' ' THEN '' ELSE CZCSXM_1 END CZCSXM_1,case when MSSM ISNULL or MSSM = ' ' THEN '' ELSE MSSM END MSSM,case when MSSM_1 ISNULL or MSSM_1 = ' ' THEN '' ELSE MSSM_1 END MSSM_1,case when HDMC ISNULL or HDMC = ' ' THEN '' ELSE HDMC END HDMC,case when HDMC_1 ISNULL or HDMC_1 = ' ' THEN '' ELSE HDMC_1 END HDMC_1 from GXGC_Multipart WHERE FID_DLTB = {FID_DLTB} and FID_DLTBBG<>-1 ) WHERE (DLBM != DLBM_1 or DLMC != DLMC_1 or QSXZ != QSXZ_1 or QSDWDM != QSDWDM_1 or QSDWMC != QSDWMC_1 or ZLDWDM != ZLDWDM_1 or ZLDWMC != ZLDWMC_1 or KCDLBM != KCDLBM_1 or KCXS != KCXS_1 or GDLX != GDLX_1 or GDPDJB != GDPDJB_1 or XZDWKD != XZDWKD_1 or TBXHDM != TBXHDM_1 or TBXHMC != TBXHMC_1 or ZZSXDM != ZZSXDM_1 or ZZSXMC != ZZSXMC_1 or GDDB != GDDB_1 or FRDBS != FRDBS_1 or CZCSXM != CZCSXM_1 or MSSM != MSSM_1 or HDMC != HDMC_1)", true);
if (contrast != null && contrast.Rows.Count > 0)
{
rdbHelper.ExecuteSQL($" UPDATE GXGC_Multipart set BGXW='2' where OBJECTID={row["OBJECTID"]} ;");
break;
}
}
}
}
}
}
data = rdbHelper.ExecuteDatatable("tab", "select OBJECTID,DLBM, DLMC, QSXZ, QSDWDM, QSDWMC, ZLDWDM, ZLDWMC, KCDLBM, KCXS, GDLX, GDPDJB, XZDWKD, TBXHDM, TBXHMC, ZZSXDM, ZZSXMC, GDDB, FRDBS, CZCSXM, MSSM, HDMC,DLBM_1, DLMC_1, QSXZ_1, QSDWDM_1, QSDWMC_1, ZLDWDM_1, ZLDWMC_1, KCDLBM_1, KCXS_1, GDLX_1, GDPDJB_1, XZDWKD_1, TBXHDM_1, TBXHMC_1, ZZSXDM_1, ZZSXMC_1, GDDB_1, FRDBS_1, CZCSXM_1, MSSM_1, HDMC_1 from GXGC_Multipart WHERE BGXW=1 ", true);
if (data != null && data.Rows.Count > 0)
{
foreach (DataRow row in data.Rows)
{
IFeature f = multipartToSingleFeatureLayer.FeatureClass.GetFeature(row["OBJECTID"].ToInt());
var IdentifyList = FeatureAPI.Identify(f.ShapeCopy, multipartToSingleFeatureLayer);
foreach (var ifeature in IdentifyList)
{
if (ifeature.OID == row["OBJECTID"].ToInt()) continue;//相同ID的不进行对比
//图形相邻 属性相同且共边
var length = FeatureAPI.LengthOfSide(f.Shape, ifeature.Shape);
if (length == 0) continue;
bool isIdentical = true;
if (ifeature.Value[ifeature.Fields.FindField("FID_DLTBBG")].ToString() == "-1")
{
foreach (DataColumn column in data.Columns)
{
if (column.ColumnName == "OBJECTID") continue;
if (column.ColumnName.Contains("_1")) continue;
int index = ifeature.Fields.FindField($"{ column.ColumnName}_1");
if (index != -1)
{
var thisrow = row[column].ToString().ToTrim();
var thisfeature = ifeature.Value[index].ToString().ToTrim();
if (thisrow != thisfeature)
{
if ((thisrow == "0" && string.IsNullOrEmpty(thisfeature)) || (thisfeature == "0" && string.IsNullOrEmpty(thisrow)))
continue;
isIdentical = false;
break;
}
}
}
}
else
{
foreach (DataColumn column in data.Columns)
{
if (column.ColumnName == "OBJECTID") continue;
if (column.ColumnName.Contains("_1")) continue;
int index = ifeature.Fields.FindField(column.ColumnName);
if (index != -1)
{
var thisrow = row[column].ToString().ToTrim();
var thisfeature = ifeature.Value[index].ToString().ToTrim();
if (thisrow != thisfeature)
{
if ((thisrow == "0" && string.IsNullOrEmpty(thisfeature)) || (thisfeature == "0" && string.IsNullOrEmpty(thisrow)))
continue;
isIdentical = false;
break;
}
}
}
}
if (isIdentical)
{
rdbHelper.ExecuteSQL($" UPDATE GXGC_Multipart set BGXW='2' where OBJECTID={row["OBJECTID"]} ;");
break;
}
}
}
}
#endregion
#region 面积平差
DataTable data_BSM = rdbHelper.ExecuteDatatable("tab", "select BSM,TBMJ_1 from GXGC_Multipart GROUP BY BSM HAVING count(BSM)>1", true);
data = rdbHelper.ExecuteDatatable("tab", "select OBJECTID,BSM,TBMJ,TBMJ_1 from GXGC_Multipart ", true);
Dictionary<int, double> _GXGCvaluePairs = new Dictionary<int, double>();//记录平差结果
if (data_BSM != null && data_BSM.Rows.Count > 0)
{
foreach (DataRow row in data_BSM.Rows)
{
var jc_TBMJ = row["TBMJ_1"].ToDouble();
List<Adjustment> shpList = new List<Adjustment>();
var rows = data.Select($"BSM ='{row["BSM"]}'");
foreach (var item in rows)
{
shpList.Add(new Adjustment()
{
ID = item["OBJECTID"].ToInt(),
bgmj = item["TBMJ"].ToDouble()
});
}
if (shpList.Count > 0)
{
AreaAdjustment(shpList, jc_TBMJ);//面积平差
foreach (var item in shpList)
{
if (!_GXGCvaluePairs.ContainsKey(item.ID))
_GXGCvaluePairs.Add(item.ID, item.bgmj);
}
}
}
}
#endregion
#region 生成更新过程层
this.UpdateMsg("正在生成更新过程层数据...");
DataTable data_BGXW = rdbHelper.ExecuteDatatable("tab", @"select FID_DLTBBG,FID_DLTB,BGXW,OBJECTID,TBMJ_1 from GXGC_Multipart WHERE BGXW NOTNULL ", true);
GXGCFcToFc(multipartToSingleFeatureLayer.FeatureClass, GXGCFC, null, false, data_BGXW, _GXGCvaluePairs);
#endregion
#region 生成更新层
this.UpdateMsg("正在生成更新层数据...");
GXFcToFc(GXGCFC, GXFC, new QueryFilterClass() { WhereClause = "BGHDLBM <>'1001' and BGHDLBM <>'1002' and BGHDLBM <>'1003' and BGHDLBM<>'1004' and BGHDLBM <>'1006' and BGHDLBM<>'1009' and BGHDLBM<>'1101' and BGHDLBM<>'1107' and BGHDLBM<>'1107A'" });
paramClass = new GPParamClass();
paramClass.FirstFeatureClass = GXFC;
paramClass.OutFeatureClassPath = $"{TempfilePath}\\GX_Dissolve";
paramClass.IsGetOutPutFeature = true;
paramClass.ListDissolveFiledName = new List<string>() { "DLBM", "DLMC", "QSXZ", "QSDWDM", "QSDWMC", "ZLDWDM", "ZLDWMC", "KCDLBM", "KCXS", "GDLX", "GDPDJB", "TBXHDM", "TBXHMC", "ZZSXDM", "ZZSXMC", "GDDB", "FRDBS", "CZCSXM", "MSSM", "HDMC" };
GeoprocessorHelper.DissolveAnalysis(paramClass, ref DissolveAnalysisFeatureLayer);
dltbgxTb.DeleteSearchedRows(null);
fcAPI = new FeatureClassAPI(DissolveAnalysisFeatureLayer.FeatureClass);
fcAPI.FcToFc(GXFC, null, false);
GXFcToFc(GXGCFC, GXFC, new QueryFilterClass() { WhereClause = "BGHDLBM ='1001' or BGHDLBM ='1002' or BGHDLBM ='1003' or BGHDLBM='1004' or BGHDLBM ='1006' or BGHDLBM='1009' or BGHDLBM='1101' or BGHDLBM='1107' or BGHDLBM='1107A'" });
#endregion
#region 更新层/更新过程层 标识码,图斑编号等赋值
paramClass = new GPParamClass()
{
FirstFeatureClass = GXFC,
SecondFeatureLayer = GXGCFC_Layer,
OutFeatureClassPath = $"{TempfilePath}\\GX_GXGCUnion",
IsGetOutPutFeature = true,
PreserveAttributes = "ALL"
};
GeoprocessorHelper.UnionAnalysis(paramClass, ref Temp_DLTBGXGC);
ws = (Temp_DLTBGXGC.FeatureClass as FeatureClass).Workspace;
rdbHelper.ExecuteSQL(" drop table GX_GXGCUnion ");
TableToTable(ws as IFeatureWorkspace, pOutWork, "GX_GXGCUnion");
DataTable GX_GXGCUnion = rdbHelper.ExecuteDatatable("tab", "select FID_DLTBGX,FID_DLTBGXGC,TBBGMJ,ZLDWDM,BGXW,BGHTBBH,BGHTBBSM from GX_GXGCUnion", true);
Dictionary<int, string[]> bsmDic = new Dictionary<int, string[]>();
Dictionary<int, int> OIDdic = new Dictionary<int, int>();
var strBSM = GetNewBSM(new List<IFeatureClass>() { JCFeatureLayer.FeatureClass });
Dictionary<string, int> dicTBBH = new Dictionary<string, int>();
GetMaxTBBH(JCFeatureLayer.FeatureClass, ref dicTBBH);
foreach (DataRow item in GX_GXGCUnion.Rows)
{
int gxID = item["FID_DLTBGX"].ToInt();
string zldwdm = item["ZLDWDM"].ToString();
string bgxw = item["BGXW"].ToString();
string TBBH = string.Empty;
if (!bsmDic.ContainsKey(gxID))
{
if (bgxw == "2")
{
var strbsm = strBSM.Substring(0, 10);
var Maxbsm = strBSM.Substring(10).ToInt() + 1;
strBSM = strbsm + Maxbsm.ToString().PadLeft(8, '0');//最新标识码
if (dicTBBH.ContainsKey(zldwdm))
{
dicTBBH[zldwdm] = dicTBBH[zldwdm] + 1;//最大图斑编号-取最新值
TBBH = dicTBBH[zldwdm].ToTrim();
}
else
{
dicTBBH.Add(zldwdm, 1);
TBBH = dicTBBH[zldwdm].ToTrim();
}
bsmDic.Add(gxID, new string[] { strBSM, TBBH });
}
else
{
bsmDic.Add(gxID, new string[] { item["BGHTBBSM"].ToString(), item["BGHTBBH"].ToString() });
}
}
int gxgcID = item["FID_DLTBGXGC"].ToInt();
if (!OIDdic.ContainsKey(gxgcID))
{
OIDdic.Add(gxgcID, gxID);
}
}
pCursor = GXFC.Update(null, true);
var _index_BSM = GXFC.FindField("BSM");
var _index_YSDM = GXFC.FindField("YSDM");//2001010100
var _index_TBBH = GXFC.FindField("TBBH");
var _index_TBMJ = GXFC.FindField("TBMJ");
var _index_KCXS = GXFC.FindField("KCXS");
var _index_KCMJ = GXFC.FindField("KCMJ");
var _index_TBDLMJ = GXFC.FindField("TBDLMJ");
var igx_gxsj = GXFC.FindField("GXSJ");
var igx_xzqtzlx = GXFC.FindField("XZQTZLX");
while ((feature = pCursor.NextFeature()) != null)
{
int oid = feature.OID;
if (bsmDic.ContainsKey(oid))
{
string[] arr = bsmDic[oid];
feature.Value[_index_BSM] = arr[0];
feature.Value[_index_TBBH] = arr[1];
}
var kcxs = feature.Value[_index_KCXS].ToDouble();//扣除系数
feature.Value[_index_YSDM] = "2001010100";//要素代码
DataRow[] row = GX_GXGCUnion.Select($"FID_DLTBGX={feature.OID}");
double mj = 0.00;
if (row.Length > 0)
{
string gxgcid = string.Join(" or ", row.Select(r => $"OBJECTID = {r["FID_DLTBGXGC"].ToString()}")).ToString();
mj = row.Select(r => r["TBBGMJ"].ToDouble()).Sum().ToDouble();
}
feature.Value[_index_TBMJ] = mj;
feature.Value[_index_KCMJ] = Math.Round(mj * kcxs, 2);
feature.Value[_index_TBDLMJ] = Math.Round(mj - mj * kcxs, 2);
feature.Value[igx_gxsj] = new DateTime(DateTime.Now.Year - 1, 12, 31);
feature.Value[igx_xzqtzlx] = 0;
pCursor.UpdateFeature(feature);
}
pCursor.Flush();
pCursor = GXGCFC.Update(null, true);
int iBGHTBBSM = GXGCFC.FindField("BGHTBBSM");
int iBGHTBBH = GXGCFC.FindField("BGHTBBH");
var igxgc_xzqtzlx = GXGCFC.FindField("XZQTZLX");
while ((feature = pCursor.NextFeature()) != null)
{
int oid = feature.OID;
if (OIDdic.ContainsKey(oid))
{
int gxOID = OIDdic[oid];
if (bsmDic.ContainsKey(gxOID))
{
string[] arr = bsmDic[gxOID];
feature.Value[iBGHTBBSM] = arr[0];
feature.Value[iBGHTBBH] = arr[1];
}
}
feature.Value[igxgc_xzqtzlx] = 0;
pCursor.UpdateFeature(feature);
}
pCursor.Flush();
#endregion
#region 坐落信息变更
//给定图斑进行变更
//if (SelLocation_Layer != null && SelLocation_Layer.FeatureClass.FeatureCount(null) != 0)
//{
//}
//给定坐落信息进行变更
if (ListZLXXInfo.Count > 0)
{
this.UpdateMsg("正在进行坐落信息变更,请稍后...");
GX_GXGCUnion = rdbHelper.ExecuteDatatable("tab", "select DISTINCT BGQTBBSM from GX_GXGCUnion", true);
foreach (ZLXXInfo item in ListZLXXInfo)
{
if (string.IsNullOrWhiteSpace(item.BGQDM.ToTrim()) || string.IsNullOrWhiteSpace(item.BGHDM.ToTrim())) continue;
//if (item.BGQDM.ToTrim().Length == 6 && item.BGHDM.ToTrim().Length == 6)
//{
// DataTable _GX_GXGCUnion = GX_GXGCUnion.Clone();
// _GX_GXGCUnion.Clear();
// ImplementZLBG(JCFeatureLayer.FeatureClass, GXFC, GXGCFC, null, _GX_GXGCUnion, dicTBBH, item);
//}
#region 根据变更前坐落单位代码 在基础库查询出数据 插入更新层更新过程层 更新层中已存在则排除
#region 修改更新层/更新过程层中的坐落信息变化的图斑
itable = GXGCFC as ITable;
iCursor = itable.Update(new QueryFilterClass() { SubFields = "OBJECTID,BGHZLDWDM,BGHZLDWMC,BGHQSDWDM,BGHQSDWMC", WhereClause = $"BGHZLDWDM like '{item.BGQDM}%'" }, true);
int iBGHZLDWDM = GXGCFC.FindField("BGHZLDWDM");
int iBGHZLDWMC = GXGCFC.FindField("BGHZLDWMC");
int iBGHQSDWDM = GXGCFC.FindField("BGHQSDWDM");
int iBGHQSDWMC = GXGCFC.FindField("BGHQSDWMC");
while ((irow = iCursor.NextRow()) != null)
{
if (item.BGQDM.ToTrim().Length == 19 && item.BGHDM.ToTrim().Length == 19)//19位的修改代码和名称
{
irow.Value[iBGHZLDWDM] = item.BGHDM;
irow.Value[iBGHZLDWMC] = item.BGHMC;
irow.Value[iBGHQSDWDM] = item.BGHDM;
irow.Value[iBGHQSDWMC] = item.BGHMC;
}
else
{
irow.Value[iBGHZLDWDM] = irow.Value[iBGHZLDWDM].ToString().Replace(item.BGQDM, item.BGHDM);
irow.Value[iBGHQSDWDM] = irow.Value[iBGHQSDWDM].ToString().Replace(item.BGQDM, item.BGHDM);
}
iCursor.UpdateRow(irow);
}
iCursor.Flush();
itable = GXFC as ITable;
iCursor = itable.Update(new QueryFilterClass() { SubFields = "OBJECTID,ZLDWDM,ZLDWMC,QSDWDM,QSDWMC", WhereClause = $"ZLDWDM like '{item.BGQDM}%'" }, true);
int iZLDWDM = GXFC.FindField("ZLDWDM");
int iZLDWMC = GXFC.FindField("ZLDWMC");
int iQSDWDM = GXFC.FindField("QSDWDM");
int iQSDWMC = GXFC.FindField("QSDWMC");
while ((irow = iCursor.NextRow()) != null)
{
if (item.BGQDM.ToTrim().Length == 19 && item.BGHDM.ToTrim().Length == 19)//19位的修改代码和名称
{
irow.Value[iZLDWDM] = item.BGHDM;
irow.Value[iZLDWMC] = item.BGHMC;
irow.Value[iQSDWDM] = item.BGHDM;
irow.Value[iQSDWMC] = item.BGHMC;
}
else
{
irow.Value[iZLDWDM] = irow.Value[iZLDWDM].ToString().Replace(item.BGQDM, item.BGHDM);
irow.Value[iQSDWDM] = irow.Value[iQSDWDM].ToString().Replace(item.BGQDM, item.BGHDM);
}
iCursor.UpdateRow(irow);
}
iCursor.Flush();
#endregion
//将坐落变更的图斑添加至更新层更新过程层
//ImplementZLBG(JCFeatureLayer.FeatureClass, GXFC, GXGCFC, new QueryFilterClass() { WhereClause = $"ZLDWDM like '{item.BGQDM }%'" }, GX_GXGCUnion, dicTBBH, item);
#endregion
}
}
#endregion
LogAPI.Debug($"地类图斑数据提取_结束时间:{DateTime.Now}");
}
catch (Exception ex)
{
LogAPI.Debug("地类图斑数据提取失败:" + ex.Message);
LogAPI.Debug(ex);
throw ex;
}
finally
{
if (JCFeatureLayer != null)
Marshal.ReleaseComObject(JCFeatureLayer);
if (GXFC != null)
Marshal.ReleaseComObject(GXFC);
if (GXGCFC != null)
Marshal.ReleaseComObject(GXGCFC);
if (BGFeatureClass != null)
Marshal.ReleaseComObject(BGFeatureClass);
}
}
#endregion
#region 获取最新图斑编号
private static void GetMaxTBBH(IFeatureClass fc, ref Dictionary<string, int> result)
{
ICursor cursor = (fc as ITable).Search(new QueryFilterClass() { SubFields = "OBJECTID,ZLDWDM,TBBH" }, true);
IRow row = null;
int zlIndex = -1;
int bhIndex = -1;
try
{
while ((row = cursor.NextRow()) != null)
{
if (zlIndex == -1)
zlIndex = row.Fields.FindField("ZLDWDM");
if (bhIndex == -1)
bhIndex = row.Fields.FindField("TBBH");
if (zlIndex != -1 && bhIndex != -1)
{
string zl = row.Value[zlIndex].ToTrim();
zl = zl.Replace(zl.Substring(0, 6), (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE);
int tbbh = 0;
int.TryParse(row.Value[bhIndex].ToString(), out tbbh);
if (result.ContainsKey(zl))
{
if (result[zl] < tbbh)
result[zl] = tbbh;
}
else
{
result.Add(zl, tbbh);
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("获取最新图斑编号失败:" + ex.Message);
LogAPI.Debug(ex);
}
}
#endregion
#region 获取最新标识码
public static string GetNewBSM(List<IFeatureClass> fcList)
{
string result = string.Empty;
int xh = 0;
string leftStr = string.Empty;
foreach (var item in fcList)
{
string MaxBSM = GetMaxBSM(item);
if (MaxBSM.Length != 18)
continue;
int xh2 = Convert.ToInt32(MaxBSM.Substring(10));
leftStr = MaxBSM.Substring(0, 10);
if (xh < xh2)
xh = xh2;
}
xh++;
if (string.IsNullOrWhiteSpace(leftStr))
leftStr = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + "1210";
result = leftStr + xh.ToString().PadLeft(8, '0');
return result;
}
private static string GetMaxBSM(IFeatureClass fc)
{
System.Windows.Forms.Application.DoEvents();
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;
}
return BSM;
}
#endregion
#region DelectDirect
private static void DelectDirect(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) //判断是否文件夹
{
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
subdir.Delete(true); //删除子目录和文件
}
else
{
File.Delete(i.FullName); //删除指定文件
}
}
}
catch (Exception e)
{
throw;
}
}
#endregion
#region 面积平差
/// <summary>
/// 面积平差
/// </summary>
/// <param name="shpList">需要平差的对象集合</param>
/// <param name="pKZMJ">控制面积</param>
public void AreaAdjustment(List<Adjustment> shpList, double pKZMJ)
{
try
{
if (shpList.Count == 1)
{
shpList[0].bgmj = pKZMJ;
return;
}
shpList = shpList.OrderByDescending(o => o.bgmj).ToList();
double mjc = Math.Round(shpList.Sum(s => s.bgmj) - 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].bgmj = shpList[i].bgmj + tpmj;
else
shpList[i].bgmj = shpList[i].bgmj - tpmj;
}
}
if (e != 0)
{
double tpmj = e * 0.01;
for (int i = f; i < shpList.Count; i++)
{
if (mjc < 0)
shpList[i].bgmj = shpList[i].bgmj + tpmj;
else
shpList[i].bgmj = shpList[i].bgmj - tpmj;
}
}
mjc = Math.Round(shpList.Sum(s => s.bgmj), 2) - pKZMJ;
}
}
catch (Exception ex)
{
LogAPI.Debug("面积平差错误:" + ex.Message);
throw ex;
}
}
#endregion
#region GXGCFcToFc
public bool GXGCFcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, IQueryFilter pFilter, bool pIsCut, DataTable data_BSM, Dictionary<int, double> GXGCvaluePairs)
{
IFeatureCursor S_Cursor = null;
IFeatureCursor T_Cursor = null;
try
{
if (FeatureClass == null || pFc == null) return false;
//获取对应关系
Dictionary<int, int> dicField = new Dictionary<int, int>();
Dictionary<int, int> dicField1 = new Dictionary<int, int>();
for (int i = 0; i < pFc.Fields.FieldCount; i++)
{
IField field = pFc.Fields.Field[i];
if (field.Name == pFc.ShapeFieldName || field.Name.Contains(pFc.ShapeFieldName) || field.Name == pFc.OIDFieldName || !field.Editable) continue;
int index = -1;
if (field.Name.Contains("BGQ"))
{
index = FeatureClass.Fields.FindField($"{field.Name.Replace("BGQTB", "")}_1");
if (index == -1)
index = FeatureClass.Fields.FindField($"{field.Name.Replace("BGQ", "")}_1");
if (index == -1)
index = FeatureClass.Fields.FindField($"{field.Name.Replace("BGQ", "")}");
}
if (field.Name.Contains("BGH"))
{
index = FeatureClass.Fields.FindField(field.Name.Replace("BGHTB", ""));
if (index == -1)
index = FeatureClass.Fields.FindField(field.Name.Replace("BGH", ""));
}
if (field.Name == "BGHTBBSM" || field.Name == "BGQTBBSM")
{
index = FeatureClass.Fields.FindField($"BSM");
}
if (index == -1) continue;
dicField.Add(i, index);
index = FeatureClass.Fields.FindField($"{field.Name.Replace("BGQTB", "").Replace("BGHTB", "")}_1");
if (index == -1)
index = FeatureClass.Fields.FindField($"{field.Name.Replace("BGQ", "").Replace("BGH", "")}_1");
if (field.Name == "BGHTBBSM" || field.Name == "BGQTBBSM")
{
index = FeatureClass.Fields.FindField($"BSM");
}
if (index == -1) continue;
dicField1.Add(i, index);
}
IFeatureClassLoad pFclsLoad = pFc as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//此处写编辑的代码
S_Cursor = FeatureClass.Search(pFilter, true);
IFeature f = null;
IFeatureBuffer buffer = pFc.CreateFeatureBuffer();
T_Cursor = pFc.Insert(true);
var iFID_DLTBBG = FeatureClass.FindField("FID_DLTBBG");
var iFID_DLTB = FeatureClass.FindField("FID_DLTB");
var ibgxw = pFc.FindField("BGXW");
var itbbgmj = pFc.FindField("TBBGMJ");
var ibgqkcxs = pFc.FindField("BGQKCXS");
var ibgqkcmj = pFc.FindField("BGQKCMJ");
var ibgqtbdlmj = pFc.FindField("BGQTBDLMJ");
var ibghkcxs = pFc.FindField("BGHKCXS");
var ibghkcmj = pFc.FindField("BGHKCMJ");
var ibghtbdlmj = pFc.FindField("BGHTBDLMJ");
var ibsm = pFc.FindField("BSM");
var igxsj = pFc.FindField("GXSJ");
var tbbgmj = 0.00;
int bsm = 1;
while ((f = S_Cursor.NextFeature()) != null)
{
var FID_DLTBBG = f.Value[iFID_DLTBBG].ToString();
var FID_DLTB = f.Value[iFID_DLTB].ToString();
var row = data_BSM.Select($"FID_DLTBBG={FID_DLTBBG} and FID_DLTB={FID_DLTB} ");
if (row == null || row.Length == 0) continue;
buffer.Shape = f.ShapeCopy;
if (pFilter is ISpatialFilter && pIsCut)
{
if (FeatureAPI.IsInterSect((pFilter as ISpatialFilter).Geometry, f.ShapeCopy))
{
buffer.Shape = FeatureAPI.InterSect(f.ShapeCopy, (pFilter as SpatialFilterClass).Geometry);
}
else
{
continue;
}
}
if (FID_DLTBBG == "-1")
{
foreach (int item in dicField1.Keys)//被动变更的图斑 变更前后属性相同
{
try
{
buffer.Value[item] = f.Value[dicField1[item]].ToTrim();
}
catch
{
buffer.Value[item] = f.Value[dicField1[item]];
}
}
}
else
{
foreach (int item in dicField.Keys)
{
try
{
buffer.Value[item] = f.Value[dicField[item]].ToTrim();
}
catch
{
buffer.Value[item] = f.Value[dicField[item]];
}
}
}
buffer.Value[ibgxw] = row[0]["BGXW"];
if (GXGCvaluePairs.ContainsKey(f.OID))
tbbgmj = GXGCvaluePairs[f.OID];
else
tbbgmj = row[0]["TBMJ_1"].ToDouble();
buffer.Value[itbbgmj] = tbbgmj;//图斑变更面积
buffer.Value[ibgqkcmj] = buffer.Value[ibgqkcxs].ToDouble() * tbbgmj;//变更前扣除面积
buffer.Value[ibgqtbdlmj] = tbbgmj - buffer.Value[ibgqkcxs].ToDouble() * tbbgmj;//变更前图斑地类面积
buffer.Value[ibghkcmj] = buffer.Value[ibghkcxs].ToDouble() * tbbgmj;//变更后扣除面积
buffer.Value[ibghtbdlmj] = tbbgmj - buffer.Value[ibghkcxs].ToDouble() * tbbgmj;//变更后图斑地类面积
buffer.Value[ibsm] = $"{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).CODE}2111{(bsm++).ToString().PadLeft(8, '0')}";
buffer.Value[igxsj] = new DateTime(DateTime.Now.Year - 1, 12, 31);
T_Cursor.InsertFeature(buffer);
}
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region GXFcToFc
public bool GXFcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, IQueryFilter pFilter)
{
IFeatureCursor S_Cursor = null;
IFeatureCursor T_Cursor = null;
try
{
if (FeatureClass == null || pFc == null) return false;
Dictionary<int, int> dicField = new Dictionary<int, int>();
int index = -1;
for (int i = 0; i < pFc.Fields.FieldCount; i++)
{
IField field = pFc.Fields.Field[i];
if (field.Name == pFc.ShapeFieldName || field.Name.Contains(pFc.ShapeFieldName) || field.Name == pFc.OIDFieldName || !field.Editable) continue;
index = FeatureClass.Fields.FindField($"BGH{field.Name}");
if (index == -1)
continue;
dicField.Add(i, index);
}
IFeatureClassLoad pFclsLoad = pFc as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//此处写编辑的代码
S_Cursor = FeatureClass.Search(pFilter, true);
IFeature f = null;
IFeatureBuffer buffer = pFc.CreateFeatureBuffer();
T_Cursor = pFc.Insert(true);
while ((f = S_Cursor.NextFeature()) != null)
{
buffer.Shape = f.ShapeCopy;
foreach (int item in dicField.Keys)
{
buffer.Value[item] = f.Value[dicField[item]];
}
T_Cursor.InsertFeature(buffer);
}
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception)
{
throw;
}
}
#endregion
#region FcToFc
public bool FcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, IQueryFilter pFilter)
{
IFeatureCursor S_Cursor = null;
IFeatureCursor T_Cursor = null;
try
{
if (FeatureClass == null || pFc == null) return false;
Dictionary<int, int> dicField = new Dictionary<int, int>();
int index = -1;
for (int i = 0; i < pFc.Fields.FieldCount; i++)
{
IField field = pFc.Fields.Field[i];
if (field.Name == pFc.ShapeFieldName || field.Name.Contains(pFc.ShapeFieldName) || field.Name == pFc.OIDFieldName || !field.Editable) continue;
index = FeatureClass.Fields.FindField($"{field.Name}");
if (index == -1)
continue;
dicField.Add(i, index);
}
IFeatureClassLoad pFclsLoad = pFc as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//此处写编辑的代码
S_Cursor = FeatureClass.Search(pFilter, true);
IFeature f = null;
IFeatureBuffer buffer = pFc.CreateFeatureBuffer();
T_Cursor = pFc.Insert(true);
while ((f = S_Cursor.NextFeature()) != null)
{
buffer.Shape = f.ShapeCopy;
foreach (int item in dicField.Keys)
{
buffer.Value[item] = f.Value[dicField[item]];
}
T_Cursor.InsertFeature(buffer);
}
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception)
{
throw;
}
}
#endregion
#region ImplementZLBG
public bool ImplementZLBG(IFeatureClass JCFC, IFeatureClass GXFC, IFeatureClass GXGCFC, IQueryFilter pFilter, DataTable dataTable, Dictionary<string, int> dicTBBH, ZLXXInfo zLXXInfo)
{
IFeatureCursor S_Cursor = null;
IFeatureCursor GX_Cursor = null;
IFeatureCursor GXGC_Cursor = null;
try
{
if (JCFC == null || GXFC == null) return false;
#region 获取字段对应关系
Dictionary<int, int> GXdicField = new Dictionary<int, int>();//更新层
Dictionary<int, int> GXGCdicField = new Dictionary<int, int>();//更新过程层
int index = -1;
#region 更新层
for (int i = 0; i < GXFC.Fields.FieldCount; i++)
{
IField field = GXFC.Fields.Field[i];
if (field.Name == GXFC.ShapeFieldName || field.Name.Contains(GXFC.ShapeFieldName) || field.Name == GXFC.OIDFieldName || !field.Editable) continue;
index = JCFC.Fields.FindField(field.Name);
if (index == -1)
continue;
GXdicField.Add(i, index);
}
#endregion
#region 更新过程层
for (int i = 0; i < GXGCFC.Fields.FieldCount; i++)
{
IField field = GXGCFC.Fields.Field[i];
if (field.Name == "BSM" || field.Name == "BGHTBBSM" || field.Name == GXGCFC.ShapeFieldName || field.Name.Contains(GXGCFC.ShapeFieldName) || field.Name == GXGCFC.OIDFieldName || !field.Editable) continue;
index = JCFC.Fields.FindField($"{field.Name.Replace("BGQTB", "").Replace("BGHTB", "")}");
if (index == -1)
index = JCFC.Fields.FindField($"{field.Name.Replace("BGQ", "").Replace("BGH", "")}");
if (index == -1)
continue;
GXGCdicField.Add(i, index);
}
#endregion
#endregion
#region 属性赋值
IFeatureClassLoad pFclsLoad = GXFC as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//此处写编辑的代码
S_Cursor = JCFC.Search(pFilter, true);
IFeature f = null;
IFeatureBuffer GXbuffer = GXFC.CreateFeatureBuffer();
IFeatureBuffer GXGCbuffer = GXGCFC.CreateFeatureBuffer();
GX_Cursor = GXFC.Insert(true);
GXGC_Cursor = GXGCFC.Insert(true);
#region 索引
#region 基础
int _iJCBSM = JCFC.FindField("BSM");
int _iTBMJ = JCFC.FindField("TBMJ");
int _iJCZLDWDM = JCFC.FindField("ZLDWDM");
int _iJCQSDWDM = JCFC.FindField("QSDWDM");
#endregion
#region 更新
int _iGXTBBH = GXFC.FindField("TBBH");
int _iGXZLDWDM = GXFC.FindField("ZLDWDM");
int _iGXZLDWMC = GXFC.FindField("ZLDWMC");
int _iGXQSDWDM = GXFC.FindField("QSDWDM");
int _iGXQSDWMC = GXFC.FindField("QSDWMC");
#endregion
#region 更新过程
int _iGXGCTBBH = GXGCFC.FindField("BGHTBBH");
int _iBGXW = GXGCFC.FindField("BGXW");
int _iTBBGMJ = GXGCFC.FindField("TBBGMJ");
int _iBGHZLDWDM = GXGCFC.FindField("BGHZLDWDM");
int _iBGHZLDWMC = GXGCFC.FindField("BGHZLDWMC");
int _iBGHQSDWDM = GXGCFC.FindField("BGHQSDWDM");
int _iBGHQSDWMC = GXGCFC.FindField("BGHQSDWMC");
int _iGXGCBSM = GXGCFC.FindField("BSM");
#endregion
#endregion
var strGXGCBSM = GetNewBSM(new List<IFeatureClass>() { GXGCFC });
string zldwdm = zLXXInfo.BGHDM;
string TBBH = string.Empty;
while ((f = S_Cursor.NextFeature()) != null)
{
DataRow[] row = dataTable.Select($"BGQTBBSM={f.Value[_iJCBSM].ToString()}");
if (row.Length > 0) continue;
#region 更新层赋值
GXbuffer.Shape = f.ShapeCopy;
if (dicTBBH.ContainsKey(zldwdm))
{
dicTBBH[zldwdm] = dicTBBH[zldwdm] + 1;//最大图斑编号-去最新值
TBBH = dicTBBH[zldwdm].ToTrim();
}
else
{
dicTBBH.Add(zldwdm, 1);
TBBH = dicTBBH[zldwdm].ToTrim();
}
foreach (int item in GXdicField.Keys)
{
GXbuffer.Value[item] = f.Value[GXdicField[item]];
}
GXbuffer.Value[_iGXTBBH] = TBBH;
GXbuffer.Value[_iGXZLDWDM] = f.Value[_iJCZLDWDM].ToString().Replace(zLXXInfo.BGQDM, zLXXInfo.BGHDM);
GXbuffer.Value[_iGXQSDWDM] = f.Value[_iJCQSDWDM].ToString().Replace(zLXXInfo.BGQDM, zLXXInfo.BGHDM);
if (zLXXInfo.BGQDM.Length == 19 && zLXXInfo.BGHDM.Length == 19)
{
GXbuffer.Value[_iGXZLDWMC] = zLXXInfo.BGHMC;
GXbuffer.Value[_iGXQSDWMC] = zLXXInfo.BGHMC;
}
GX_Cursor.InsertFeature(GXbuffer);
#endregion
#region 更新过程层
GXGCbuffer.Shape = f.ShapeCopy;
foreach (int item in GXGCdicField.Keys)
{
GXGCbuffer.Value[item] = f.Value[GXGCdicField[item]];
}
GXGCbuffer.Value[_iGXGCTBBH] = TBBH;
GXGCbuffer.Value[_iBGXW] = "1";
GXGCbuffer.Value[_iTBBGMJ] = f.Value[_iTBMJ];
var strbsm = strGXGCBSM.Substring(0, 10);
var Maxbsm = strGXGCBSM.Substring(10).ToInt() + 1;
strGXGCBSM = strbsm + Maxbsm.ToString().PadLeft(8, '0');//最新标识码
GXGCbuffer.Value[_iGXGCBSM] = strGXGCBSM;
GXGCbuffer.Value[_iBGHZLDWDM] = f.Value[_iJCZLDWDM].ToString().Replace(zLXXInfo.BGQDM, zLXXInfo.BGHDM);
GXGCbuffer.Value[_iBGHQSDWDM] = f.Value[_iJCQSDWDM].ToString().Replace(zLXXInfo.BGQDM, zLXXInfo.BGHDM);
if (zLXXInfo.BGQDM.Length == 19 && zLXXInfo.BGHDM.Length == 19)
{
GXGCbuffer.Value[_iBGHZLDWMC] = zLXXInfo.BGHMC;
GXGCbuffer.Value[_iBGHQSDWMC] = zLXXInfo.BGHMC;
}
GXGC_Cursor.InsertFeature(GXGCbuffer);
#endregion
}
GX_Cursor.Flush();
GXGC_Cursor.Flush();
#endregion
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception)
{
throw;
}
}
#endregion
#region TableToTable
public bool TableToTable(IFeatureWorkspace pInWork, IWorkspace pOutWork, string tableName, IQueryFilter queryFilter = null)
{
try
{
if (pInWork == null || pOutWork == null || string.IsNullOrEmpty(tableName)) return false;
IWorkspace2 workspace2 = pInWork as IWorkspace2;
if (workspace2 != null)
{
if (!workspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, tableName))
{
return false;
}
}
ITable pInTable = pInWork.OpenTable(tableName);
if (pInTable == null) return false;
IDataset pIndataset = (IDataset)pInTable;
IDatasetName pInDatasetName = (IDatasetName)pIndataset.FullName;
IEnumDataset enumDataset = pOutWork.get_Datasets(esriDatasetType.esriDTTable);
IDataset dataset;
enumDataset.Reset();
while ((dataset = enumDataset.Next()) != null)
{
string[] names = dataset.Name.Split('.');
if (string.Equals(names[names.Length - 1], tableName, StringComparison.CurrentCultureIgnoreCase))
{
dataset.Delete();
break;
}
}
IDataset pOutDataset = (IDataset)pOutWork;
IDatasetName pOutDatasetName = new TableNameClass();
pOutDatasetName.WorkspaceName = (IWorkspaceName)pOutDataset.FullName;
pOutDatasetName.Name = tableName;
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields targetFeatureClassFields = pInTable.Fields;
IFields sourceFeatureClassFields = pInTable.Fields;
IEnumFieldError enumFieldError;
fieldChecker.InputWorkspace = pInWork as IWorkspace;
fieldChecker.ValidateWorkspace = pOutWork;
fieldChecker.Validate(sourceFeatureClassFields, out enumFieldError, out targetFeatureClassFields);
IFeatureDataConverter one2another = new FeatureDataConverterClass();
try
{
one2another.ConvertTable(pInDatasetName, queryFilter, pOutDatasetName, targetFeatureClassFields, "", 1000, 0);
}
finally
{
Marshal.ReleaseComObject(one2another);
}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
throw ex;
}
}
#endregion
}
public class Adjustment
{
public int ID { get; set; }
public double bgmj { get; set; }
}
}