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

2281 lines
122 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using GPHelper;
//using IDEParameter;
using KGIS.Framework.AE;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.AE.GaussCalculate;
using KGIS.Framework.AE.GPHelper;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace KGIS_DLTB
{
public class DLTB_IDGHelper : BaseIDG
{
//private IFeatureClass BGFeatureClass = null;
//private IFeatureLayer JCFeatureLayer = null;
//private IFeatureLayer BgTbLayer = null;
//private IFeatureLayer GxgcTBLayer = null;
//private IFeatureLayer GXPDTLayer = null;
//private IFeatureLayer JCPDTLayer = null;
private string TempDbPath = string.Empty;
private string TempSqlitePath = string.Empty;
IWorkspace pOutWork = null;
Dictionary<int, double> AreaList = new Dictionary<int, double>();
private IDGParameter Parm = null;
public void Execute(IDGParameter parm)
{
Parm = parm;
DateTime StartTime = DateTime.Now;
IFeatureLayer Temp_DLTBGXGC = null;
IFeatureLayer Temp_BGTBLayer = null;//变更图斑融合
IFeatureLayer DissolveAnalysisFeatureLayer = null;//更新层融合后的图层
IFeatureLayer EraseAnalysisLayer = null;
IFeature feature = null;
IFeatureCursor pCursor = null;
IFeatureClassAPI fcAPI = null;
GPParamClass paramClass = new GPParamClass();
try
{
OpenDB(parm);
string TempDir = CreateTempDB("DLTB");
TempDbPath = System.IO.Path.Combine(TempDir, "TempGDB.gdb");
(GxTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL("Delete From DLTBGX WHERE 1=1");
(GxgcTBLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL("Delete From DLTBGXGC WHERE 1=1");
//ITable dltbgxTb = GxTbLayer.FeatureClass as ITable;
//dltbgxTb.DeleteSearchedRows(null);
//ITable dltbgxgcTb = GxgcTBLayer.FeatureClass as ITable;
//dltbgxgcTb.DeleteSearchedRows(null);
#region 判断是否存在坐落变更 提取相关数据
if (Parm.PrjInfo.ListZLXXInfo.Count > 0)
{
Console.WriteLine("Msg:正在处理坐落变更数据...");
string TempZLBGDir = CreateTempDB("DLTB_ZLBG");
string TempZLBGDbPath = System.IO.Path.Combine(TempZLBGDir, "TempGDB.gdb");
IWorkspaceAPI wsAPI = new WorkspaceAPI(TempZLBGDbPath, WorkspaceTypeEnum.GDBFile, true);
IFeatureClassAPI DLTBBG_ZLBGAPI = wsAPI.CreateFeatureClass("DLTBBG", (BgTbLayer.FeatureClass as IGeoDataset).SpatialReference, BgTbLayer.FeatureClass.Fields);
fcAPI = new FeatureClassAPI(JcTbLayer.FeatureClass);
IQueryFilter filter = new QueryFilterClass() { };
bool isMDB = ((IDataset)fcAPI.FeatureClass).Workspace.PathName.ToUpper().Contains(".MDB");
foreach (var item in Parm.PrjInfo.ListZLXXInfo)
{
if (string.IsNullOrWhiteSpace(item.BGQDM.ToTrim()) || string.IsNullOrWhiteSpace(item.BGHDM.ToTrim())) continue;
if (isMDB)
{
if (item.IsQS == "是")
filter.WhereClause = $"QSDWDM like '{item.BGQDM}*'";
else
filter.WhereClause = $"ZLDWDM like '{item.BGQDM}*'";
}
else
{
if (item.IsQS == "是")
filter.WhereClause = $"QSDWDM like '{item.BGQDM}%'";
else
filter.WhereClause = $"ZLDWDM like '{item.BGQDM}%'";
}
fcAPI.FcToFc(DLTBBG_ZLBGAPI.FeatureClass, filter, false);
ITable tempBGTb = DLTBBG_ZLBGAPI.FeatureClass as ITable;
ICursor _cursor = tempBGTb.Update(filter, true);
IRow _row = null;
int _idx = DLTBBG_ZLBGAPI.FeatureClass.FindField("ZLDWDM");
int _idxZLMC = DLTBBG_ZLBGAPI.FeatureClass.FindField("ZLDWMC");
int _idxQS = DLTBBG_ZLBGAPI.FeatureClass.FindField("QSDWDM");
int _idxQSMC = DLTBBG_ZLBGAPI.FeatureClass.FindField("QSDWMC");
int _idxFRDBS = DLTBBG_ZLBGAPI.FeatureClass.FindField("FRDBS");
while ((_row = _cursor.NextRow()) != null && _idx != -1)
{
_row.Value[_idx] = _row.Value[_idx].ToTrim().Replace(item.BGQDM, item.BGHDM);
_row.Value[_idxQS] = _row.Value[_idxQS].ToTrim().Replace(item.BGQDM, item.BGHDM);
_row.Value[_idxZLMC] = _row.Value[_idxZLMC].ToTrim().Replace(item.BGQMC, item.BGHMC);
_row.Value[_idxQSMC] = _row.Value[_idxQSMC].ToTrim().Replace(item.BGQMC, item.BGHMC);
if (_idxFRDBS != -1)
_row.Value[_idxFRDBS] = "0";
_cursor.UpdateRow(_row);
}
_cursor.Flush();
}
#region 变更图斑擦除坐落变更的图斑
paramClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = DLTBBG_ZLBGAPI.FeatureClass };
paramClass.SecondFeatureLayer = BgTbLayer;
paramClass.OutFeatureClassPath = $"{TempZLBGDbPath}\\BGTB_Erase";
paramClass.IsGetOutPutFeature = true;
paramClass.GPType = EnumGPType.Erase;
GPHelper.Instance.ExeGPForProces(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(BgTbLayer.FeatureClass);
fcAPI.FcToFc(DLTBBG_ZLBGAPI.FeatureClass, null, false);
BgTbLayer.FeatureClass = DLTBBG_ZLBGAPI.FeatureClass;
}
#endregion
string dbPath = TempDir + @"\Temp" + ".sqlite";
TempSqlitePath = dbPath;
Console.WriteLine("Msg:正在处理变更图斑数据...");
Temp_BGTBLayer = ProcessBGTB();
IWorkspaceAPI wsAPI1 = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile, true);
IFeatureClassAPI TempGXGCAPI = wsAPI1.OpenFeatureClass("DLTBGXGC");
Temp_DLTBGXGC = new FeatureLayerClass() { FeatureClass = TempGXGCAPI.FeatureClass };
pOutWork = CreateDBWorkspace(dbPath);
//CustomGPHelper.TableToTable(Temp_DLTBGXGC, dbPath, "DLTBGXGC");
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
rdbHelper.ExecuteSQL(" drop table DLTBGXGC ");
TableToTable(wsAPI1.CurrentWorkspace as IFeatureWorkspace, pOutWork, "DLTBGXGC");
//IFeatureLayer ptempLayer = null;
//GPParamClass gPParamClass2 = new GPParamClass();
//gPParamClass2.FirstFeatureLayer = Temp_DLTBGXGC;
//gPParamClass2.GPType = EnumGPType.Default;
//CustomGPHelper.RepairGeo(gPParamClass2);
//IFeatureCursor gcCursor = TempGXGCAPI.FeatureClass.Update(new QueryFilter() { WhereClause = "SHAPE_AREA<0.01" }, true);
//IFeature gcF = null;
//int idx = TempGXGCAPI.FeatureClass.FindField("BGXW");
//rdbHelper.BeginTransaction();
//while ((gcF = gcCursor.NextFeature()) != null)
//{
// IGeometry tempGeo = gcF.ShapeCopy;
// ITopologicalOperator topo = tempGeo as ITopologicalOperator;
// topo.Simplify();
// double area = GetEllipseArea(gcF.ShapeCopy);
// if (area == 0)
// {
// gcF.Value[idx] = "-1";
// gcCursor.UpdateFeature(gcF);
// rdbHelper.ExecuteSQL($"Delete from DLTBGXGC where OBJECTID={gcF.OID}");
// }
//}
//rdbHelper.Commit();
//gcCursor.Flush();
//wsAPI1.CurrentWorkspace.ExecuteSQL("Delete from DLTBGXGC where BGXW='-1'");
rdbHelper.ExecuteSQL("CREATE INDEX IDX_FID_DLTBGX ON DLTBGXGC (FID_DLTBGX);");
//Console.WriteLine("Msg:正在生成临时过程数据...");
//Temp_DLTBGXGC = GenerateTempGXGC(Temp_BGTBLayer, dbPath);
rdbHelper.ExecuteSQL(@"update dltbgxgc set BSM_1= null,TBBH_1=null");
rdbHelper.ExecuteSQL(@"Update DLTBGXGC set KCDLBM ='' where KCDLBM ISNULL or KCDLBM=' ' or TRIM(KCDLBM)='';
Update DLTBGXGC set KCXS=0 where KCXS ISNULL ;
Update DLTBGXGC set GDLX =Null where GDLX ISNULL or GDLX=' ' or TRIM(GDLX)='';
Update DLTBGXGC set GDPDJB ='' where GDPDJB ISNULL or GDPDJB=' ' or TRIM(GDPDJB)='';
Update DLTBGXGC set XZDWKD=0 where XZDWKD ISNULL ;
Update DLTBGXGC set TBXHDM ='' where TBXHDM ISNULL or TBXHDM=' ' or TRIM(TBXHDM)='';
Update DLTBGXGC set TBXHMC ='' where TBXHMC ISNULL or TBXHMC=' ' or TRIM(TBXHMC)='';
Update DLTBGXGC set ZZSXDM ='' where ZZSXDM ISNULL or ZZSXDM=' ' or TRIM(ZZSXDM)='';
Update DLTBGXGC set ZZSXMC ='' where ZZSXMC ISNULL or ZZSXMC=' ' or TRIM(ZZSXMC)='';
Update DLTBGXGC set GDDB =0 where GDDB ISNULL;
Update DLTBGXGC set FRDBS ='' where FRDBS ISNULL or FRDBS=' ' or TRIM(FRDBS)='';
Update DLTBGXGC set CZCSXM ='' where CZCSXM ISNULL or CZCSXM=' ' or TRIM(CZCSXM)='';
Update DLTBGXGC set MSSM ='' where MSSM ISNULL or MSSM=' ' or TRIM(MSSM)='';
Update DLTBGXGC set HDMC ='' where HDMC ISNULL or HDMC=' ' or TRIM(HDMC)='';
Update DLTBGXGC set XZQTZLX =NULL where XZQTZLX ='' or XZQTZLX=' ' or TRIM(XZQTZLX)='';");
Console.WriteLine("Msg:正在进行变更行为赋值...");
#region BGXW=2
//变更图斑与基础库图斑一对多
rdbHelper.ExecuteSQL(" UPDATE DLTBGXGC set BGXW='2' where FID_DLTBGX in (select FID_DLTBGX from DLTBGXGC where FID_DLTBGX <> -1 GROUP BY FID_DLTBGX HAVING COUNT(FID_DLTBGX) > 1) ");
rdbHelper.ExecuteSQL(@" UPDATE DLTBGXGC set BGXW='2' where BGXW IS NULL and BSM in (select BSM from DLTBGXGC GROUP BY BSM HAVING COUNT(BSM) > 1 ) ");
#endregion
rdbHelper.ExecuteSQL(@"update dltbgxgc set bgxw='0' WHERE XZQTZLX is null and OBJECTID in (select objectid from DLTBGXGC WHERE BGXW is null
and TRIM(IfNull(ZLDWDM,'')) = TRIM(IfNull(ZLDWDM_1,''))
and TRIM(IfNull(ZLDWMC,'')) = TRIM(IfNull(ZLDWMC_1,''))
and TRIM(IfNull(QSDWDM,'')) = TRIM(IfNull(QSDWDM_1,''))
and TRIM(IfNull(QSDWMC,'')) = TRIM(IfNull(QSDWMC_1,''))
and TRIM(IfNull(DLBM,'')) = TRIM(IfNull(DLBM_1,''))
and TRIM(IfNull(DLMC,'')) = TRIM(IfNull(DLMC_1,''))
and TRIM(IfNull(QSXZ,'')) = TRIM(IfNull(QSXZ_1,''))
and TRIM(IfNull(KCDLBM,'')) = TRIM(IfNull(KCDLBM_1,''))
and (IfNull(KCXS,0) = IfNull(KCXS_1,0))
and TRIM(IfNull(GDLX,'')) = TRIM(IfNull(GDLX_1,''))
and TRIM(IfNull(GDPDJB,'')) = TRIM(IfNull(GDPDJB_1,''))
and (IfNull(XZDWKD,0) = IfNull(XZDWKD_1,0))
and TRIM(IfNull(TBXHDM,'')) = TRIM(IfNull(TBXHDM_1,''))
and TRIM(IfNull(TBXHMC,'')) = TRIM(IfNull(TBXHMC_1,''))
and TRIM(IfNull(ZZSXDM,'')) = TRIM(IfNull(ZZSXDM_1,''))
and TRIM(IfNull(ZZSXMC,'')) = TRIM(IfNull(ZZSXMC_1,''))
and (IfNull(GDDB,0) = IfNull(GDDB_1,0))
and TRIM(IfNull(FRDBS,'')) = TRIM(IfNull(FRDBS_1,''))
and TRIM(IfNull(CZCSXM,'')) = TRIM(IfNull(CZCSXM_1,''))
and TRIM(IfNull(MSSM,'')) = TRIM(IfNull(MSSM_1,''))
and TRIM(IfNull(HDMC,'')) = TRIM(IfNull(HDMC_1,''))
)");
rdbHelper.ExecuteSQL(@"update dltbgxgc set bgxw='0' WHERE XZQTZLX is null and OBJECTID in (select OBJECTID from DLTBGXGC d WHERE BGXW is null and DLBM in ('0101','0102','0103') and DLBM_1 in ('0101','0102','0103')
and TRIM(IfNull(ZLDWDM,'')) = TRIM(IfNull(ZLDWDM_1,''))
and TRIM(IfNull(ZLDWMC,'')) = TRIM(IfNull(ZLDWMC_1,''))
and TRIM(IfNull(QSDWDM,'')) = TRIM(IfNull(QSDWDM_1,''))
and TRIM(IfNull(QSDWMC,'')) = TRIM(IfNull(QSDWMC_1,''))
and TRIM(IfNull(DLBM,'')) = TRIM(IfNull(DLBM_1,''))
and TRIM(IfNull(DLMC,'')) = TRIM(IfNull(DLMC_1,''))
and TRIM(IfNull(QSXZ,'')) = TRIM(IfNull(QSXZ_1,''))
and TRIM(IfNull(GDPDJB,'')) = TRIM(IfNull(GDPDJB_1,''))
and (IfNull(XZDWKD,0) = IfNull(XZDWKD_1,0))
and TRIM(IfNull(TBXHDM,'')) = TRIM(IfNull(TBXHDM_1,''))
and TRIM(IfNull(TBXHMC,'')) = TRIM(IfNull(TBXHMC_1,''))
and TRIM(IfNull(ZZSXDM,'')) = TRIM(IfNull(ZZSXDM_1,''))
and TRIM(IfNull(ZZSXMC,'')) = TRIM(IfNull(ZZSXMC_1,''))
and (IfNull(GDDB,0) = IfNull(GDDB_1,0))
and TRIM(IfNull(FRDBS,'')) = TRIM(IfNull(FRDBS_1,''))
and TRIM(IfNull(CZCSXM,'')) = TRIM(IfNull(CZCSXM_1,''))
and TRIM(IfNull(MSSM,'')) = TRIM(IfNull(MSSM_1,''))
and TRIM(IfNull(HDMC,'')) = TRIM(IfNull(HDMC_1,''))
)");
#region BGXW=1
rdbHelper.ExecuteSQL(@"update dltbgxgc set bgxw='1' where bgxw is null;");
#endregion
rdbHelper.ExecuteSQL(@"update dltbgxgc set bgxw='3' where xzqtzlx = '3';");
rdbHelper.ExecuteSQL(@"delete from dltbgxgc where bgxw='0';");
Console.WriteLine("Msg:正在进行面积平差...");
#region 面积平差
DataTable data_BSM = rdbHelper.ExecuteDatatable("tab", "select BSM,TBMJ from DLTBGXGC GROUP BY BSM HAVING count(BSM)>1", true);
List<string> pcBSMList = new List<string>();
if (data_BSM != null && data_BSM.Rows.Count > 0)
{
foreach (DataRow row in data_BSM.Rows)
{
var jc_bsm = row["BSM"].ToTrim();
if (!pcBSMList.Contains(jc_bsm))
pcBSMList.Add(jc_bsm);
}
}
pCursor = Temp_DLTBGXGC.FeatureClass.Search(new QueryFilterClass() { SubFields = "OBJECTID,BSM,TBMJ,SHAPE" }, true);
var _itbmj = Temp_DLTBGXGC.FeatureClass.FindField("TBMJ");
var bsmIdx = Temp_DLTBGXGC.FeatureClass.FindField("BSM");
feature = null;
Dictionary<int, double> AreaList = new Dictionary<int, double>();
while ((feature = pCursor.NextFeature()) != null)
{
string bsm = feature.Value[bsmIdx].ToTrim();
if (!pcBSMList.Contains(bsm))
continue;
double area = GetEllipseArea(feature.ShapeCopy);
AreaList.Add(feature.OID, area.ToDouble());
}
DataTable data = rdbHelper.ExecuteDatatable("tab", "select OBJECTID,BSM,ZLDWDM_1,TBMJ from DLTBGXGC ", 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"].ToDouble();
List<Adjustment> shpList = new List<Adjustment>();
var rows = data.Select($"BSM ='{row["BSM"]}'");
foreach (var item in rows)
{
Adjustment adj = new Adjustment();
adj.ID = item["OBJECTID"].ToInt();
if (AreaList.ContainsKey(adj.ID))
adj.bgmj = AreaList[adj.ID];
shpList.Add(adj);
}
if (shpList.Count > 0)
{
AreaAdjustment(shpList, jc_TBMJ);//面积平差
foreach (var item in shpList)
{
if (!_GXGCvaluePairs.ContainsKey(item.ID))
_GXGCvaluePairs.Add(item.ID, item.bgmj);
}
}
}
}
var strBSM = GetNewBSM(new List<IFeatureClass>() { JcTbLayer.FeatureClass });
Dictionary<string, int> dicTBBH = new Dictionary<string, int>();
GetMaxTBBH(JcTbLayer.FeatureClass, ref dicTBBH);
rdbHelper.BeginTransaction();
foreach (var oid in _GXGCvaluePairs.Keys)
{
rdbHelper.ExecuteSQL(string.Format(@"update dltbgxgc set tbbgmj={1} where objectid={0};", oid, _GXGCvaluePairs[oid]));
}
rdbHelper.Commit();
DataTable txbgTB = rdbHelper.ExecuteDatatable("tab", "select OBJECTID,BSM,ZLDWDM_1,TBMJ from DLTBGXGC where (bgxw='2' or bgxw='3') and bsm_1 is null and tbbh_1 is null and tbbgmj is null", true);
rdbHelper.BeginTransaction();
foreach (DataRow item in txbgTB.Rows)
{
rdbHelper.ExecuteSQL(string.Format(@"update dltbgxgc set tbbgmj=TBMJ where objectid={0};", item["OBJECTID"]));
}
rdbHelper.Commit();
#endregion
rdbHelper.ExecuteSQL(string.Format(@"update dltbgxgc set tbbgmj=TBMJ,BSM_1=BSM,TBBH_1=TBBH where BGXW='1'"));
rdbHelper.ExecuteSQL(string.Format(@"update dltbgxgc set shape_area_1=tbbgmj where BGXW='1'"));
#region 调出面积平差
DataTable pcDT = rdbHelper.ExecuteDatatable("pc", "select sum(tbbgmj) from dltbgxgc where xzqtzlx='2'", true);
double tcMJ = pcDT.Rows[0][0].ToDouble();
if (parm.PrjInfo.KZMJ != null && tcMJ > 0)
{
double ldmjc = (parm.PrjInfo.KZMJ.TZQ_LDMJ - parm.PrjInfo.KZMJ.TZH_LDMJ).ToDouble(2);
if (!(parm.PrjInfo.KZMJ.TZQ_LDMJ == 0 && parm.PrjInfo.KZMJ.TZH_LDMJ == 0 && parm.PrjInfo.KZMJ.TZQ_HDMJ == 0 && parm.PrjInfo.KZMJ.TZH_HDMJ == 0))
{
double mjc = (ldmjc - tcMJ).ToDouble(2);
while (mjc != 0)
{
int pcs = Math.Abs(mjc / 0.01).ToInt();
string pcSql = string.Format($@"select objectid,tbbgmj,bsm,xzqtzlx,bgxw from dltbgxgc where xzqtzlx = '2' and bgxw = '2' and tbbgmj<>tbmj ORDER by tbbgmj desc LIMIT {pcs}");
DataTable temp = rdbHelper.ExecuteDatatable("temp", pcSql, true);
pcSql = $@"select * from dltbgxgc where (xzqtzlx='0' or xzqtzlx is null) and bsm in (
select bsm from dltbgxgc where xzqtzlx = '2' and bgxw = '2' and tbbgmj<>tbmj ORDER by tbbgmj desc LIMIT {pcs}
)";
DataTable temp1 = rdbHelper.ExecuteDatatable("temp2", pcSql, true);
Dictionary<string, int> hc_bsmCount = new Dictionary<string, int>();
Dictionary<string, int> bsmCount = new Dictionary<string, int>();
rdbHelper.BeginTransaction();
string upMJSql = $@"
update dltbgxgc set tbbgmj=tbbgmj+0.01 where objectid in (select objectid from dltbgxgc where xzqtzlx = '2' and bgxw = '2' and tbbgmj<>tbmj ORDER by tbbgmj DESC LIMIT {pcs})";
if (mjc < 0)
{
upMJSql = $@"
update dltbgxgc set tbbgmj=tbbgmj-0.01 where objectid in (select objectid from dltbgxgc where xzqtzlx = '2' and bgxw = '2' and tbbgmj<>tbmj ORDER by tbbgmj DESC LIMIT {pcs})";
}
rdbHelper.ExecuteSQL(upMJSql);
for (int i = 0; i < temp.Rows.Count; i++)
{
if (mjc > 0)
{
//+
int oid = temp.Rows[i]["OBJECTID"].ToInt();
string tempBSM = temp.Rows[i]["BSM"].ToTrim();
string strTZLX = temp.Rows[i]["XZQTZLX"].ToTrim();
if (_GXGCvaluePairs.ContainsKey(oid))
{
if (hc_bsmCount.ContainsKey(tempBSM))
{
hc_bsmCount[tempBSM] = hc_bsmCount[tempBSM] + 1;
}
else
{
hc_bsmCount.Add(tempBSM, 1);
}
_GXGCvaluePairs[oid] = (_GXGCvaluePairs[oid] + 0.01).ToDouble(2);
}
}
else
{
//-
int oid = temp.Rows[i]["OBJECTID"].ToInt();
string tempBSM = temp.Rows[i]["BSM"].ToTrim();
string strTZLX = temp.Rows[i]["XZQTZLX"].ToTrim();
if (_GXGCvaluePairs.ContainsKey(oid))
{
if (hc_bsmCount.ContainsKey(tempBSM))
{
hc_bsmCount[tempBSM] = hc_bsmCount[tempBSM] + 1;
}
else
{
hc_bsmCount.Add(tempBSM, 1);
}
_GXGCvaluePairs[oid] = (_GXGCvaluePairs[oid] - 0.01).ToDouble(2);
}
}
}
for (int i = 0; i < temp1.Rows.Count; i++)
{
if (mjc > 0)
{
//+
int oid = temp1.Rows[i]["OBJECTID"].ToInt();
string tempBSM = temp1.Rows[i]["BSM"].ToTrim();
string strTZLX = temp1.Rows[i]["XZQTZLX"].ToTrim();
if (_GXGCvaluePairs.ContainsKey(oid))
{
if (bsmCount.ContainsKey(tempBSM))
{
continue;
}
else
{
bsmCount.Add(tempBSM, 1);
}
double value = 0.01 * hc_bsmCount[tempBSM];
_GXGCvaluePairs[oid] = (_GXGCvaluePairs[oid] - value).ToDouble(2);
rdbHelper.ExecuteSQL($@"update dltbgxgc set tbbgmj=tbbgmj-{value} where objectid={oid}");
}
}
else
{
//-
int oid = temp1.Rows[i]["OBJECTID"].ToInt();
string tempBSM = temp1.Rows[i]["BSM"].ToTrim();
string strTZLX = temp1.Rows[i]["XZQTZLX"].ToTrim();
if (_GXGCvaluePairs.ContainsKey(oid))
{
if (bsmCount.ContainsKey(tempBSM))
{
continue;
}
else
{
bsmCount.Add(tempBSM, 1);
}
double value = 0.01 * hc_bsmCount[tempBSM];
_GXGCvaluePairs[oid] = (_GXGCvaluePairs[oid] + value).ToDouble(2);
rdbHelper.ExecuteSQL($@"update dltbgxgc set tbbgmj=tbbgmj+{value} where objectid={oid}");
}
}
}
rdbHelper.Commit();
if (mjc > 0)
{
mjc = Math.Round(mjc - temp.Rows.Count * 0.01, 2);
}
else if (mjc < 0)
{
mjc = Math.Round(mjc + temp.Rows.Count * 0.01, 2);
}
}
}
}
#endregion
txbgTB = rdbHelper.ExecuteDatatable("tab", "select FID_DLTBGX,sum(tbbgmj) bghtbmj,ZLDWDM_1,BGXW,BSM,XZQTZLX from dltbgxgc where bgxw='2' or bgxw='3' or xzqtzlx='1' or (bgxw='1' and substr(ZLDWDM,0,13)<>substr(ZLDWDM_1,0,13)) group by FID_DLTBGX;", true);
rdbHelper.BeginTransaction();
foreach (DataRow item in txbgTB.Rows)
{
string TBBH = string.Empty;
string BGQBSM = string.Empty;
if (item["BGXW"].ToTrim() != "1" || item["XZQTZLX"].ToTrim() == "1")
{
var strbsm = strBSM.Substring(0, 10);
var Maxbsm = strBSM.Substring(10).ToInt() + 1;
strBSM = strbsm + Maxbsm.ToString().PadLeft(8, '0');//最新标识码
}
else
{
BGQBSM = item["BSM"].ToTrim();
}
string strZLDM = item["ZLDWDM_1"].ToTrim();
if (strZLDM.Length > 12)
strZLDM = strZLDM.Substring(0, 12);
if (dicTBBH.ContainsKey(strZLDM))
{
dicTBBH[strZLDM] = dicTBBH[strZLDM] + 1;//最大图斑编号-去最新值
TBBH = dicTBBH[strZLDM].ToTrim();
}
else
{
dicTBBH.Add(strZLDM, 1);
TBBH = dicTBBH[strZLDM].ToTrim();
}
rdbHelper.ExecuteSQL(string.Format(@"update dltbgxgc set BSM_1='{1}',TBBH_1='{2}',shape_area_1={3} where FID_DLTBGX={0};", item["FID_DLTBGX"], string.IsNullOrWhiteSpace(BGQBSM) ? strBSM : BGQBSM, TBBH, item["BGHTBMJ"]));
}
//foreach (DataRow dr in txbgTB.Rows)
//{
// rdbHelper.ExecuteSQL(string.Format(@"update dltbgxgc set shape_area_1={1} where FID_DLTBGX={0}", dr["FID_DLTBGX"], dr["BGHTBMJ"]));
//}
rdbHelper.Commit();
rdbHelper.ExecuteSQL(string.Format(@"update DLTBGXGC set BZ_1='1' WHERE BGXW ='1'
and
(
TRIM(IfNull(ZLDWDM,'')) != TRIM(IfNull(ZLDWDM_1,''))
or TRIM(IfNull(ZLDWMC,'')) != TRIM(IfNull(ZLDWMC_1,''))
or TRIM(IfNull(QSDWDM,'')) != TRIM(IfNull(QSDWDM_1,''))
or TRIM(IfNull(QSDWMC,'')) != TRIM(IfNull(QSDWMC_1,''))
)
and TRIM(IfNull(DLBM,'')) = TRIM(IfNull(DLBM_1,''))
and TRIM(IfNull(DLMC,'')) = TRIM(IfNull(DLMC_1,''))
and TRIM(IfNull(QSXZ,'')) = TRIM(IfNull(QSXZ_1,''))
and TRIM(IfNull(KCDLBM,'')) = TRIM(IfNull(KCDLBM_1,''))
and ((IfNull(KCXS,0)==0) = (IfNull(KCXS_1,0)=0))
and TRIM(IfNull(GDLX,'')) = TRIM(IfNull(GDLX_1,''))
and TRIM(IfNull(GDPDJB,'')) = TRIM(IfNull(GDPDJB_1,''))
and ((IfNull(XZDWKD,0)==0) = (IfNull(XZDWKD_1,0)=0))
and TRIM(IfNull(TBXHDM,'')) = TRIM(IfNull(TBXHDM_1,''))
and TRIM(IfNull(TBXHMC,'')) = TRIM(IfNull(TBXHMC_1,''))
and TRIM(IfNull(ZZSXDM,'')) = TRIM(IfNull(ZZSXDM_1,''))
and TRIM(IfNull(ZZSXMC,'')) = TRIM(IfNull(ZZSXMC_1,''))
and ((IfNull(GDDB,0)==0) = (IfNull(GDDB_1,0)=0))
and TRIM(IfNull(FRDBS,'')) = TRIM(IfNull(FRDBS_1,''))
and TRIM(IfNull(CZCSXM,'')) = TRIM(IfNull(CZCSXM_1,''))"));
rdbHelper.ExecuteSQL(string.Format(@"update DLTBGXGC set BZ_1='1' WHERE BGXW ='1' and (XZQTZLX = '2' or XZQTZLX = '4')"));
Console.WriteLine("Msg:正在写入过程数据...");
#region 生成更新过程层
DataTable data_BGXW = rdbHelper.ExecuteDatatable("tab", @"select FID_DLTBGX,FID_JC_DLTB,BGXW,TBBGMJ,BSM_1,TBBH_1,OBJECTID,TBMJ,bz_1 from DLTBGXGC WHERE BGXW IS NOT NULL ", true);
GXGCFcToFc(Temp_DLTBGXGC.FeatureClass, GxgcTBLayer.FeatureClass, null, false, data_BGXW, _GXGCvaluePairs);
#endregion
Console.WriteLine("Msg:正在写入更新数据...");
#region 生成更新层
IFeatureClassAPI TempGXAPI = wsAPI1.OpenFeatureClass("DLTBGX");
DataTable dtDLTBGX = rdbHelper.ExecuteDatatable("tab", @"select FID_DLTBGX,shape_area_1 as TBMJ,BSM_1,TBBH_1,BZ_1 from DLTBGXGC WHERE BGXW IS NOT NULL and ((XZQTZLX <> '2' and XZQTZLX<> '4') or XZQTZLX is NULL) ", true);
GXFcToFc(TempGXAPI.FeatureClass, GxTbLayer.FeatureClass, null, dtDLTBGX);
#endregion
#region 关于田坎系数调整:
//1.变更前后均为耕地,涉及切割时,切割后的耕地坡度和田坎系数继承原耕地,不重算(耕地内部二级类变化的,坡度不变,系数调整)。
//2.变更前后均为耕地,涉及合并时,如果合并前的耕地坡度或田坎系数不一样,不合并(位置相邻、地类、坡度、系数等均一致的可合并)。
//3.耕地部分变更为非耕地的,剩余耕地重算坡度级别,并相应调整田坎系数。变更为非耕地的图斑面积大于等于400平米时(多部件合计400),认定为部分变更;否则视同前后均为耕地,按规则1、2处理。
//GD_FGD(GxgcTBLayer.FeatureClass, GxTbLayer.FeatureClass);
#endregion
//CustomGPHelper.RepairGeo(GxTbLayer.FeatureClass);
//CustomGPHelper.RepairGeo(GxgcTBLayer.FeatureClass);
if (Parm != null && Parm.PrjInfo != null && (Parm.PrjInfo.ProjType == EnumProjType.RCBG_BCGD || Parm.PrjInfo.ProjType == EnumProjType.RCBG_ZJG))
{
//为日常变更赋值部分属性
IFeatureCursor featureGC = GxgcTBLayer.FeatureClass.Update(null, true);
IFeature GCFeature = null;
int XMMCIndex = GxgcTBLayer.FeatureClass.FindField("XMMC");
int XMBHIndex = GxgcTBLayer.FeatureClass.FindField("XMBH");
int DKMCIndex = GxgcTBLayer.FeatureClass.FindField("DKMC");
IFeatureLayer BgTbFLayer = OpenLayer(BgWsAPI, "DLTBBG");//只读取属性信息
int BgXMMCIndex = BgTbFLayer.FeatureClass.FindField("XMMC");
int BgXMBHIndex = BgTbFLayer.FeatureClass.FindField("XMBH");
int BgDKMCIndex = BgTbFLayer.FeatureClass.FindField("DKMC");
while ((GCFeature = featureGC.NextFeature()) != null)
{
List<IFeature> features = FeatureAPI.Identify2(GCFeature.ShapeCopy, BgTbFLayer);
if (features == null || features.Count == 0) continue;
if (features.Count == 1)
{
if (XMMCIndex != -1 && BgXMMCIndex != -1)
GCFeature.Value[XMMCIndex] = features[0].Value[BgXMMCIndex];
if (XMBHIndex != -1 && BgXMBHIndex != -1)
GCFeature.Value[XMBHIndex] = features[0].Value[BgXMBHIndex];
if (DKMCIndex != -1 && BgDKMCIndex != -1)
GCFeature.Value[DKMCIndex] = features[0].Value[BgDKMCIndex];
GCFeature.Store();
}
else
{
double sumMJ = 0;
IFeature featureTemp = null;
foreach (IFeature Fitem in features)
{
double sumMJTemp = FeatureAPI.GetInterArea(Fitem.ShapeCopy, GCFeature.ShapeCopy);
if (sumMJTemp > sumMJ)
{
featureTemp = Fitem;
sumMJ = sumMJTemp;
}
}
if (featureTemp != null)
{
if (XMMCIndex != -1 && BgXMMCIndex != -1)
GCFeature.Value[XMMCIndex] = featureTemp.Value[BgXMMCIndex];
if (XMBHIndex != -1 && BgXMBHIndex != -1)
GCFeature.Value[XMBHIndex] = featureTemp.Value[BgXMBHIndex];
if (DKMCIndex != -1 && BgDKMCIndex != -1)
GCFeature.Value[DKMCIndex] = featureTemp.Value[BgDKMCIndex];
GCFeature.Store();
}
else
{
//Console.WriteLine($"Msg:为相交的数据:{GCFeature.OID}");
}
}
}
featureGC.Flush();
}
Console.WriteLine("Msg:正在生成年末数据...");
base.CreateNMK(parm);
Console.WriteLine($"Log:地类图斑数据提取完成。耗时:{GetTime(StartTime)}");
}
catch (Exception ex)
{
LogAPI.Debug(ex);
Console.WriteLine("Err:地类图斑数据提取失败!" + ex.Message);
Console.WriteLine("Err:地类图斑数据提取失败!" + ex.StackTrace);
}
finally
{
//this.CloseLoading();
//if (JcTbLayer.FeatureClass != null)
// Marshal.ReleaseComObject(JcTbLayer.FeatureClass);
//if (GxTbLayer.FeatureClass != null)
// Marshal.ReleaseComObject(GxTbLayer.FeatureClass);
//if (GxgcTBLayer.FeatureClass != null)
// Marshal.ReleaseComObject(GxgcTBLayer.FeatureClass);
//if (BgTbLayer.FeatureClass != null)
// Marshal.ReleaseComObject(BgTbLayer.FeatureClass);
}
}
private void GD_FGD(IFeatureClass DLTBGXGCFC, IFeatureClass DLTBGXFC)
{
IWorkspace pOutWork = null;
try
{
string TempDir = CreateTempDB("KCXSUpdate_1");
string dbPath = TempDir + @"\Temp" + ".sqlite";
pOutWork = CreateDBWorkspace(dbPath);
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
rdbHelper.ExecuteSQL(" drop table DLTBGXGC ");
TableToTable((DLTBGXGCFC as FeatureClass).Workspace as IFeatureWorkspace, pOutWork, "DLTBGXGC");
DataTable dt = rdbHelper.ExecuteDatatable("dt", @" select bgqtbbsm,bghtbbsm,bgqgdpdjb,bghgdpdjb,bgqkcxs,bghkcxs,BGQGDLX,BGHGDLX,TBBGMJ from DLTBGXGC d2 WHERE BGHTBBSM||'-'||TBBGMJ in( select BGHTBBSM||'-'||MAX(TBBGMJ) TBBGMJ from DLTBGXGC d WHERE BGHTBBSM in (select BGHTBBSM from dltbgxgc where substr(bgqdlbm,1,2)='01' and substr(bghdlbm,1,2)='01' and bgxw='2' and (BGQGDPDJB<>BGHGDPDJB or BGQKCXS<> BGHKCXS ) ) group by BGHTBBSM )and bgqtbbsm not in (select bgqtbbsm from (SELECT BGQTBBSM ,substr(bghdlbm,1,2) BGHDLBM,COUNT(1) from dltbgxgc group by BGQTBBSM ,substr(bghdlbm,1,2) ) group by BGQTBBSM HAVING count(1)>1) ", true);
for (int i = 0; i < dt.Rows.Count; i++)
{
(DLTBGXGCFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGXGC set BGHKCXS={dt.Rows[i]["BGQKCXS"]} where BGHTBBSM='{dt.Rows[i]["BGHTBBSM"]}'");
(DLTBGXGCFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGXGC set BGHGDPDJB='{dt.Rows[i]["BGQGDPDJB"]}' where BGHTBBSM='{dt.Rows[i]["BGHTBBSM"]}'");
(DLTBGXGCFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGXGC set BGHGDLX='{dt.Rows[i]["BGQGDLX"]}' where BGHTBBSM='{dt.Rows[i]["BGHTBBSM"]}'");
(DLTBGXFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGX set KCXS={dt.Rows[i]["BGQKCXS"]} where BSM='{dt.Rows[i]["BGHTBBSM"]}'");
(DLTBGXFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGX set GDPDJB='{dt.Rows[i]["BGQGDPDJB"]}' where BSM='{dt.Rows[i]["BGHTBBSM"]}'");
(DLTBGXFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGX set GDLX='{dt.Rows[i]["BGQGDLX"]}' where BSM='{dt.Rows[i]["BGHTBBSM"]}'");
}
}
catch (Exception ex)
{
LogAPI.Debug("异常:" + ex.Message);
}
finally
{
if (pOutWork != null)
Marshal.ReleaseComObject(pOutWork);
}
}
public void CalculateArea(object pParm)
{
try
{
CalcAreaParm CalParm = pParm as CalcAreaParm;
IFeatureLayer _Layer = GeoDBAPI.DeSerialzedPersist(CalParm.StrLayer) as IFeatureLayer;
IFeatureCursor pCursor = _Layer.FeatureClass.Search(new QueryFilterClass() { SubFields = "OBJECTID,BSM,TBMJ,SHAPE" }, true);
var _itbmj = _Layer.FeatureClass.FindField("TBMJ");
var bsmIdx = _Layer.FeatureClass.FindField("BSM");
IFeature feature = null;
while ((feature = pCursor.NextFeature()) != null)
{
string bsm = feature.Value[bsmIdx].ToTrim();
if (!CalParm.BsmList.Contains(bsm))
continue;
double area = GetEllipseArea(feature.ShapeCopy);
lock (AreaList)
{
AreaList.Add(feature.OID, area.ToDouble());
}
}
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
}
}
public class CalcAreaParm
{
public string StrLayer { get; set; }
public int StartIndex { get; set; }
public List<string> BsmList { get; set; }
}
public void OpenDB(IDGParameter parm)
{
try
{
LayerCfg layerInfo = null;
if (parm.PrjInfo != null && !string.IsNullOrWhiteSpace(parm.PrjInfo.TempData))
{
byte[] contentArray = Convert.FromBase64String(parm.PrjInfo.TempData);
string LayerCfg = System.Text.Encoding.Default.GetString(contentArray);
layerInfo = SerializeAPI.DeserializeToObject<LayerCfg>(LayerCfg);
}
if (layerInfo == null)
{
throw new Exception("Err:获取图层信息失败!");
}
//FileInfo fileInfo = new FileInfo(parm.PrjInfo.BGDatabase);
string PathBgDB = parm.PrjInfo.BGDatabase;// Path.Combine(, "BGDB" + ".gdb");
string PathZLDB = parm.PrjInfo.ZLDatabase;
//string PathNMDB = parm.PrjInfo.NMDatabase;
BgWsAPI = new WorkspaceAPI(PathBgDB, WorkspaceTypeEnum.GDBFile, true);
if (BgWsAPI.CurrentWorkspace == null)
{
Console.WriteLine("打开变更数据库失败!");
return;
}
ZlWsAPI = new WorkspaceAPI(PathZLDB, WorkspaceTypeEnum.GDBFile, true);
if (ZlWsAPI.CurrentWorkspace == null)
{
Console.WriteLine("打开增量数据库失败!");
return;
}
NmWsAPI = new WorkspaceAPI(parm.PrjInfo.NMDatabase, WorkspaceTypeEnum.GDBFile, true);
if (NmWsAPI.CurrentWorkspace == null)
{
Console.WriteLine("打开年末数据库失败!");
//return;
}
LayerCfg JCLayerInfo = layerInfo.Layers.FirstOrDefault(f => f.LayerName == "年初数据");
if (JCLayerInfo == null)
{
throw new Exception("Err:获取年初数据库失败!");
}
List<LayerCfg> NcList = JCLayerInfo.GetAllItem();
//if (parm.ExeDLTB)
//{
LayerCfg _JcTBLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "地类图斑");
_jcTbLayer = OpenLayer(_JcTBLayerInfo);
if (_jcTbLayer == null)
{
throw new Exception("Err:获取年初地类图斑数据失败!");
}
else
CheackJCGDB(_jcTbLayer);
LayerCfg _JcPdtLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "坡度图");
_jcPdtLayer = OpenLayer(_JcPdtLayerInfo);
if (_jcPdtLayer == null)
{
//throw new Exception("Err:获取年初坡度图数据失败!");
}
_bgTbLayer = OpenLayer(BgWsAPI, "DLTBBG");
_gxTbLayer = OpenLayer(ZlWsAPI, "DLTBGX");
_gxgcTBLayer = OpenLayer(ZlWsAPI, "DLTBGXGC");
_gxPdtLayer = OpenLayer(ZlWsAPI, "PDTGX");
_nmTbLayer = OpenLayer(NmWsAPI, "DLTB_NMK");
}
catch (Exception ex)
{
Console.WriteLine("打开年末数据库失败!" + ex.Message + ex.StackTrace);
throw ex;
}
}
public void CheackJCGDB(IFeatureLayer JClayer)
{
if (((IDataset)JClayer.FeatureClass).Name != "DLTB")
{
throw new Exception("Err:年初地类图斑要素类名称非“DLTB”,需使用国家下发的原始基础库!");
}
if (JClayer.FeatureClass.OIDFieldName != "OBJECTID")
{
throw new Exception("Err:年初地类图斑数据主键字段非“OBJECTID”,需使用国家下发的原始基础库!");
}
if (JClayer.FeatureClass.Fields.FieldCount == 0)
{
throw new Exception("Err:年初地类图斑数据字段结构与国家下发模板存在差异,需使用国家下发的原始基础库!");
}
string FieldsJH = "OBJECTID,BSM,TBYBH,YSDM,TBBH,DLBM,DLMC,QSXZ,QSDWDM,QSDWMC,ZLDWDM,ZLDWMC,TBMJ,KCDLBM,KCXS,KCMJ,TBDLMJ,GDLX,GDPDJB,XZDWKD,TBXHDM,TBXHMC,ZZSXDM,ZZSXMC,GDDB,FRDBS,CZCSXM,SJNF,MSSM,HDMC,BZ";
foreach (var item in FieldsJH.Split(','))
{
int fieldIndex = JClayer.FeatureClass.Fields.FindField(item);
if (fieldIndex == -1)
throw new Exception($"Err:年初地类图斑数据缺失字段“{item}”,需使用国家下发的原始基础库!");
}
for (int i = 0; i < JClayer.FeatureClass.Fields.FieldCount; i++)
{
IField field = JClayer.FeatureClass.Fields.get_Field(i);
if (!field.Editable || field.Name.ToUpper().Contains("SHAPE") || field.Name == "XZQTZLX")
continue;
if (!FieldsJH.Contains(field.Name))
throw new Exception($"Err:年初地类图斑数据出现非国家下发字段“{field.Name}”,需使用国家下发的原始基础库!");
}
}
private IWorkspace CreateDBWorkspace(string pDbPath)
{
try
{
if (!File.Exists(pDbPath))
{
Console.WriteLine(string.Format("指定的文件路径{0}不存在!", pDbPath));
return null;
}
IWorkspaceFactory pOutWorkFactory = null;
pOutWorkFactory = new SqlWorkspaceFactoryClass();
IWorkspace pOutWork = pOutWorkFactory.OpenFromFile(pDbPath, 0);
return pOutWork;
}
catch (Exception ex)
{
Console.WriteLine($"Log:CreateDBWorkspace错误:{ex.Message}");
throw;
}
}
private IFeatureLayer ProcessBGTB()
{
IFeatureLayer result = null;
IWorkspaceAPI wsAPI = null;
IFeatureClassAPI fcAPI = null;
try
{
#region 空属性值 赋值
#region 变更图斑
string BgtbName = (BgTbLayer.FeatureClass as FeatureClass).BrowseName;
Console.WriteLine($"Log:变更图斑空属性赋值:" + BgtbName);
//Console.WriteLine($"Log:KCDLBM");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set XZQTZLX =Null where XZQTZLX='3' ");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set XZQTZLX =Null where XZQTZLX='0' ");//变更层行政区调整类型影响变更过程图斑合并问题;
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set XZQTZLX =Null where XZQTZLX is Null OR XZQTZLX='' or XZQTZLX=' ' or XZQTZLX=' ' ");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set KCDLBM =Null where KCDLBM is Null or KCDLBM=' ' or KCDLBM=' ' ");
//Console.WriteLine($"Log:KCDLBM");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set KCXS=0 where KCXS is Null ");
//Console.WriteLine($"Log:KCXS");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set GDLX =Null where GDLX is Null or GDLX=' ' or GDLX=' ' ");
//Console.WriteLine($"Log:GDLX");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set GDPDJB =Null where GDPDJB is Null or GDPDJB=' ' or GDPDJB=' ' ");
//Console.WriteLine($"Log:GDPDJB");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set XZDWKD=0 where XZDWKD is Null ");
//Console.WriteLine($"Log:XZDWKD");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set TBXHDM =Null where TBXHDM is Null or TBXHDM=' ' or TBXHDM=' ' ");
//Console.WriteLine($"Log:TBXHDM");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set TBXHMC =Null where TBXHMC is Null or TBXHMC=' ' or TBXHMC=' ' ");
//Console.WriteLine($"Log:TBXHMC");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set ZZSXDM =Null where ZZSXDM is Null or ZZSXDM=' ' or ZZSXDM=' ' ");
//Console.WriteLine($"Log:ZZSXDM");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set ZZSXMC =Null where ZZSXMC is Null or ZZSXMC=' ' or ZZSXMC=' ' ");
//Console.WriteLine($"Log:ZZSXMC");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set GDDB =0 where GDDB is Null ");
//Console.WriteLine($"Log:GDDB");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set FRDBS =Null where FRDBS is Null or FRDBS=' ' or FRDBS=' ' ");
//Console.WriteLine($"Log:FRDBS");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set CZCSXM =Null where CZCSXM is Null or CZCSXM=' ' or CZCSXM=' ' ");
//Console.WriteLine($"Log:CZCSXM");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set MSSM =Null where MSSM is Null or MSSM=' ' or MSSM=' ' ");
//Console.WriteLine($"Log:MSSM");
(BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set HDMC =Null where HDMC is Null or HDMC=' ' or HDMC=' ' ");
//Console.WriteLine($"Log:HDMC");
#endregion
#region 基础地类图斑
//string JC_DLTBName = (JcTbLayer.FeatureClass as FeatureClass).BrowseName;
//Console.WriteLine($"Log:基础图斑空属性赋值:" + JC_DLTBName);
//Console.WriteLine($"Log:KCDLBM");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set KCDLBM =Null where KCDLBM is Null or KCDLBM=' ' or KCDLBM=' ' ");
//Console.WriteLine($"Log:KCXS");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set KCXS =0 where KCXS is Null");
//Console.WriteLine($"Log:GDLX");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDLX =Null where GDLX is Null or GDLX=' ' or GDLX=' ' ");
//Console.WriteLine($"Log:GDPDJB");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDPDJB =Null where GDPDJB is Null or GDPDJB=' ' or GDPDJB=' ' ");
//Console.WriteLine($"Log:XZDWKD");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set XZDWKD =0 where XZDWKD is Null");
//Console.WriteLine($"Log:TBXHDM");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set TBXHDM =Null where TBXHDM is Null or TBXHDM=' ' or TBXHDM=' ' ");
//Console.WriteLine($"Log:TBXHMC");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set TBXHMC =Null where TBXHMC is Null or TBXHMC=' ' or TBXHMC=' ' ");
//Console.WriteLine($"Log:ZZSXDM");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set ZZSXDM =Null where ZZSXDM is Null or ZZSXDM=' ' or ZZSXDM=' ' ");
//Console.WriteLine($"Log:ZZSXMC");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set ZZSXMC =Null where ZZSXMC is Null or ZZSXMC=' ' or ZZSXMC=' ' ");
//Console.WriteLine($"Log:GDDB");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDDB =0 where GDDB is Null");
//Console.WriteLine($"Log:FRDBS");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set FRDBS =Null where FRDBS is Null or FRDBS=' ' or FRDBS=' ' ");
//Console.WriteLine($"Log:CZCSXM");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set CZCSXM =Null where CZCSXM is Null or CZCSXM=' ' or CZCSXM=' ' ");
//Console.WriteLine($"Log:MSSM");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set MSSM =Null where MSSM is Null or MSSM=' ' or MSSM=' ' ");
//Console.WriteLine($"Log:HDMC");
//(JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set HDMC =Null where HDMC is Null or HDMC=' ' or HDMC=' ' ");
//Console.WriteLine($"Log:属性处理完成");
#endregion
#endregion
#region 新增质检规则“地类图斑更新过程层变更前图斑细化代码标注“LQGD”,“MQGD”,“SHGD”,“SMGD”,变更后地类为耕地的图斑,变更前后图斑细化代码应保持不变”,地类图斑更新过程层变更前图斑细化代码为林区耕地、牧区耕地、沙荒耕地或石漠化耕地,变更后地类仍为耕地的图斑,变更前后图斑细化代码应保持不变。
GD_TBXHDM();
#endregion
//GeoprocessorHelper helper = new GeoprocessorHelper();
//相邻同属性图斑是否合并(针对原始变更图斑层)
if (Parm.AllowUnion)
{
LogAPI.Debug("变更图斑合并……");
IVariantArray mGPParm = new VarArrayClass();
mGPParm.Add(BgTbLayer);
mGPParm.Add(TempDbPath);
mGPParm.Add("DLTBBG");
CustomGPHelper.DLTBBGDissolve_Tool(mGPParm);
wsAPI = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile, true);
fcAPI = wsAPI.OpenFeatureClass("DLTBBG");
BgTbLayer.FeatureClass = fcAPI.FeatureClass;
}
IVariantArray mTBBGGPParm = new VarArrayClass();
mTBBGGPParm.Add(BgTbLayer);
mTBBGGPParm.Add(JcTbLayer);
mTBBGGPParm.Add(TempDbPath);
CustomGPHelper.DLTBBG_Tool(mTBBGGPParm);
if (wsAPI == null)
wsAPI = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile, true);
fcAPI = wsAPI.OpenFeatureClass("TempDLTBGX");
if (Parm.AllowPDFZ)
{
LogAPI.Debug("耕地坡度赋值……");
IFeatureLayer tempLayer = new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = "地类图斑" };
IVariantArray mGPParm = new VarArrayClass();
mGPParm.Add(tempLayer);
if (GxPdtLayer.FeatureClass.FeatureCount(null) > 0)
{
mGPParm.Add(GxPdtLayer);
CustomGPHelper.SetGDPDJB_Tool(mGPParm);
if (wsAPI == null)
wsAPI = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile,true);
fcAPI = wsAPI.OpenFeatureClass("TempDLTBGX");
}
else if (JcPdtLayer != null && JcPdtLayer.FeatureClass.FeatureCount(null) > 0)
{
mGPParm.Add(JcPdtLayer);
CustomGPHelper.SetGDPDJB_Tool(mGPParm);
if (wsAPI == null)
wsAPI = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile, true);
fcAPI = wsAPI.OpenFeatureClass("TempDLTBGX");
}
}
if (Parm.AllowUnion)
{
BgtbName = "TempDLTBGX";
Console.WriteLine($"Log:变更图斑空属性赋值:" + BgtbName);
if (Parm.AutoSetGDLX)
{
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set GDLX='TT' where GDPDJB in ('2','3','4','5') and DLBM = '0101' and (GDLX <> 'TT' and GDLX <> 'PD' or GDLX is NULL) ");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set GDLX='PD' where GDPDJB in ('2','3','4','5') and (DLBM='0102' or DLBM='0103') and (GDLX <> 'TT' and GDLX <> 'PD' or GDLX is NULL) ");
}
if (Parm.AutoCalcGDKCSX)
{
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set GDLX =Null,KCDLBM=Null,KCXS=0 where GDPDJB='1' ");
//if (Parm.KCXSDic.ContainsKey("2"))
//{
// wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set KCDLBM ='1203',KCXS={Parm.KCXSDic["2"]} where GDPDJB='2' and GDLX='TT' ");
//}
foreach (string key in Parm.KCXSDic.Keys)
{
string[] strGDPDArr = key.Split('-');
string strGDLX = strGDPDArr[0];
string strGDPDJB = strGDPDArr[1];
decimal strKCXS = Parm.KCXSDic[key];
string strKCDLBM = string.Empty;
if ("2,3,4,5".Contains(strGDPDJB) && strKCXS != 0)
strKCDLBM = "1203";
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set KCDLBM ='{strKCDLBM}',KCXS={strKCXS} where GDPDJB='{strGDPDJB}' and GDLX='{strGDLX}' ");
}
}
//Console.WriteLine($"Log:KCDLBM");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set KCDLBM =Null where KCDLBM is Null or KCDLBM=' ' or KCDLBM=' ' ");
//Console.WriteLine($"Log:KCDLBM");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set KCXS=0 where KCXS is Null ");
//Console.WriteLine($"Log:KCXS");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set GDLX =Null where GDLX is Null or GDLX=' ' or GDLX=' ' ");
//Console.WriteLine($"Log:GDLX");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set GDPDJB =Null where GDPDJB is Null or GDPDJB=' ' or GDPDJB=' ' ");
//Console.WriteLine($"Log:GDPDJB");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set XZDWKD=0 where XZDWKD is Null ");
//Console.WriteLine($"Log:XZDWKD");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set TBXHDM =Null where TBXHDM is Null or TBXHDM=' ' or TBXHDM=' ' ");
//Console.WriteLine($"Log:TBXHDM");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set TBXHMC =Null where TBXHMC is Null or TBXHMC=' ' or TBXHMC=' ' ");
//Console.WriteLine($"Log:TBXHMC");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set ZZSXDM =Null where ZZSXDM is Null or ZZSXDM=' ' or ZZSXDM=' ' ");
//Console.WriteLine($"Log:ZZSXDM");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set ZZSXMC =Null where ZZSXMC is Null or ZZSXMC=' ' or ZZSXMC=' ' ");
//Console.WriteLine($"Log:ZZSXMC");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set GDDB =0 where GDDB is Null ");
//Console.WriteLine($"Log:GDDB");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set FRDBS =Null where FRDBS is Null or FRDBS=' ' or FRDBS=' ' ");
//Console.WriteLine($"Log:FRDBS");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set CZCSXM =Null where CZCSXM is Null or CZCSXM=' ' or CZCSXM=' ' ");
//Console.WriteLine($"Log:CZCSXM");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set MSSM =Null where MSSM is Null or MSSM=' ' or MSSM=' ' ");
//Console.WriteLine($"Log:MSSM");
wsAPI.CurrentWorkspace.ExecuteSQL($"Update {BgtbName} set HDMC =Null where HDMC is Null or HDMC=' ' or HDMC=' ' ");
//Console.WriteLine($"Log:HDMC");
LogAPI.Debug("更新图斑合并……");
IFeatureLayer tempLayer = new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = "地类图斑" };
IVariantArray mGPParm = new VarArrayClass();
mGPParm.Add(tempLayer);
mGPParm.Add(TempDbPath);
mGPParm.Add("DLTBGX");
CustomGPHelper.DLTBBGDissolve_Tool(mGPParm);
wsAPI = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile, true);
fcAPI = wsAPI.OpenFeatureClass("DLTBGX");
}
else
{
IFeatureLayer tempLayer = new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = "地类图斑" };
IFeatureLayer AllGxTBLayer = null;
GPParamClass gPParamClass = new GPParamClass();
gPParamClass.FirstFeatureLayer = tempLayer;
gPParamClass.OutFeatureClassPath = TempDbPath;
gPParamClass.IsGetOutPutFeature = true;
gPParamClass.ListDissolveFiledName = new List<string>();
gPParamClass.FcName = "DLTBGX";
gPParamClass.GPType = EnumGPType.FcToFc;
GPHelper.Instance.ExeGPForProces(gPParamClass, ref AllGxTBLayer);
if (wsAPI == null)
wsAPI = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile, true);
fcAPI = wsAPI.OpenFeatureClass("DLTBGX");
}
IFeatureLayer tempDLTBGX = new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = "地类图斑更新" };
if (wsAPI == null)
wsAPI = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile, true);
IFeatureClassAPI jcFcAPI = wsAPI.OpenFeatureClass("JC_DLTB");
IFeatureLayer tempJC_DLTB = new FeatureLayerClass() { FeatureClass = jcFcAPI.FeatureClass, Name = "基础地类图斑" };
IFeatureLayer ptempLayer = null;
GPParamClass gPParamClass2 = new GPParamClass();
gPParamClass2.FirstFeatureLayer = tempDLTBGX;
gPParamClass2.GPType = EnumGPType.Default;
GPHelper.Instance.ExeGPForProces(gPParamClass2, ref ptempLayer);
IVariantArray mDLTBGXGCPParm = new VarArrayClass();
mDLTBGXGCPParm.Add(tempDLTBGX);
mDLTBGXGCPParm.Add(tempJC_DLTB);
mDLTBGXGCPParm.Add(TempDbPath);
//mDLTBGXGCPParm.Add(TempSqlitePath);
CustomGPHelper.DLTBGXGC_Tool(mDLTBGXGCPParm);
//fcAPI = wsAPI.OpenFeatureClass("TempDLTBGX");
}
catch (Exception ex)
{
Console.WriteLine($"Log:变更前执行变更图斑数据处理失败:{ex.Message}");
Console.WriteLine($"Log:变更前执行变更图斑数据处理失败:{ex.StackTrace}");
LogAPI.Debug(ex);
throw ex;
}
return result;
}
/// <summary>
/// 新增质检规则“地类图斑更新过程层变更前图斑细化代码标注“LQGD”,“MQGD”,“SHGD”,“SMGD”,变更后地类为耕地的图斑,变更前后图斑细化代码应保持不变”,地类图斑更新过程层变更前图斑细化代码为林区耕地、牧区耕地、沙荒耕地或石漠化耕地,变更后地类仍为耕地的图斑,变更前后图斑细化代码应保持不变。
/// </summary>
/// <param name="DLTBGXGCFC"></param>
/// <param name="DLTBGXFC"></param>
private void GD_TBXHDM()
{
IWorkspace pOutWork = null;
GPParamClass paramClass = new GPParamClass();
IFeatureLayer IntersectLayer = null;
IFeatureSelection jcfeatureSelection = null;
IFeatureSelection bgfeatureSelection = null;
try
{
string TempDir = CreateTempDB("BGTB_JCDLTB");
string temppath = System.IO.Path.Combine(TempDir, "TempGDB.gdb");
bgfeatureSelection = BgTbLayer as IFeatureSelection;
bgfeatureSelection.Clear();
bgfeatureSelection.SelectFeatures(new QueryFilterClass() { WhereClause = "dlbm in ('0101','0102','0103') and (tbxhdm is null or tbxhdm='')" }, esriSelectionResultEnum.esriSelectionResultNew, false);
if ((BgTbLayer as IFeatureSelection).SelectionSet.Count > 0)
{
jcfeatureSelection = JcTbLayer as IFeatureSelection;
jcfeatureSelection.Clear();
jcfeatureSelection.SelectFeatures(new QueryFilterClass() { WhereClause = "tbxhdm in('LQGD','MQGD','SHGD','SMGD')" }, esriSelectionResultEnum.esriSelectionResultNew, false);
if ((JcTbLayer as IFeatureSelection).SelectionSet.Count > 0)
{
GPParamClass gPParamClass = new GPParamClass
{
FirstFeatureLayer = BgTbLayer,
SecondFeatureLayer = JcTbLayer,
OutFeatureClassPath = $"{TempDir}\\TempGDB.gdb\\BGTB_JCDLTB",
IsGetOutPutFeature = true,
GPType = EnumGPType.Intersect
};
GPHelper.Instance.ExeGPForProces(gPParamClass, ref IntersectLayer);
}
}
bgfeatureSelection.Clear();
jcfeatureSelection.Clear();
if (IntersectLayer != null)
{
IFeature feature = null;
WorkspaceAPI BgWsAPI = new WorkspaceAPI($"{TempDir}\\TempGDB.gdb", WorkspaceTypeEnum.GDBFile, true);
IFeatureClassAPI FeatureClass = BgWsAPI.OpenFeatureClass("BGTB_JCDLTB");
IFeatureCursor Cursor = FeatureClass.FeatureClass.Search(new QueryFilterClass() { WhereClause = " dlbm in ('0101','0102','0103') and (tbxhdm is null or tbxhdm='') and tbxhdm_1 in('LQGD','MQGD','SHGD','SMGD')" }, false);
var ibgtboid = FeatureClass.FeatureClass.FindField("FID_DLTBBG");
var ixhdm = FeatureClass.FeatureClass.FindField("TBXHDM_1");
var ixhmc = FeatureClass.FeatureClass.FindField("TBXHMC_1");
while ((feature = Cursor.NextFeature()) != null)
{
string oid = feature.Value[ibgtboid].ToTrim();
string TBXHDM = feature.Value[ixhdm].ToTrim();
string TBXHMC = feature.Value[ixhmc].ToTrim();
(BgTbLayer as FeatureClass).Workspace.ExecuteSQL($"update DLTBBG set TBXHDM='{TBXHDM}' where OBJECTID={oid} ");
(BgTbLayer as FeatureClass).Workspace.ExecuteSQL($"update DLTBBG set TBXHMC='{TBXHMC}' where OBJECTID={oid} ");
}
}
if (Parm.AllowPDFZ)
{
//string dbPath = TempDir + @"\Temp" + ".sqlite";
//pOutWork = CreateDBWorkspace(dbPath);
//IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
//rdbHelper.ExecuteSQL(" drop table BGTB_JCDLTB ");
//IWorkspaceAPI wsAPI1 = new WorkspaceAPI(temppath, WorkspaceTypeEnum.GDBFile);
//TableToTable(wsAPI1.CurrentWorkspace as IFeatureWorkspace, pOutWork, "BGTB_JCDLTB");
//DataTable dt = rdbHelper.ExecuteDatatable("dt", @" select bgqtbbsm,bghtbbsm,bgqgdpdjb,bghgdpdjb,bgqkcxs,bghkcxs,BGQGDLX,BGHGDLX,TBBGMJ from DLTBGXGC d2 WHERE BGHTBBSM||'-'||TBBGMJ in( select BGHTBBSM||'-'||MAX(TBBGMJ) TBBGMJ from DLTBGXGC d WHERE BGHTBBSM in (select BGHTBBSM from dltbgxgc where substr(bgqdlbm,1,2)='01' and substr(bghdlbm,1,2)='01' and bgxw='2' and (BGQGDPDJB<>BGHGDPDJB or BGQKCXS<> BGHKCXS ) ) group by BGHTBBSM )and bgqtbbsm not in (select bgqtbbsm from (SELECT BGQTBBSM ,substr(bghdlbm,1,2) BGHDLBM,COUNT(1) from dltbgxgc group by BGQTBBSM ,substr(bghdlbm,1,2) ) group by BGQTBBSM HAVING count(1)>1) ", true);
}
}
catch (Exception ex)
{
LogAPI.Debug("异常:" + ex.Message);
}
finally
{
if (pOutWork != null)
Marshal.ReleaseComObject(pOutWork);
}
}
private void SetDLTBBG_PDJB()
{
IWorkspace pOutWork = null;
try
{
//string TempDir = CreateTempDB("KCXSUpdate_1");
//string dbPath = TempDir + @"\Temp" + ".sqlite";
//pOutWork = CreateDBWorkspace(dbPath);
//IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
//rdbHelper.ExecuteSQL(" drop table DLTBGXGC ");
//TableToTable((DLTBGXGCFC as FeatureClass).Workspace as IFeatureWorkspace, pOutWork, "DLTBGXGC");
//DataTable dt = rdbHelper.ExecuteDatatable("dt", @" select bgqtbbsm,bghtbbsm,bgqgdpdjb,bghgdpdjb,bgqkcxs,bghkcxs,BGQGDLX,BGHGDLX,TBBGMJ from DLTBGXGC d2 WHERE BGHTBBSM||'-'||TBBGMJ in( select BGHTBBSM||'-'||MAX(TBBGMJ) TBBGMJ from DLTBGXGC d WHERE BGHTBBSM in (select BGHTBBSM from dltbgxgc where substr(bgqdlbm,1,2)='01' and substr(bghdlbm,1,2)='01' and bgxw='2' and (BGQGDPDJB<>BGHGDPDJB or BGQKCXS<> BGHKCXS ) ) group by BGHTBBSM )and bgqtbbsm not in (select bgqtbbsm from (SELECT BGQTBBSM ,substr(bghdlbm,1,2) BGHDLBM,COUNT(1) from dltbgxgc group by BGQTBBSM ,substr(bghdlbm,1,2) ) group by BGQTBBSM HAVING count(1)>1) ", true);
//for (int i = 0; i < dt.Rows.Count; i++)
//{
// (DLTBGXGCFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGXGC set BGHKCXS={dt.Rows[i]["BGQKCXS"]} where BGHTBBSM='{dt.Rows[i]["BGHTBBSM"]}'");
// (DLTBGXGCFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGXGC set BGHGDPDJB='{dt.Rows[i]["BGQGDPDJB"]}' where BGHTBBSM='{dt.Rows[i]["BGHTBBSM"]}'");
// (DLTBGXGCFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGXGC set BGHGDLX='{dt.Rows[i]["BGQGDLX"]}' where BGHTBBSM='{dt.Rows[i]["BGHTBBSM"]}'");
// (DLTBGXFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGX set KCXS={dt.Rows[i]["BGQKCXS"]} where BSM='{dt.Rows[i]["BGHTBBSM"]}'");
// (DLTBGXFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGX set GDPDJB='{dt.Rows[i]["BGQGDPDJB"]}' where BSM='{dt.Rows[i]["BGHTBBSM"]}'");
// (DLTBGXFC as FeatureClass).Workspace.ExecuteSQL($"update DLTBGX set GDLX='{dt.Rows[i]["BGQGDLX"]}' where BSM='{dt.Rows[i]["BGHTBBSM"]}'");
//}
}
catch (Exception ex)
{
LogAPI.Debug("异常:" + ex.Message);
}
finally
{
if (pOutWork != null)
Marshal.ReleaseComObject(pOutWork);
}
}
private void GD_()
{
IWorkspace pOutWork = null;
GPParamClass paramClass = new GPParamClass();
IFeatureLayer IntersectLayer = null;
try
{
string TempDir = CreateTempDB("BGTB_JCDLTB1");
IFeatureLayer bgselect = null;
paramClass = new GPParamClass();
paramClass.FirstFeatureLayer = BgTbLayer;
paramClass.GPType = EnumGPType.SelectLayerByAttribute;
paramClass.IsGetOutPutFeature = true;
paramClass.Where_clause = "dlbm in ('0101','0102','0103')";
paramClass.FcName = "BGTB";
paramClass.TempGDBPath = $"{TempDir}\\TempGDB.gdb";
GPHelper.Instance.ExeGPForProces(paramClass, ref bgselect);
IFeatureLayer jcselect = null;
paramClass = new GPParamClass();
paramClass.FirstFeatureLayer = JcTbLayer;
paramClass.GPType = EnumGPType.SelectLayerByAttribute;
paramClass.IsGetOutPutFeature = true;
paramClass.Where_clause = "dlbm in ('0101','0102','0103')";
paramClass.FcName = "JCTB";
paramClass.TempGDBPath = $"{TempDir}\\TempGDB.gdb";
GPHelper.Instance.ExeGPForProces(paramClass, ref jcselect);
paramClass = new GPParamClass();
paramClass.FirstFeatureLayer = bgselect;
paramClass.SecondFeatureLayer = jcselect;
paramClass.OutFeatureClassPath = $"{TempDir}\\TempGDB.gdb\\BGTB_JCDLTB";
paramClass.IsGetOutPutFeature = true;
paramClass.GPType = EnumGPType.Intersect;
GPHelper.Instance.ExeGPForProces(paramClass, ref IntersectLayer);
IFeature feature = null;
IFeatureCursor Cursor = IntersectLayer.FeatureClass.Search(null, false);
var ibgtboid = IntersectLayer.FeatureClass.FindField("FID_BGTB");
var ikcxs = IntersectLayer.FeatureClass.FindField("KCXS_1");
var igdpdjb = IntersectLayer.FeatureClass.FindField("GDPDJB_1");
var igdlx = IntersectLayer.FeatureClass.FindField("GDLX_1");
if (IntersectLayer != null)
{
while ((feature = Cursor.NextFeature()) != null)
{
string oid = feature.Value[ibgtboid].ToTrim();
string KCXS = feature.Value[ikcxs].ToTrim();
string GDPDJB = feature.Value[igdpdjb].ToTrim();
string GDLX = feature.Value[igdlx].ToTrim();
(BgTbLayer as FeatureClass).Workspace.ExecuteSQL($"update DLTBBG set KCXS={KCXS} where OBJECTID={oid} ");
(BgTbLayer as FeatureClass).Workspace.ExecuteSQL($"update DLTBBG set GDPDJB={GDPDJB} where OBJECTID={oid} ");
(BgTbLayer as FeatureClass).Workspace.ExecuteSQL($"update DLTBBG set GDLX='{GDLX}' where OBJECTID={oid} ");
}
}
}
catch (Exception ex)
{
LogAPI.Debug("异常:" + ex.Message);
}
finally
{
if (pOutWork != null)
Marshal.ReleaseComObject(pOutWork);
}
}
private IFeatureLayer GenerateTempGXGC(IFeatureLayer pTempBgTbLayer, string pTempAttrDBPath)
{
IFeatureLayer result = null;
GPParamClass paramClass = new GPParamClass();
try
{
//GPParamClass paramClass = new GPParamClass();
IFeatureLayer tempLayer = null;
paramClass = new GPParamClass();
paramClass.FirstFeatureLayer = JcTbLayer;
paramClass.SecondFeatureLayer = pTempBgTbLayer;
paramClass.TempGDBPath = $"{TempDbPath}";
paramClass.Tolerance = "-0.001";
paramClass.IsGetOutPutFeature = true;
paramClass.GPType = EnumGPType.YBG;
GPHelper.Instance.ExeGPForProces(paramClass, ref tempLayer);
IWorkspaceAPI wsAPI = new WorkspaceAPI(TempDbPath, WorkspaceTypeEnum.GDBFile);
IFeatureClassAPI fcAPI = wsAPI.OpenFeatureClass("GXGC_Multipart");
result = new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = fcAPI.FeatureClass.AliasName };
return result;
#region 设置基础地类图斑选中
if (JcTbLayer.FeatureClass.FeatureCount(null) != pTempBgTbLayer.FeatureClass.FeatureCount(null))
{
paramClass.Tolerance = "0.0001";
paramClass.FirstFeatureLayer = JcTbLayer;
paramClass.SecondFeatureLayer = pTempBgTbLayer;
paramClass.IsGetOutPutFeature = true;
paramClass.GPType = EnumGPType.SelectLayerByLocation;
paramClass.Overlap_type = "INTERSECT";
GPHelper.Instance.ExeGPForProces(paramClass, ref result);
}
#endregion
#region 变更层与基础地类图斑联合
paramClass = new GPParamClass()
{
FirstFeatureLayer = pTempBgTbLayer,
SecondFeatureLayer = result,
OutFeatureClassPath = $"{TempDbPath}\\BGTB_DLTBUnion",
IsGetOutPutFeature = true,
PreserveAttributes = "ALL",
GPType = EnumGPType.Union
};
GPHelper.Instance.ExeGPForProces(paramClass, ref result);
#endregion
#region 拆分多部件
paramClass = new GPParamClass();
paramClass.FirstFeatureLayer = result;
paramClass.OutFeatureClassPath = $"{TempDbPath}\\GXGC_Multipart";
paramClass.IsGetOutPutFeature = true;
paramClass.GPType = EnumGPType.MultipartToSinglePath;
GPHelper.Instance.ExeGPForProces(paramClass, ref result);
#endregion
#region TableToTable
string dbPath = pTempAttrDBPath;
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
rdbHelper.ExecuteSQL(" drop table GXGC_Multipart ");
rdbHelper.DisConnect();
IWorkspace ws = (result.FeatureClass as FeatureClass).Workspace;
//添加字段
IFieldEdit _field = new FieldClass();
_field.Name_2 = "BGXW";
_field.Type_2 = esriFieldType.esriFieldTypeString;
_field.Length_2 = 2;
if (result.FeatureClass.FindField("BGXW") == -1)
result.FeatureClass.AddField(_field as IField);
//矢量数据至db文件
//(result.FeatureClass as ITable).DeleteSearchedRows(new QueryFilterClass() { WhereClause = "Shape_area < 0.01" });
TableToTable(ws as IFeatureWorkspace, pOutWork, "GXGC_Multipart");
#endregion
}
catch (Exception ex)
{
Console.WriteLine($"Log:生成临时更新过程层数据失败:{ex.Message}");
throw ex;
}
return result;
}
public double GetEllipseArea(IGeometry polygon)
{
try
{
// 1、获得投影
String SphName = polygon.SpatialReference.Name.ToString().ToUpper();
// 2、获得椭球
ICoordinate coordinate = CoordinateFactory.CreateCoordinate();
if (SphName.Contains("XIAN_1980") || SphName.Contains("XIAN1980"))
{
coordinate = CoordinateFactory.CreateCoordinate(KGIS.Framework.AE.GaussCalculate.Spheroid.SphXian80);
}
else if (SphName.Contains("BEIJING_1954") || SphName.Contains("BEIJING1954"))
{
coordinate = CoordinateFactory.CreateCoordinate(KGIS.Framework.AE.GaussCalculate.Spheroid.SphBeijing54);
}
else if (SphName.Contains("WGS_1984") || SphName.Contains("WGS1984"))
{
coordinate = CoordinateFactory.CreateCoordinate(KGIS.Framework.AE.GaussCalculate.Spheroid.SphWGS84);
}
else if (SphName.Contains("CGCS_2000") || SphName.Contains("CGCS2000"))
{
coordinate = CoordinateFactory.CreateCoordinate(KGIS.Framework.AE.GaussCalculate.Spheroid.SphCGCS2000);
}
else
{
return -1;
}
// 3、计算面积
IGeometry pGeometry = polygon as IGeometry;
double PolygonArea = 0.0;
// 4、保留两位小数
PolygonArea = Math.Round(coordinate.CalculateTerranArea(pGeometry), 2, MidpointRounding.AwayFromZero);
return PolygonArea;
}
catch (Exception ex)
{
throw ex;
}
}
public void GDPDExcute()
{
//IFeatureClassAPI GXAPI = null;
//IFeatureClassAPI pdtFcAPI = null;
IFeatureLayer PDTLayer = null;
IFeature feature = null;
IFeatureCursor cursor = null;
IWorkspaceFactory pFtWsFct = null;
IWorkspaceName workspaceName = null;
IFeatureLayer unionLayer = null;
IFeatureClassAPI unionFcAPI = null;
try
{
Console.WriteLine("Msg:正在进行耕地坡度级别赋值,请稍后...");
#region 变更图斑层(GDB)
//// 获取变更图斑
//GXAPI = new FeatureClassAPI(BgTbLayer.FeatureClass);
//if (GXAPI == null || GXAPI.FeatureClass == null)
//{
// Console.WriteLine("Err:未获取到更新层图斑");
// return;
//}
#endregion
#region 坡度图层(MDB)
PDTLayer = GxPdtLayer;
if (GxPdtLayer == null && JcPdtLayer == null)
{
Console.WriteLine("Warning:当前工程不存在坡度图图层!");
return;
}
if (PDTLayer.FeatureClass.FeatureCount(null) <= 0)
{
PDTLayer = JcPdtLayer;
}
if (PDTLayer.FeatureClass.FeatureCount(null) <= 0)
{
Console.WriteLine("Warning:当前工程中未导入坡度数据!");
return;
}
#endregion
//IWorkspaceAPI psTempWorkspaceAPI = new WorkspaceAPI(pTempGDbPath, WorkspaceTypeEnum.GDBFile);
//IFeatureClassAPI tempdltbgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("TempDLTBGX", (BgTbLayer.FeatureClass as IGeoDataset).SpatialReference, BgTbLayer.FeatureClass.Fields);
//tempdltbgxFeatureclassAPI.AddField("OLDOBJECTID", esriFieldType.esriFieldTypeInteger, "老OBJECTID");
//IFeatureClass tempdltbgxFC = tempdltbgxFeatureclassAPI.FeatureClass;
//Dictionary<int, int> fieldsDic = new Dictionary<int, int>();
//for (int i = 0; i < tempdltbgxFC.Fields.FieldCount; i++)
//{
// IField field = tempdltbgxFC.Fields.Field[i];
// if (field.Name == tempdltbgxFC.ShapeFieldName || field.Name.Contains(tempdltbgxFC.ShapeFieldName) || field.Name == tempdltbgxFC.OIDFieldName || !field.Editable) continue;
// if (!"DLBM,GDLX,GDDB,GDPDJB,KCXS".Contains(field.Name)) continue;
// int index = -1;
// index = BgTbLayer.FeatureClass.Fields.FindField(field.Name);
// if (index == -1)
// index = BgTbLayer.FeatureClass.Fields.FindFieldByAliasName(field.AliasName);
// if (index == -1)
// continue;
// fieldsDic.Add(i, index);
//}
//if (fieldsDic.Count == 0)
// return;
//IFeatureBuffer buffer = tempdltbgxFC.CreateFeatureBuffer();
//IFeatureCursor tempgxCursor = tempdltbgxFC.Insert(true);
//int oldOIDIndex = tempdltbgxFC.FindField("OLDOBJECTID");
//if (oldOIDIndex == -1)
// return;
//IQueryFilter queryfilter = new QueryFilterClass();
//queryfilter.WhereClause = string.Format("DLBM like '01%' ");
//int gdCount = BgTbLayer.FeatureClass.FeatureCount(queryfilter);
//if (gdCount == 0)
// return;
//IFeature gxtbFeature = null;
//IFeatureCursor dltbgxCursor = BgTbLayer.FeatureClass.Search(queryfilter, true);
//int OIDIndex = BgTbLayer.FeatureClass.FindField("OBJECTID");
//int num = 0;
//while ((gxtbFeature = dltbgxCursor.NextFeature()) != null)
//{
// num++;
// if (gxtbFeature.ShapeCopy.IsEmpty) continue;
// buffer.Shape = gxtbFeature.ShapeCopy;
// foreach (int item in fieldsDic.Keys)
// {
// if (string.IsNullOrWhiteSpace(gxtbFeature.Value[fieldsDic[item]].ToTrim()))
// buffer.Value[item] = DBNull.Value;
// buffer.Value[item] = gxtbFeature.Value[fieldsDic[item]];
// }
// buffer.Value[oldOIDIndex] = gxtbFeature.Value[OIDIndex];
// tempgxCursor.InsertFeature(buffer);
// if (num % 1000 == 0)
// {
// tempgxCursor.Flush();
// }
// Marshal.ReleaseComObject(gxtbFeature);
//}
//tempgxCursor.Flush();
//DLTBGX与PDTGX 相交
GPParamClass gPParamClass = new GPParamClass();
gPParamClass.FirstFeatureLayer = BgTbLayer;
gPParamClass.SecondFeatureLayer = PDTLayer;
gPParamClass.OutFeatureClassPath = TempDbPath + "\\TB_PD";
gPParamClass.IsGetOutPutFeature = true;
gPParamClass.GPType = EnumGPType.Identify;
GPHelper.Instance.ExeGPForProces(gPParamClass, ref unionLayer);
unionFcAPI = new FeatureClassAPI(unionLayer.FeatureClass);
cursor = unionFcAPI.FeatureClass.Search(null, true);
feature = null;
Dictionary<int, string> DicPDJB = new Dictionary<int, string>();
Dictionary<int, double> DicMJ = new Dictionary<int, double>();
Dictionary<int, List<PDJBModel>> DicPDJB_MJ = new Dictionary<int, List<PDJBModel>>();
int idxOID = unionFcAPI.FeatureClass.FindField("OLDOBJECTID");
if (idxOID == -1)
{
return;
}
int idxArea = unionFcAPI.FeatureClass.FindField("SHAPE_AREA");
int idxPDJB = unionFcAPI.FeatureClass.FindField("PDJB");
while ((feature = cursor.NextFeature()) != null)
{
int oid = Convert.ToInt32(feature.Value[idxOID].ToTrim());
if (oid == 456)
{
}
double area = feature.Value[idxArea].ToDouble(2);
string pdjb = feature.Value[idxPDJB].ToTrim();
if (!DicPDJB_MJ.ContainsKey(oid))
{
DicPDJB_MJ.Add(oid, new List<PDJBModel>() { new PDJBModel() { PDJB = pdjb, MJ = area } });
}
else
{
List<PDJBModel> list = DicPDJB_MJ[oid];
PDJBModel pdjbMod = list.FirstOrDefault(f => f.PDJB == pdjb);
if (pdjbMod == null)
{
list.Add(new PDJBModel() { PDJB = pdjb, MJ = area });
}
else
{
pdjbMod.MJ += area;
}
DicPDJB_MJ[oid] = list;
}
if (!DicMJ.ContainsKey(oid))
{
DicMJ.Add(oid, area);
DicPDJB.Add(oid, pdjb);
}
else if (DicMJ[oid] < area)
{
DicMJ[oid] = area;
DicPDJB[oid] = pdjb;
}
}
cursor = BgTbLayer.FeatureClass.Update(new QueryFilter() { WhereClause = "DLBM like '01%' " }, false);
int Objectid_GX = BgTbLayer.FeatureClass.FindField("objectid");
int BSM_GX = BgTbLayer.FeatureClass.FindField("BSM");
int GDPDJB_GX = BgTbLayer.FeatureClass.FindField("GDPDJB");
int GDLX_GX = BgTbLayer.FeatureClass.FindField("GDLX");
int idxKCXS = BgTbLayer.FeatureClass.FindField("KCXS");
int DLBM_GX = BgTbLayer.FeatureClass.FindField("DLBM");
int GDPDJBIndex = PDTLayer.FeatureClass.FindField("PDJB");
var count = BgTbLayer.FeatureClass.FeatureCount(new QueryFilter() { WhereClause = "DLBM like '01%' " });
var featurecount = 0;
while ((feature = cursor.NextFeature()) != null)
{
featurecount++;
if (featurecount % 500 == 0)
{
Console.WriteLine($"Msg:正在进行耕地坡度赋值...【{featurecount}/{count}】");
}
if (feature.OID == 529)
{
}
string pdjb = string.Empty;
if (!DicPDJB_MJ.ContainsKey(feature.OID))
{
continue;
}
double tempmj = feature.Value[feature.Fields.FindField("SHAPE_AREA")].ToDouble(0);
if (tempmj == 850.0)
{
}
List<PDJBModel> list = DicPDJB_MJ[feature.OID];
list = list.OrderByDescending(o => o.MJ).ToList();
pdjb = list[0].PDJB;//[feature.OID];
feature.Value[GDPDJB_GX] = pdjb;
string dlbm = feature.Value[DLBM_GX].ToString();
string bghbsm = feature.Value[BSM_GX].ToString();
string UpdateGCSql = string.Empty;
string strGDLX = feature.Value[GDLX_GX].ToTrim();
if (pdjb == "1")
{
strGDLX = "";
}
else
if (!string.IsNullOrWhiteSpace(dlbm) && "2,3,4,5".Contains(pdjb) && string.IsNullOrWhiteSpace(strGDLX))
{
string kcxsKey1 = string.Format("{0}-{1}", "TT", pdjb);
double xs1 = 0;
if (Parm.KCXSDic.ContainsKey(kcxsKey1))
{
xs1 = Parm.KCXSDic[kcxsKey1].ToDouble();
}
string kcxsKey2 = string.Format("{0}-{1}", "PD", pdjb);
double xs2 = 0;
if (Parm.KCXSDic.ContainsKey(kcxsKey2))
{
xs2 = Parm.KCXSDic[kcxsKey2].ToDouble();
}
if (xs1 == 0 && xs2 != 0)
{
strGDLX = "PD";
}
else if (xs1 != 0 && xs2 == 0)
{
strGDLX = "TT";
}
else
{
if (dlbm == "0101")
{
strGDLX = "TT";
}
else if ("0102,0103".Contains(dlbm))
{
strGDLX = "PD";
}
}
}
string kcxsKey = string.Format("{0}-{1}", strGDLX, pdjb);
if (Parm.KCXSDic.ContainsKey(kcxsKey))
{
feature.Value[idxKCXS] = Parm.KCXSDic[kcxsKey].ToDouble();
}
feature.Value[GDLX_GX] = strGDLX;
cursor.UpdateFeature(feature);
Marshal.ReleaseComObject(feature);
}
}
catch (Exception ex)
{
Console.WriteLine("Warning:耕地坡度级别赋值异常:" + ex.Message);
Console.WriteLine("Warning:耕地坡度级别赋值异常:" + ex);
}
finally
{
//ProgressHelper.CloseProcessBar();
if (feature != null)
Marshal.ReleaseComObject(feature);
if (cursor != null)
Marshal.ReleaseComObject(cursor);
if (pFtWsFct != null)
Marshal.ReleaseComObject(pFtWsFct);
if (workspaceName != null)
Marshal.ReleaseComObject(workspaceName);
if (unionLayer != null)
Marshal.ReleaseComObject(unionLayer);
}
}
#region 获取最新图斑编号
private void GetMaxTBBH(IFeatureClass fc, ref Dictionary<string, int> result)
{
ICursor cursor = (fc as ITable).Search(new QueryFilterClass() { SubFields = "ZLDWDM,TBBH" }, true);
IRow row = null;
int zlIndex = -1;
int bhIndex = -1;
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();
if (zl.Length > 12)
zl = zl.Substring(0, 12);
zl = zl.Replace(zl.Substring(0, 6), Parm.PrjInfo.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);
}
}
}
}
#endregion
#region 获取最新标识码
public 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 = Parm.PrjInfo.CODE + "1210";
result = leftStr + xh.ToString().PadLeft(8, '0');
return result;
}
private static string GetMaxBSM(IFeatureClass fc)
{
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;
if (table.FindField("XZQTZLX") != -1)
{
tableSort.QueryFilter = new QueryFilterClass() { WhereClause = "XZQTZLX is NULL" };
}
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 面积平差
/// <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 (tpsm < 0)//int值溢出了
{
long tems = (long)(Math.Abs(Math.Round(mjc, 2)) / (double)0.01);
e = (int)(tems / shpList.Count);
f = (int)(tems % 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);
LogAPI.Debug(ex);
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", "")}");
//}
//else
//if (field.Name.Contains("BGH"))
//{
// index = FeatureClass.Fields.FindField(field.Name.Replace("BGHTB", ""));
// if (index == -1)
// index = FeatureClass.Fields.FindField(field.Name.Replace("BGH", ""));
//}
//else
//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);
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"))
{
string fieldName = field.Name.Replace("BGQTB", "").Replace("BGQ", "");
if ("BGQTBBH,BGQTBMJ,BGQTBXHDM,BGQTBXHMC,BGQTBDLMJ".Contains(field.Name))
fieldName = field.Name.Replace("BGQ", "");
index = FeatureClass.Fields.FindField($"{fieldName}");
if (index == -1)
index = FeatureClass.Fields.FindField(fieldName);
}
else
if (field.Name.Contains("BGH"))
{
string fieldName = field.Name.Replace("BGHTB", "").Replace("BGH", "");
if ("BGHTBBH,BGHTBMJ,BGHTBXHDM,BGHTBXHMC,BGHTBDLMJ".Contains(field.Name))
fieldName = field.Name.Replace("BGH", "");
index = FeatureClass.Fields.FindField(fieldName + "_1");
}
if (index == -1) continue;
dicField.Add(i, index);
string fName = field.Name.Replace("BGQTB", "").Replace("BGHTB", "").Replace("BGQ", "").Replace("BGH", "");
index = FeatureClass.Fields.FindField($"{fName}_1");
if ("BGQTBBH,BGQTBMJ,BGQTBXHDM,BGQTBXHMC,BGQTBDLMJ,BGHTBBH,BGHTBMJ,BGHTBXHDM,BGHTBXHMC,BGHTBDLMJ".Contains(field.Name))
fName = field.Name.Replace("BGH", "").Replace("BGQ", "");
index = FeatureClass.Fields.FindField($"{fName}_1");
if (index == -1)
index = FeatureClass.Fields.FindField(fName);
if (index == -1) continue;
dicField1.Add(i, index);
}
(pFc as ITable).DeleteSearchedRows(null);
string s = (pFc as FeatureClass).Workspace.PathName;
IFeatureClassLoad pFclsLoad = pFc as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//此处写编辑的代码
S_Cursor = FeatureClass.Search(pFilter, true);
IFeature f = null;
T_Cursor = pFc.Insert(true);
IFeatureBuffer buffer = pFc.CreateFeatureBuffer();
var iFID_DLTBBG = FeatureClass.FindField("FID_DLTBGX");
var iFID_DLTB = FeatureClass.FindField("FID_JC_DLTB");
var ibgxw = pFc.FindField("BGXW");
//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 idxONLYZLBG = pFc.FindField("ONLYZLBG");
var idxBGHTBBSM = pFc.FindField("BGHTBBSM");
var idxBGHTBBH = pFc.FindField("BGHTBBH");
var idxXZQTZLX = pFc.FindField("XZQTZLX");
var idxJCTBBH = FeatureClass.FindField("TBBH_1");
if (idxJCTBBH == -1)
idxJCTBBH = FeatureClass.FindField("TBBH");
var idxJCXZQTZLX = FeatureClass.FindField("XZQTZLX");
var tbbgmj = 0.00;
int bsm = 1;
while ((f = S_Cursor.NextFeature()) != null)
{
string tempXZQTZLX = f.Value[idxJCXZQTZLX].ToTrim();
if (GXGCvaluePairs.ContainsKey(f.OID))
{
tbbgmj = GXGCvaluePairs[f.OID];
//if (tbbgmj == 0) continue;
}
var FID_DLTBBG = f.Value[iFID_DLTBBG].ToString();
var FID_DLTB = f.Value[iFID_DLTB].ToString();
var row = data_BSM.Select($"FID_DLTBGX={FID_DLTBBG} and FID_JC_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
{
if (f.Value[dicField1[item]].ToString().Contains(" ") || f.Value[dicField1[item]] is DBNull)
{
buffer.Value[item] = f.Value[dicField1[item]].ToTrim();
}
else
{
buffer.Value[item] = f.Value[dicField1[item]];
}
}
catch
{
buffer.Value[item] = f.Value[dicField1[item]];
}
}
}
else
{
foreach (int item in dicField.Keys)
{
try
{
buffer.Value[item] = f.Value[dicField[item]];
}
catch
{
buffer.Value[item] = f.Value[dicField[item]];
}
}
}
if (idxJCTBBH != -1)
buffer.Value[idxBGHTBBH] = f.Value[idxJCTBBH];
buffer.Value[ibgxw] = row[0]["BGXW"];
if (GXGCvaluePairs.ContainsKey(f.OID))
tbbgmj = GXGCvaluePairs[f.OID];
else
tbbgmj = row[0]["TBBGMJ"].ToDouble();
buffer.Value[itbbgmj] = Math.Round(tbbgmj, 2);//图斑变更面积
var bgqkcmj = Math.Round((decimal)(buffer.Value[ibgqkcxs].ToDouble() * tbbgmj), 2, MidpointRounding.AwayFromZero).ToDouble();//变更前扣除面积
buffer.Value[ibgqkcmj] = bgqkcmj;
buffer.Value[ibgqtbdlmj] = tbbgmj - bgqkcmj;//变更前图斑地类面积
var bghkcmj = Math.Round((decimal)(buffer.Value[ibghkcxs].ToDouble() * tbbgmj), 2, MidpointRounding.AwayFromZero).ToDouble();//变更后扣除面积
if (tempXZQTZLX == "2" || tempXZQTZLX == "4")
{
buffer.Value[ibghkcmj] = 0;
buffer.Value[ibghtbdlmj] = 0;//变更后图斑地类面积
buffer.Value[idxBGHTBBSM] = "";
buffer.Value[idxBGHTBBH] = "";
for (int i = 0; i < pFc.Fields.FieldCount; i++)
{
IField bghField = pFc.Fields.Field[i];
if (bghField.Name.StartsWith("BGH"))
{
try
{
buffer.Value[i] = DBNull.Value;
}
catch (Exception ex)
{
buffer.Value[i] = 0;
}
}
}
}
else if (tempXZQTZLX == "3")
{
for (int i = 0; i < pFc.Fields.FieldCount; i++)
{
IField bghField = pFc.Fields.Field[i];
if (bghField.Name.StartsWith("BGQ"))
{
try
{
buffer.Value[i] = DBNull.Value;
}
catch (Exception ex)
{
buffer.Value[i] = 0;
}
}
}
buffer.Value[ibghkcmj] = bghkcmj;
buffer.Value[ibghtbdlmj] = tbbgmj - bghkcmj;//变更后图斑地类面积
buffer.Value[idxBGHTBBSM] = row[0]["BSM_1"];
buffer.Value[idxBGHTBBH] = row[0]["TBBH_1"];
}
else
{
buffer.Value[ibghkcmj] = bghkcmj;
buffer.Value[ibghtbdlmj] = tbbgmj - bghkcmj;//变更后图斑地类面积
buffer.Value[idxBGHTBBSM] = row[0]["BSM_1"];
buffer.Value[idxBGHTBBH] = row[0]["TBBH_1"];
}
buffer.Value[idxONLYZLBG] = row[0]["BZ_1"];
if (idxJCXZQTZLX != -1)
{
if (string.IsNullOrWhiteSpace(f.Value[idxJCXZQTZLX].ToTrim()))
{
buffer.Value[idxXZQTZLX] = "0";
}
else
{
buffer.Value[idxXZQTZLX] = f.Value[idxJCXZQTZLX];
}
}
else
{
buffer.Value[idxXZQTZLX] = "0";
}
buffer.Value[ibsm] = $"{Parm.PrjInfo.CODE}2111{(bsm++).ToString().PadLeft(8, '0')}";
buffer.Value[igxsj] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : 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, DataTable dtDLTBGX)
{
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)
index = FeatureClass.Fields.FindField($"BGHTB{field.Name}");
if (index == -1)
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;
T_Cursor = pFc.Insert(true);
int idxBSM = pFc.FindField("BSM");
int idxTBBH = pFc.FindField("TBBH");
int idxTBMJ = pFc.FindField("TBMJ");
int idxGXSJ = pFc.FindField("GXSJ");
//int idxGXSJ = pFc.FindField("SJNF");
var idxONLYZLBG = pFc.FindField("ONLYZLBG");
int idxGXOID = FeatureClass.FindField("FID_DLTBGX");
IFeatureBuffer buffer = pFc.CreateFeatureBuffer();
while ((f = S_Cursor.NextFeature()) != null)
{
int gxOID = f.OID;// f.Value[idxGXOID].ToInt();
var row = dtDLTBGX.Select($"FID_DLTBGX={gxOID}");
if (row == null || row.Length == 0) continue;
if (row[0]["TBMJ"].ToDouble() <= 0) continue;
buffer.Shape = f.ShapeCopy;
foreach (int item in dicField.Keys)
{
buffer.Value[item] = f.Value[dicField[item]];
}
buffer.Value[idxBSM] = row[0]["BSM_1"];
buffer.Value[idxTBBH] = row[0]["TBBH_1"];
buffer.Value[idxTBMJ] = row[0]["TBMJ"];
buffer.Value[idxONLYZLBG] = row[0]["BZ_1"];
buffer.Value[idxGXSJ] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : 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)
{
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 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)
{
Console.WriteLine($"Log:TableToTable处理失败:{ex.Message}");
Console.WriteLine($"Log:TableToTable处理失败:{ex.StackTrace}");
//LogAPI.Debug(ex);
throw ex;
}
}
#endregion
}
public class Adjustment
{
public int ID { get; set; }
public double bgmj { get; set; }
}
public class PDJBModel
{
public string PDJB { get; set; }
public double MJ { get; set; }
}
}