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

1525 lines
81 KiB

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
//using IDEParameter;
using KGIS.Framework.AE;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.AE.GaussCalculate;
using KGIS.Framework.AE.GPHelper;
using KGIS.Framework.AE.ExtensionMethod;
using KGIS.Framework.DBOperator;
using KGIS.Framework.ThreadManager;
using KGIS.Framework.Utils;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.IO;
namespace IDGForNDBG
{
public class ZLHZHelper : BaseIDG
{
private IFeatureClass _CZCFc = null;
private string TempGDBPath = string.Empty;
private string TempDBPath = string.Empty;
private List<string> listSQL = new List<string>();
Dictionary<int, double> AreaList = new Dictionary<int, double>();
public void Execute(IDGParameter pParm)
{
//ThreadManager.Instance.QueueUserWorkItem(new System.Threading.WaitCallback(ZLHZ), pParm);
ZLHZ(pParm);
}
public void ZLHZ(object pParm)
{
DateTime StartTime = DateTime.Now;
Console.WriteLine("Log:正在进行增量汇总...");
IDGParameter Parm = pParm as IDGParameter;
IRDBHelper rdbHelper = null;
IFeatureClass gxgc_FeatureClass = null;
string resultTableName = "GXGC_CZC20X";
IFeatureLayer tempFeatureLayer = null;
ICursor pCursor = null;
IRow pRow = null;
try
{
OpenDB(Parm);
string TempDir = CreateTempDB("ZLHZ");
TempGDBPath = System.IO.Path.Combine(TempDir, "TempGDB.gdb");
string dbPath = $"{Parm.PrjInfo.ProjDir}\\BGTJ.sqlite";
TempDBPath = dbPath;
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
string createTableSQL = $"CREATE TABLE IF NOT EXISTS {resultTableName} (BGHTBBSM,BGQTBBSM,BGQCZCSXM,MJ,ISInterSect,BGMJ)";
rdbHelper.ExecuteNonQueryWithException(createTableSQL, CommandType.Text);
rdbHelper.ExecuteNonQueryWithException($" delete from {resultTableName} ", CommandType.Text);
string insertSQL = "insert into " + resultTableName + "(BGHTBBSM,BGQTBBSM,BGQCZCSXM,MJ,ISInterSect,BGMJ) values({0});";
#region
gxgc_FeatureClass = GxgcTBLayer.FeatureClass;
IFeatureLayer tempjcCjdcqLayer = null;
if (!string.IsNullOrEmpty(Parm.PrjInfo.DR_CZCPath))
{
string HRCZC = Parm.PrjInfo.DR_CZCPath;
string hr_dbPath = HRCZC.Substring(0, HRCZC.ToLower().IndexOf(".gdb"));
hr_dbPath = hr_dbPath + ".gdb";
IWorkspaceAPI hrWsAPI = new WorkspaceAPI(hr_dbPath, WorkspaceTypeEnum.GDBFile);
FileInfo fInfo = new FileInfo(HRCZC);
IFeatureClassAPI hrFcAPI = hrWsAPI.OpenFeatureClass(fInfo.Name);
IFeatureLayer hrCZCLayer = new FeatureLayerClass() { FeatureClass = hrFcAPI.FeatureClass };
GPParamClass gPParamClass = new GPParamClass();
gPParamClass.FirstFeatureLayer = JcCzcLayer;
gPParamClass.SecondFeatureLayer = hrCZCLayer;
gPParamClass.IsGetOutPutFeature = true;
gPParamClass.GPType = EnumGPType.Erase;
gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "CZC");
GPHelper.Instance.ExeGPForProces(gPParamClass, ref tempjcCjdcqLayer);
hrFcAPI.FcToFc(tempjcCjdcqLayer.FeatureClass, new QueryFilterClass() { WhereClause = "CZCLX='203' or CZCLX='203A' " }, false);
tempjcCjdcqLayer.Name = "城镇村";
_CZCFc = tempjcCjdcqLayer.FeatureClass;
ITable tempdltb = _CZCFc as ITable;
tempdltb.DeleteSearchedRows(new QueryFilterClass() { WhereClause = "CZCLX<>'203' and CZCLX<>'203A'" });
}
else
{
_CZCFc = JcCzcLayer.FeatureClass;
}
//IWorkspaceAPI wsAPI = new WorkspaceAPI(TempGDBPath, WorkspaceTypeEnum.GDBFile);
//IFeatureClassAPI Temp_CZCDYD = wsAPI.CreateFeatureClass("CZCDYD", (JcCzcLayer.FeatureClass as IGeoDataset).SpatialReference, JcCzcLayer.FeatureClass.Fields);
//IFeatureClassAPI fcAPI = new FeatureClassAPI(JcCzcLayer.FeatureClass);
var CZC20X_Layer_BGQCZCSXM = _CZCFc.FindField("CZCLX");
pCursor = (gxgc_FeatureClass as ITable).Search(new QueryFilterClass() { WhereClause = "ONLYZLBG is null OR ONLYZLBG = '' or XZQTZLX='1' or XZQTZLX='2' " }, true);
int shapeIndex = gxgc_FeatureClass.Fields.FindField("SHAPE");
int tbbgmjIndex = gxgc_FeatureClass.Fields.FindField("TBBGMJ");
int BGHTBBSMIndex = gxgc_FeatureClass.Fields.FindField("BGHTBBSM");
int BGQTBBSMIndex = gxgc_FeatureClass.Fields.FindField("BGQTBBSM");
int BGQDLBMIndex = gxgc_FeatureClass.Fields.FindField("BGQDLBM");
int BGQCZCSXMIndex = gxgc_FeatureClass.Fields.FindField("BGQCZCSXM");
//int idxXZQTZLX = gxgc_FeatureClass.Fields.FindField("XZQTZLX");
if (shapeIndex < 0)
{
throw new Exception("未找到SHAPE字段");
}
double MJ = 0;
string BGHTBBSM = string.Empty;
string BGQTBBSM = string.Empty;
string BGQDLBM = string.Empty;
string BGQCZCSXM = string.Empty;
//string XZQTZLX = string.Empty;
string CZCSXM = string.Empty;
List<string> listSQL = new List<string>();
var count = gxgc_FeatureClass.FeatureCount(null);
var featurecount = 0;
List<string> JSYD = new List<string>() { "05H1", "0508", "0601", "0602", "0603", "0701", "0702", "08H1", "08H2", "0809", "0810", "09", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201" };
while ((pRow = pCursor.NextRow()) != null)
{
if (pRow.OID == 27939)
{
}
featurecount++;
BGQDLBM = pRow.get_Value(BGQDLBMIndex).ToString();
BGQCZCSXM = pRow.get_Value(BGQCZCSXMIndex).ToString();
//if (idxXZQTZLX != -1)
// XZQTZLX = pRow.Value[idxXZQTZLX].ToTrim();
//if (BGQCZCSXM != "203" && BGQCZCSXM != "203A" && BGQCZCSXM.ToTrim() != "") continue;
//if ((BGQCZCSXM == "203" || BGQCZCSXM == "203A") && JSYD.Contains(BGQDLBM.Length > 4 ? BGQDLBM.Substring(0, 4) : BGQDLBM)) continue;
if (BGQCZCSXM != "203" && BGQCZCSXM.ToTrim() != "") continue;
if (BGQCZCSXM == "203" && JSYD.Contains(BGQDLBM.Length > 4 ? BGQDLBM.Substring(0, 4) : BGQDLBM)) continue;
IPolygon pPolygon = pRow.get_Value(shapeIndex) as IPolygon;
var gxgcmj = pPolygon.GetEllipseArea();
MJ = pRow.get_Value(tbbgmjIndex).ToDouble();//TBBGMJ
BGHTBBSM = pRow.get_Value(BGHTBBSMIndex).ToString();
BGQTBBSM = pRow.get_Value(BGQTBBSMIndex).ToString();
if (BGQTBBSM == "421022211000200165" && BGHTBBSM == "421022211000251336")
{
}
//IFeature featuresad = GxgcTBLayer.FeatureClass.GetFeature((int)pRow.get_Value(0));
try
{
List<IFeature> jcFeatures = FeatureAPI.Identify2(pPolygon, new FeatureLayer() { FeatureClass = _CZCFc });
//if (jcFeatures.Count == 0&& (XZQTZLX=="2"&& XZQTZLX == "1"))
//{
//}
foreach (IFeature item in jcFeatures)
{
CZCSXM = item.Value[CZC20X_Layer_BGQCZCSXM].ToString();
IGeometry IntersectGeo = FeatureAPI.InterSect(pPolygon, item.ShapeCopy);
if (IntersectGeo.IsEmpty)
continue;
List<ShapeInfo> areaOperationData = new List<ShapeInfo>();
ShapeInfo InterShape = new ShapeInfo(IntersectGeo);
m_FeatureInfo = InterShape;
List<ShapeInfo> InterShapes = GetFeatures();
int id = 0;
foreach (var interShapes in InterShapes)
{
id++;
interShapes.SetBGQCZCSXM(CZCSXM);
interShapes.SetISInterSect("1");
areaOperationData.Add(interShapes);
}
IGeometry DiffGeo = FeatureAPI.Difference(pPolygon, item.ShapeCopy);
List<ShapeInfo> DiffShapes = null;
if (DiffGeo != null && !DiffGeo.IsEmpty)
{
ShapeInfo DiffShape = new ShapeInfo(DiffGeo);
m_FeatureInfo = DiffShape;
DiffShapes = GetFeatures();
foreach (var diffShapes in DiffShapes)
{
id++;
diffShapes.SetISInterSect("0");
diffShapes.SetBGQCZCSXM("");
areaOperationData.Add(diffShapes);
}
}
//AreaAdjustment2(areaOperationData, MJ);
//按比例拆分面积
foreach (var area in areaOperationData)
{
if (area.Area == 0) continue;
area.SetArea(area.Area / gxgcmj * MJ);
}
areaOperationData = areaOperationData.OrderByDescending(x => x.Area).ToList();
double cz = MJ - areaOperationData.Sum(x => x.Area);
cz = Math.Round(cz, 2);
if (cz != 0)
{
var area = areaOperationData[0].Area + cz;
areaOperationData[0].SetArea(area);
}
foreach (var area in areaOperationData)
{
//if (area.Area == 0) continue;
listSQL.Add(string.Format(insertSQL, $"'{BGHTBBSM}','{BGQTBBSM}','{area.BGQCZCSXM}','{area.Area}','{area.ISInterSect}','{MJ}'"));
}
}
}
catch (Exception)
{
}
}
InsertDB(listSQL, dbPath);
listSQL.Clear();
listSQL = null;
GC.Collect();
#endregion
#region MyRegion
//#region
//gxgc_FeatureClass = GxgcTBLayer.FeatureClass;// MapsManager.Instance.MapService.GetFeatureClassByName("DLTBGXGC");
//_CZCFc = JcCzcLayer.FeatureClass;
//GPParamClass gPParamClass = new GPParamClass();
//gPParamClass.FirstFeatureLayer = JcCzcLayer;
//gPParamClass.GPType = EnumGPType.SelectLayerByAttribute;
//gPParamClass.IsGetOutPutFeature = true;
//gPParamClass.Where_clause = "CZCLX = '203' or CZCLX = '203A'";
//gPParamClass.FcName = "DLTBGX201";
//gPParamClass.TempGDBPath = TempGDBPath;
//GPHelper.Instance.ExeGPForProces(gPParamClass, ref CZC20X_Layer);
//IFeatureLayer pGxgc_CzcLayer = null;
//#region 变更层与基础地类图斑联合
//GPParamClass paramClass = new GPParamClass()
//{
// FirstFeatureLayer = GxgcTBLayer,
// SecondFeatureLayer = CZC20X_Layer,
// OutFeatureClassPath = $"{TempGDBPath}\\Gxgc_CzcUnion_M",
// IsGetOutPutFeature = true,
// PreserveAttributes = "ALL",
// GPType = EnumGPType.Union
//};
//GPHelper.Instance.ExeGPForProces(paramClass, ref pGxgc_CzcLayer);
//#endregion
//#region 拆分多部件
//paramClass = new GPParamClass();
//paramClass.FirstFeatureLayer = pGxgc_CzcLayer;
//paramClass.OutFeatureClassPath = $"{TempGDBPath}\\Gxgc_CzcUnion";
//paramClass.IsGetOutPutFeature = true;
//paramClass.GPType = EnumGPType.MultipartToSinglePath;
//GPHelper.Instance.ExeGPForProces(paramClass, ref pGxgc_CzcLayer);
//#endregion
//IWorkspace pOutWork = new SqlWorkspaceFactoryClass().OpenFromFile(dbPath, 0);
//IFeatureClass featureClass = pGxgc_CzcLayer.FeatureClass;
//IWorkspace ws = (featureClass as FeatureClass).Workspace;
//rdbHelper.ExecuteSQL(" drop table Gxgc_CzcUnion ");
//TableToTable(ws as IFeatureWorkspace, pOutWork, "Gxgc_CzcUnion");
//#region 面积平差
//DataTable data_BSM = rdbHelper.ExecuteDatatable("tab", "select OBJECTID,FID_DLTBGXGC,TBBGMJ from Gxgc_CzcUnion where FID_DLTBGXGC!=-1 GROUP BY FID_DLTBGXGC HAVING count(FID_DLTBGXGC)>1", true);
//List<int> GcOIDList = new List<int>();
//if (data_BSM != null && data_BSM.Rows.Count > 0)
//{
// foreach (DataRow row in data_BSM.Rows)
// {
// var gcOID = row["FID_DLTBGXGC"].ToInt();
// if (!GcOIDList.Contains(gcOID) && gcOID != -1)
// GcOIDList.Add(gcOID);
// }
//}
//ThreadManager thm = new ThreadManager();
//#region 计算面积
//{
// int num = GcOIDList.Count / 4;
// for (int i = 0; i < 4; i++)
// {
// List<int> tempBsmList = new List<int>();
// if (i < 3)
// {
// tempBsmList = GcOIDList.GetRange(i * num, num);
// }
// else
// {
// tempBsmList = GcOIDList.GetRange(i * num, GcOIDList.Count - i * num);
// }
// CalcAreaParm threadParm = new CalcAreaParm();
// threadParm.OidList = tempBsmList;
// threadParm.StrGxgcLayer = GeoDBAPI.SerialzedPersist(GxgcTBLayer);
// thm.QueueUserWorkItem(new System.Threading.WaitCallback(CalculateArea), threadParm);
// }
// while (thm.ActiveCount > 0) { }
//}
//#endregion
//{
// int num = GcOIDList.Count / 4;
// for (int i = 0; i < 4; i++)
// {
// List<int> tempBsmList = new List<int>();
// if (i < 3)
// {
// tempBsmList = GcOIDList.GetRange(i * num, num);
// }
// else
// {
// tempBsmList = GcOIDList.GetRange(i * num, GcOIDList.Count - i * num);
// }
// CalcAreaParm threadParm = new CalcAreaParm();
// threadParm.OidList = tempBsmList;
// threadParm.StrGxgcLayer = GeoDBAPI.SerialzedPersist(GxgcTBLayer);
// threadParm.StrUnionLayer = GeoDBAPI.SerialzedPersist(pGxgc_CzcLayer);
// threadParm.InsertSQL = insertSQL;
// threadParm.ListSQL = new List<string>();
// threadParm.PcList = new List<PCModel>();
// thm.QueueUserWorkItem(new System.Threading.WaitCallback(PressGXGC), threadParm, new System.Threading.WaitCallback(PressComplate));
// }
//}
//{
// //CalcAreaParm threadParm = new CalcAreaParm();
// //threadParm.OidList = pcOIDList;
// //threadParm.StrGxgcLayer = GeoDBAPI.SerialzedPersist(bgParm.GXGCTBLayer);
// //threadParm.StrUnionLayer = GeoDBAPI.SerialzedPersist(pGxgc_CzcLayer);
// //threadParm.InsertSQL = insertSQL;
// //threadParm.ListSQL = new List<string>();
// //threadParm.PcList = new List<PCModel>();
// //thm.QueueUserWorkItem(new System.Threading.WaitCallback(PressGXGC), threadParm, new System.Threading.WaitCallback(PressComplate));
//}
//while (thm.ActiveCount > 0) { }
////if (AreaList.Count > 0)
////{
////}
//#endregion
////InsertDB(listSQL, dbPath);
////listSQL.Clear();
////listSQL = null;
//GC.Collect();
//#endregion
#endregion
CreateBGYLB(Parm);
Console.WriteLine($"Log:增量汇总提取完成。耗时:{GetTime(StartTime)}");
}
catch (Exception ex)
{
Console.WriteLine("Err:增量汇总时发生异常!");
LogAPI.Debug($"执行增量汇总错误:{ex.Message}");
LogAPI.Debug($"执行增量汇总错误:{ex.StackTrace}");
}
finally
{
if (gxgc_FeatureClass != null)
Marshal.ReleaseComObject(gxgc_FeatureClass);
if (tempFeatureLayer != null)
Marshal.ReleaseComObject(tempFeatureLayer);
}
}
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 = KGIS.Framework.Utils.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;// System.IO.Path.Combine(fileInfo.DirectoryName, "NMDB" + ".gdb");
BgWsAPI = new WorkspaceAPI(PathBgDB, WorkspaceTypeEnum.GDBFile);
if (BgWsAPI.CurrentWorkspace == null)
{
Console.WriteLine("打开变更数据库失败!");
return;
}
ZlWsAPI = new WorkspaceAPI(PathZLDB, WorkspaceTypeEnum.GDBFile);
if (ZlWsAPI.CurrentWorkspace == null)
{
Console.WriteLine("打开增量数据库失败!");
return;
}
NmWsAPI = new WorkspaceAPI(PathNMDB, WorkspaceTypeEnum.GDBFile);
LayerCfg JCLayerInfo = layerInfo.Layers.FirstOrDefault(f => f.LayerName == "年初数据");
if (JCLayerInfo == null)
{
throw new Exception("Err:获取年初数据库失败!");
}
List<LayerCfg> NcList = JCLayerInfo.GetAllItem();
LayerCfg _JcCzcLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "城镇村等用地");
_jcCzcLayer = OpenLayer(_JcCzcLayerInfo);
if (_JcCzcLayerInfo == null)
throw new Exception("Err:获取年初城镇村等用地数据失败!");
_gxgcTBLayer = OpenLayer(ZlWsAPI, "DLTBGXGC");
}
catch (Exception ex)
{
throw ex;
}
}
public void CalculateArea(object pParm)
{
try
{
CalcAreaParm CalParm = pParm as CalcAreaParm;
IFeatureLayer _Layer = GeoDBAPI.DeSerialzedPersist(CalParm.StrGxgcLayer) as IFeatureLayer;
IFeatureCursor pCursor = _Layer.FeatureClass.Search(new QueryFilterClass() { SubFields = "OBJECTID,SHAPE" }, true);
IFeature feature = null;
//int _i = 0;
while ((feature = pCursor.NextFeature()) != null)
{
if (!CalParm.OidList.Contains(feature.OID)) continue;
double area = GetEllipseArea(feature.ShapeCopy);
lock (AreaList)
{
AreaList.Add(feature.OID, area.ToDouble());
}
}
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
}
}
private void PressComplate(object obj)
{
lock (TempDBPath)
{
CalcAreaParm CalParm = obj as CalcAreaParm;
IEnumerable<IGrouping<int, PCModel>> groupInfo = CalParm.PcList.GroupBy(g => g.FID_Gxgc);
foreach (var item in groupInfo)
{
List<PCModel> _list = item.ToList();
foreach (var pc in _list)
{
if (pc.MJ == 0) continue;
pc.MJ = pc.MJ / pc.ZGeoMJ * pc.ZMJ;
}
_list = _list.OrderByDescending(o => o.MJ).ToList();
double cz = _list[0].ZMJ - _list.Sum(x => x.MJ);
cz = Math.Round(cz, 2);
if (cz != 0)
{
_list[0].MJ = _list[0].MJ + cz;
}
foreach (var model in _list)
{
if (model.MJ == 0) continue;
CalParm.ListSQL.Add(string.Format(CalParm.InsertSQL, $"'{model.BGHTBBSM}','{model.BGQTBBSM}','{model.BGQCZCSXM}','{model.MJ}','{model.IsIntersect}','{model.ZMJ}'"));
}
}
InsertDB(CalParm.ListSQL, TempDBPath);
CalParm.PcList.Clear();
CalParm.ListSQL.Clear();
CalParm.OidList.Clear();
CalParm = null;
Console.WriteLine("...");
}
}
private void PressGXGC(object pObj)
{
try
{
CalcAreaParm CalParm = pObj as CalcAreaParm;
IFeatureLayer _UnionLayer = GeoDBAPI.DeSerialzedPersist(CalParm.StrUnionLayer) as IFeatureLayer;
IFeatureCursor pCursor = _UnionLayer.FeatureClass.Search(null, true);
int IdxFid_Gxgc = _UnionLayer.FeatureClass.Fields.FindField("FID_DLTBGXGC");
int IdxFid_Czc = _UnionLayer.FeatureClass.Fields.FindField("FID_DLTBGX201");
int tbbgmjIndex = _UnionLayer.FeatureClass.Fields.FindField("TBBGMJ");
int BGHTBBSMIndex = _UnionLayer.FeatureClass.Fields.FindField("BGHTBBSM");
int BGQTBBSMIndex = _UnionLayer.FeatureClass.Fields.FindField("BGQTBBSM");
int BGQDLBMIndex = _UnionLayer.FeatureClass.Fields.FindField("BGQDLBM");
int BGQCZCSXMIndex = _UnionLayer.FeatureClass.Fields.FindField("BGQCZCSXM");
int JCCZCSXMIndex = _UnionLayer.FeatureClass.Fields.FindField("CZCLX");
double MJ = 0;
string BGHTBBSM = string.Empty;
string BGQTBBSM = string.Empty;
string BGQDLBM = string.Empty;
string BGQCZCSXM = string.Empty;
string CZCSXM = string.Empty;
List<string> listSQL = new List<string>();
var count = _UnionLayer.FeatureClass.FeatureCount(null);
//var featurecount = 0;
IFeature pRow = null;
List<string> JSYD = new List<string>() { "05H1", "0508", "0601", "0602", "0603", "0701", "0702", "08H1", "08H2", "0809", "0810", "09", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201" };
//List<PCModel> _List = new List<PCModel>();
int num = 0;
while ((pRow = pCursor.NextFeature()) != null)
{
num++;
int Fid_Gxgc = pRow.Value[IdxFid_Gxgc].ToInt();
int Fid_Czc = pRow.Value[IdxFid_Czc].ToInt();
if (!CalParm.OidList.Contains(Fid_Gxgc))
continue;
bool IsIntersect = Fid_Gxgc != -1 && Fid_Czc != -1;
//featurecount++;
BGQDLBM = pRow.get_Value(BGQDLBMIndex).ToString();
BGQCZCSXM = pRow.get_Value(BGQCZCSXMIndex).ToString();
if (BGQCZCSXM != "203" && BGQCZCSXM != "203A" && BGQCZCSXM.ToTrim() != "") continue;
if ((BGQCZCSXM == "203" || BGQCZCSXM == "203A") && JSYD.Contains(BGQDLBM.Length > 4 ? BGQDLBM.Substring(0, 4) : BGQDLBM)) continue;
//if (featurecount % 100 == 0 || featurecount == count)
// Console.WriteLine($"正在进行城镇村范围叠加...【{featurecount}/{count}】");
IGeometry geometry = pRow.ShapeCopy;//.get_Value(shapeIndex) as IGeometry;
var gxgcmj = GetEllipseArea(geometry);
MJ = Convert.ToDouble(pRow.get_Value(tbbgmjIndex));
BGHTBBSM = pRow.get_Value(BGHTBBSMIndex).ToString();
BGQTBBSM = pRow.get_Value(BGQTBBSMIndex).ToString();
CZCSXM = pRow.Value[JCCZCSXMIndex].ToString();
if (!IsIntersect)
CZCSXM = BGQCZCSXM;
PCModel model = new PCModel();
model.FID = pRow.OID;
model.FID_Gxgc = Fid_Gxgc;
model.BGQTBBSM = BGQTBBSM;
model.BGHTBBSM = BGHTBBSM;
model.BGQCZCSXM = CZCSXM;
model.MJ = gxgcmj;
model.ZMJ = MJ;
if (AreaList.ContainsKey(Fid_Gxgc))
model.ZGeoMJ = AreaList[Fid_Gxgc];
model.IsIntersect = IsIntersect ? "1" : "0";
CalParm.PcList.Add(model);
Marshal.ReleaseComObject(geometry);
//CalParm.ListSQL.Add(string.Format(CalParm.InsertSQL, $"'{BGHTBBSM}','{BGQTBBSM}','{area.BGQCZCSXM}','{area.Area}','{area.ISInterSect}','{MJ}'"));
}
}
catch (Exception ex)
{
throw ex;
}
}
private 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;
}
}
#region InsertDataToMemeoryLayer
private void InsertDataToMemeoryLayer(IFeatureClass pSource, IFeatureClass pTarget, IQueryFilter pFilter = null)
{
try
{
if (pSource == null || pTarget == null) return;
IFeatureClassAPI fcAPI = new FeatureClassAPI(pSource);
if (pTarget != null)
fcAPI.FcToFc(pTarget, pFilter, false);
}
catch (Exception ex)
{
LogAPI.Debug("获取城镇村范围数据失败:");
LogAPI.Debug(ex);
}
}
#endregion
#region 生成变更一览表
/// <summary>
/// 生成变更一览表
/// </summary>
private void CreateBGYLB(IDGParameter pParm)
{
IRDBHelper rdbHelper = null;
try
{
Console.WriteLine("Log:正在生成变更一览表...");
string dbPath = $"{pParm.PrjInfo.ProjDir}\\BGTJ.sqlite";
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
IWorkspace pOutWork = new SqlWorkspaceFactoryClass().OpenFromFile(dbPath, 0);
IFeatureClass featureClass = GxgcTBLayer.FeatureClass;
IWorkspace ws = (featureClass as FeatureClass).Workspace;
rdbHelper.ExecuteSQL(" drop table DLTBGXGC ");
TableToTable(ws as IFeatureWorkspace, pOutWork, "DLTBGXGC");
DataTable dt = rdbHelper.ExecuteDatatable("DLTBGXGC", @" select a.BGQTBBSM,a.BGHTBBSM,BGQTBBH,BGHTBBH,BGQZLDWDM,BGHZLDWDM,BGQZLDWMC,BGHZLDWMC,BGQQSDWDM,BGHQSDWDM,BGQQSDWMC,BGHQSDWMC,BGQQSXZ,BGHQSXZ, BGQDLBM, BGHDLBM, BGQKCDLBM, BGHKCDLBM, BGQKCXS, BGHKCXS, BGQKCMJ, BGHKCMJ, BGQGDLX, BGHGDLX, BGQGDPDJB, BGHGDPDJB, a.BGQCZCSXM, BGHCZCSXM, BGQTBXHDM, BGHTBXHDM, BGQZZSXDM, BGHZZSXDM, BGQMSSM, BGHMSSM, BGQGDDB, BGHGDDB, TBBGMJ, XZQTZLX, BGXW,ONLYZLBG from DLTBGXGC a ", true);
if (!rdbHelper.TableIsExist("BGYLB"))
{
rdbHelper.ExecuteSQL(" Create TABLE BGYLB ( BGQTBBSM text(100),BGQTBBH text(100),BGQZLDWDM text(100),BGQZLDWMC text(100),BGQQSDWDM text(100),BGQQSDWMC text(100),BGQQSXZ text(100),BGQDLBM text(100),BGQGDLX text(100),BGQGDPDJB text(100),BGQCZCSXM text(100),BGQTBXHDM text(100),BGQZZSXDM text(100),BGQMSSM text(100),BGQGDDB text(100),BGHTBBSM text(100),BGHTBBH text(100),BGHZLDWDM text(100),BGHZLDWMC text(100),BGHQSDWDM text(100),BGHQSDWMC text(100),BGHQSXZ text(100),BGHDLBM text(100),BGHGDLX text(100),BGHGDPDJB text(100),BGHCZCSXM text(100),BGHTBXHDM text(100),BGHZZSXDM text(100),BGHMSSM text(100),BGHGDDB text(100),BGMJ text(100),XZQTZLX text(100),BZ text(10) ) ");
}
rdbHelper.ExecuteSQL(" delete from BGYLB where BZ is null or BZ=''");//行政区划入、划出数据不删除
if (dt != null)
{
int count = dt.Rows.Count;
if (count == 0)
{
LogAPI.Debug("DLTBGXGC表为空");
}
int i = 1;
#region 定义参数
string bgxw = "";
//行政区调整类型
string XZQTZLX = "";
//图斑编号
string BGQTBBH = "";
string BGHTBBH = "";
//坐落单位代码
string BGQZLDWDM = "";
string BGHZLDWDM = "";
//坐落单位名称
string BGQZLDWMC = "";
string BGHZLDWMC = "";
//权属单位代码
string BGQQSDWDM = "";
string BGHQSDWDM = "";
//权属单位名称
string BGQQSDWMC = "";
string BGHQSDWMC = "";
//耕地等别
string BGQGDDB = "";
string BGHGDDB = "";
//权属性质
string BGQQSXZ = "";
string BGHQSXZ = "";
//耕地类型
string BGQGDLX = "";
string BGHGDLX = "";
//耕地坡度级别
string BGQGDPDJB = "";
string BGHGDPDJB = "";
//城镇村属性码
string BGQCZCSXM = "";
string BGHCZCSXM = "";
string B_BGQCZCSXM = "";
//图斑细化代码
string BGQTBXHDM = "";
string BGHTBXHDM = "";
//种植属性代码
string BGQZZSXDM = "";
string BGHZZSXDM = "";
//描述说明
string BGQMSSM = "";
string BGHMSSM = "";
//地类编码
string BGQDLBM = "";
string BGHDLBM = "";
string sqlTemp = @"Insert into BGYLB
(BGQTBBSM,BGQTBBH,BGQZLDWDM,BGQZLDWMC,BGQQSDWDM ,BGQQSDWMC ,BGQQSXZ ,BGQDLBM ,BGQGDLX ,BGQGDPDJB ,BGQCZCSXM ,BGQTBXHDM ,BGQZZSXDM ,BGQMSSM ,BGQGDDB ,BGHTBBSM ,BGHTBBH ,BGHZLDWDM ,BGHZLDWMC ,BGHQSDWDM ,BGHQSDWMC ,BGHQSXZ ,BGHDLBM ,BGHGDLX ,BGHGDPDJB ,BGHCZCSXM ,BGHTBXHDM ,BGHZZSXDM ,BGHMSSM ,BGHGDDB ,BGMJ ,XZQTZLX ) values
('{0}','{1}','{2}',
'{3}','{4}','{5}',
'{6}','{7}','{8}',
'{9}','{10}','{11}',
'{12}','{13}','{14}',
'{15}','{16}','{17}',
'{18}','{19}','{20}',
'{21}','{22}','{23}',
'{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}') ";
//图斑标识码
string BGQTBBSM = "";
string BGHTBBSM = "";
//图斑变更面积
double BGQTBDLMJ = 0.00;
double BGHTBDLMJ = 0.00;
//变更面积等于变更前图斑地类面积与变更后图斑地类面积中的较小值
double BGMJ = 0.00;
double B_MJ = 0.00;
string BGQKCDLBM = "";
string BGHKCDLBM = "";
//扣除面积
double BGQKCMJ = 0.00;
double BGHKCMJ = 0.00;
//扣除系数
double BGQKCXS = 0.00;
double BGHKCXS = 0.00;
double KCXS = 0.00;
#endregion
List<string> lstSql = new List<string>();
lstSql.Clear();
string sSQLTemp = "";
List<string> JSYD = new List<string>() { "05H1", "0508", "0601", "0602", "0603", "0701", "0702", "08H1", "08H2", "0809", "0810", "09", "1001", "1002", "1003", "1004", "1005", "1007", "1008", "1009", "1109", "1201" };
List<string> JSYD_1 = new List<string>() { "1001", "1002", "1003", "1007", "1008", "1009", "1109" };
DataTable czcsxm = rdbHelper.ExecuteDatatable("CZCSXM", $@"select BGQTBBSM,BGHTBBSM,BGQCZCSXM,ISInterSect,BGMJ,case when ISInterSect='0' then (select round(bgmj-sum(mj),2) from GXGC_CZC20X where BGQTBBSM=a.BGQTBBSM and BGHTBBSM=a.BGHTBBSM and ISInterSect='1' and BGMJ=a.BGMJ) else round(sum(mj),2) end mj from GXGC_CZC20X a group by BGQTBBSM,BGHTBBSM,BGQCZCSXM,ISInterSect,BGMJ", true);
foreach (DataRow dr in dt.Rows)
{
i++;
#region 参数
bgxw = dr["BGXW"].ToString().Trim();
//行政区调整类型
XZQTZLX = dr["XZQTZLX"].ToString().Trim();
//图斑编号
BGQTBBH = dr["BGQTBBH"].ToString().Trim();
BGHTBBH = dr["BGHTBBH"].ToString().Trim();
//坐落单位代码
BGQZLDWDM = dr["BGQZLDWDM"].ToString().Trim();
BGHZLDWDM = dr["BGHZLDWDM"].ToString().Trim();
//坐落单位名称
BGQZLDWMC = dr["BGQZLDWMC"].ToString().Trim();
BGHZLDWMC = dr["BGHZLDWMC"].ToString().Trim();
//权属单位代码
BGQQSDWDM = dr["BGQQSDWDM"].ToString().Trim();
BGHQSDWDM = dr["BGHQSDWDM"].ToString().Trim();
//权属单位名称
BGQQSDWMC = dr["BGQQSDWMC"].ToString().Trim();
BGHQSDWMC = dr["BGHQSDWMC"].ToString().Trim();
//耕地等别
BGQGDDB = dr["BGQGDDB"].ToString().Trim();
BGHGDDB = dr["BGHGDDB"].ToString().Trim();
//权属性质
//变更前权属性质和变更后权属性质 填写 国有 或 集体 2022.01.14
BGQQSXZ = dr["BGQQSXZ"].ToString().Trim();
BGHQSXZ = dr["BGHQSXZ"].ToString().Trim();
//耕地类型
BGQGDLX = dr["BGQGDLX"].ToString().Trim();
BGHGDLX = dr["BGHGDLX"].ToString().Trim();
//耕地坡度级别
BGQGDPDJB = dr["BGQGDPDJB"].ToString().Trim();
BGHGDPDJB = dr["BGHGDPDJB"].ToString().Trim();
//城镇村属性码
BGQCZCSXM = dr["BGQCZCSXM"].ToString().Trim();
//B_BGQCZCSXM = dr["B_BGQCZCSXM"].ToString().Trim();
BGHCZCSXM = dr["BGHCZCSXM"].ToString().Trim();
//图斑细化代码
BGQTBXHDM = dr["BGQTBXHDM"].ToString().Trim();
BGHTBXHDM = dr["BGHTBXHDM"].ToString().Trim();
//种植属性代码
BGQZZSXDM = dr["BGQZZSXDM"].ToString().Trim();
BGHZZSXDM = dr["BGHZZSXDM"].ToString().Trim();
//描述说明
BGQMSSM = dr["BGQMSSM"].ToString().Trim();
BGHMSSM = dr["BGHMSSM"].ToString().Trim();
//地类编码
BGQDLBM = dr["BGQDLBM"].ToString().Trim();
BGHDLBM = dr["BGHDLBM"].ToString().Trim();
//扣除系数
BGQKCXS = dr["BGQKCXS"].ToDouble().ToDouble(4);
BGHKCXS = dr["BGHKCXS"].ToDouble().ToDouble(4);
KCXS = BGHKCXS == 0 ? BGQKCXS : BGHKCXS;
if ((BGQGDDB == "0" || BGQGDDB == "") && (BGHGDDB == "0" || BGHGDDB == ""))
{
BGHGDDB = BGQGDDB;
}
#endregion
//图斑标识码
BGQTBBSM = dr["BGQTBBSM"].ToString().Trim();
BGHTBBSM = dr["BGHTBBSM"].ToString().Trim();
if (BGQTBBSM == "220582211000000422" && BGHTBBSM == "220582211099867781")
{
}
//图斑变更面积
double bgqmj = (dr["TBBGMJ"].ToDouble() - dr["BGQKCMJ"].ToDouble()).ToDouble(2);
double bghmj = (dr["TBBGMJ"].ToDouble() - dr["BGHKCMJ"].ToDouble()).ToDouble(2);
BGQTBDLMJ = bgqmj;
BGHTBDLMJ = bghmj;
//变更面积等于变更前图斑地类面积与变更后图斑地类面积中的较小值
BGMJ = BGQTBDLMJ > BGHTBDLMJ ? BGHTBDLMJ : BGQTBDLMJ;
//B_MJ = dr["B_MJ"].ToDouble();
if (BGMJ == 0)
continue;
//若行政区调整类型未“0”变更行为为“图形变化”,且坐落单位代码、 (新增 权属单位代码、耕地等别)权属性质、耕地类型、耕地坡度级别、
//城镇村属性码、图斑细化代码、种植属性代码、描述说明、地类编码属性字段均无
//变化,该变更要素不生成变更一览表条目
#region 2022.01.12
//1.村庄范围外标注城镇村属性码的图斑变更 BGQCZCSXM=203 BGHCZCSXM=空
//2.新增村庄用地范围
//(1)未标注城镇村属性码 BGQCZCSXM=空 BGHCZCSXM=203
//(2)标注城镇村属性码 BGQCZCSXM=203 BGHCZCSXM=203
//3.村庄变更为城市 BGQCZCSXM=空 BGHCZCSXM=201
var MJ = 0.00;
#region 变更前城镇村属性码
if ((BGQCZCSXM == "204" || BGQCZCSXM == "205") && !JSYD.Contains(BGQDLBM.Length > 4 ? BGQDLBM.Substring(0, 4) : BGQDLBM))
{
BGQCZCSXM = "";
}
if (JSYD_1.Contains(BGQDLBM))
{
BGQCZCSXM = "";
}
if (JSYD_1.Contains(BGHDLBM) || (BGHCZCSXM == "204" || BGHCZCSXM == "205") && !JSYD.Contains(BGHDLBM.Length > 4 ? BGHDLBM.Substring(0, 4) : BGHDLBM))
{
BGHCZCSXM = "";
}
#endregion
var bgmj_bhxxb = dr["TBBGMJ"].ToDouble();
if (BGQTBBSM == "220521211000062666" && BGHTBBSM == "220521211000062666")
{
}
//DataTable czcsxm = rdbHelper.ExecuteDatatable("CZCSXM", $@"select BGQTBBSM, BGHTBBSM, BGQCZCSXM, ISInterSect,case WHEN ISInterSect='0' THEN ABS(BGMJ-IFNULL((select case when SUM(MJ)>ROUND(BGMJ,4) then BGMJ ELSE SUM(MJ) END MJ from GXGC_CZC20X WHERE BGQTBBSM = '{BGQTBBSM}' and BGHTBBSM = '{BGHTBBSM}' AND ISInterSect='1' and BGMJ='{bgmj_bhxxb}' GROUP BY BGQTBBSM, BGHTBBSM, BGQCZCSXM, ISInterSect),0)) ELSE MJ END MJ from (select BGQTBBSM, BGHTBBSM, BGQCZCSXM, ISInterSect, case when SUM(MJ)>ROUND(BGMJ,4) then BGMJ ELSE SUM(MJ) END MJ,BGMJ from GXGC_CZC20X WHERE BGQTBBSM = '{BGQTBBSM}' and BGHTBBSM = '{BGHTBBSM}' and BGMJ='{bgmj_bhxxb}' GROUP BY BGQTBBSM, BGHTBBSM, BGQCZCSXM, ISInterSect,BGMJ)a ", true);
DataRow[] drs = czcsxm.Select($"BGQTBBSM='{BGQTBBSM}' and BGHTBBSM='{BGHTBBSM}' and BGMJ='{bgmj_bhxxb}'");
if (czcsxm != null && drs.Length > 0)
{
foreach (DataRow item in drs)
{
B_MJ = item["MJ"].ToDouble(2);
if ((BGQCZCSXM == "204" || BGQCZCSXM == "205") && JSYD.Contains(BGQDLBM.Length > 4 ? BGQDLBM.Substring(0, 4) : BGQDLBM))
{
}
else
{
BGQCZCSXM = item["BGQCZCSXM"].ToString();
if (XZQTZLX == "1" && dr["ONLYZLBG"].ToTrim() == "1")
{
BGHCZCSXM = BGQCZCSXM;
}
}
if (bgxw == "2" && XZQTZLX == "0" && BGQZLDWDM == BGHZLDWDM && BGQZLDWMC == BGHZLDWMC && BGQQSDWDM == BGHQSDWDM && BGQQSDWMC == BGHQSDWMC && BGQQSXZ == BGHQSXZ && BGQGDLX == BGHGDLX && BGQGDPDJB == BGHGDPDJB && BGQCZCSXM == BGHCZCSXM && BGQTBXHDM == BGHTBXHDM && BGQZZSXDM == BGHZZSXDM && BGQMSSM == BGHMSSM && BGQDLBM == BGHDLBM && BGQGDDB == BGHGDDB && BGQKCXS == BGHKCXS)
{
continue;
}//扣除面积
BGQKCMJ = 0.00;
BGHKCMJ = 0.00;
BGQKCMJ = (B_MJ * BGQKCXS).ToDecimal(2).ToDouble();
BGHKCMJ = (B_MJ * BGHKCXS).ToDecimal(2).ToDouble();
BGQTBDLMJ = B_MJ - BGQKCMJ;
BGHTBDLMJ = B_MJ - BGHKCMJ;
BGMJ = BGQTBDLMJ > BGHTBDLMJ ? BGHTBDLMJ : BGQTBDLMJ;
if (!JSYD.Contains(BGHDLBM.Length > 4 ? BGHDLBM.Substring(0, 4) : BGHDLBM) && (BGHCZCSXM == "204" || BGHCZCSXM == "205"))
{
BGHCZCSXM = string.Empty;
}
MJ = BGMJ;
if (MJ.ToString("f2").ToDouble() > 0)//面积大于0的 添加一览表
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, MJ.ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
#region 第二种情况
//扣除面积
BGQKCDLBM = dr["BGQKCDLBM"].ToString().Trim() == "" ? BGQDLBM : dr["BGQKCDLBM"].ToString().Trim();
BGHKCDLBM = dr["BGHKCDLBM"].ToString().Trim() == "" ? BGHDLBM : dr["BGHKCDLBM"].ToString().Trim();
//扣除面积
BGQKCMJ = 0.00;
BGHKCMJ = 0.00;
if (dr["BGQKCMJ"].ToString().Trim() != "")
BGQKCMJ = (B_MJ * BGQKCXS).ToDecimal(2).ToDouble();
if (dr["BGHKCMJ"].ToString().Trim() != "")
BGHKCMJ = (B_MJ * BGHKCXS).ToDecimal(2).ToDouble();
//2.若变更前扣除面积不等于变更后扣除面积,将产生如下的变更一览表条目
if (BGQKCMJ > BGHKCMJ)
{
if (BGQKCDLBM == "1203")
{
BGMJ = BGQKCMJ.ToDouble(2) - BGHKCMJ.ToDouble(2);
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQKCDLBM, "", "", BGQCZCSXM, "", "", BGQMSSM, "", BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, BGMJ.ToString("f2"), XZQTZLX);
if (BGMJ.ToString("f2") != "0.00")
{
lstSql.Add(sSQLTemp);
}
}
else
{
BGMJ = BGQKCMJ.ToDouble(2) - BGHKCMJ.ToDouble(2);
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, BGMJ.ToString("f2"), XZQTZLX);
if (BGMJ.ToString("f2") != "0.00")
{
lstSql.Add(sSQLTemp);
}
}
}
else if (BGHKCMJ > BGQKCMJ)
{
//若变更后扣除面积>变更前扣除面积
if (BGHKCDLBM == "1203")
{
BGMJ = BGHKCMJ.ToDouble(2) - BGQKCMJ.ToDouble(2);
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, "", "", BGHCZCSXM, "", "", BGHMSSM, "", BGMJ.ToString("f2"), XZQTZLX);
if (BGMJ.ToString("f2") != "0.00")
{
lstSql.Add(sSQLTemp);
}
}
else
{
BGMJ = BGHKCMJ.ToDouble(2) - BGQKCMJ.ToDouble(2);
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, BGMJ.ToString("f2"), XZQTZLX);
if (BGMJ.ToString("f2") != "0.00")
{
lstSql.Add(sSQLTemp);
}
}
}
#endregion
#region 第三种情况
//3.若坐落单位代码、权属性质、城镇村属性码、描述说明属性字段有任意一个或多个发生变化,
//且变更前后扣除地类面积均不为 0
if (BGQKCMJ != 0 && BGHKCMJ != 0)
{
if (BGQZLDWDM != BGHZLDWDM || BGQZLDWMC != BGHZLDWMC || BGQQSDWDM != BGHQSDWDM || BGQQSDWMC != BGHQSDWMC || BGQQSXZ != BGHQSXZ || BGQCZCSXM != BGHCZCSXM || BGQMSSM != BGHMSSM)
{
BGMJ = BGQKCMJ >= BGHKCMJ ? BGHKCMJ : BGQKCMJ;
#region 处理面积
if (BGQKCDLBM == "1203" && BGHKCDLBM != "1203")
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, "", "", BGQCZCSXM, "", "", BGQMSSM, "", BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, BGMJ.ToString("f2"), XZQTZLX);
if (BGMJ.ToString("f2") != "0.00")
{
lstSql.Add(sSQLTemp);
}
}
else if (BGQKCDLBM != "1203" && BGHKCDLBM == "1203")
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, "", "", BGHCZCSXM, "", "", BGHMSSM, "", BGMJ.ToString("f2"), XZQTZLX);
if (BGMJ.ToString("f2") != "0.00")
{
lstSql.Add(sSQLTemp);
}
}
else if (BGQKCDLBM == "1203" && BGHKCDLBM == "1203")
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQKCDLBM, "", "", BGQCZCSXM, "", "", BGQMSSM, "", BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, "", "", BGHCZCSXM, "", "", BGHMSSM, "", BGMJ.ToString("f2"), XZQTZLX);
if (BGMJ.ToString("f2") != "0.00")
{
lstSql.Add(sSQLTemp);
}
}
else
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, BGMJ.ToString("f2"), XZQTZLX);
if (BGMJ.ToString("f2") != "0.00")
{
lstSql.Add(sSQLTemp);
}
}
#endregion
}
}
#endregion
}
continue;
}
else
{
if (dr["ONLYZLBG"].ToTrim() != "1" && (BGQCZCSXM == "203" || BGQCZCSXM == "203A") && !JSYD.Contains(BGQDLBM.Length > 4 ? BGQDLBM.Substring(0, 4) : BGQDLBM))
{
BGQCZCSXM = "";
}
if (XZQTZLX == "2" && (BGQCZCSXM == "203" || BGQCZCSXM == "203A") && !JSYD.Contains(BGQDLBM.Length > 4 ? BGQDLBM.Substring(0, 4) : BGQDLBM))
{
BGQCZCSXM = "";
}
}
#endregion
//2020.06.22 变更一览表提取规则
//若变更行为为“图形变化”,且 坐落单位代码、权属性质、耕地类型、耕地坡度级别、城镇村属性码、图斑细化代码、种植属性代码、描述说明、地类编码属性字段均无变化,该变更要素不生成变更一览表条目。
if (bgxw == "2" && XZQTZLX == "0"
&& BGQZLDWDM == BGHZLDWDM
&& BGQZLDWMC == BGHZLDWMC
&& BGQQSDWDM == BGHQSDWDM
&& BGQQSDWMC == BGHQSDWMC
&& BGQQSXZ == BGHQSXZ
&& BGQGDLX == BGHGDLX
&& BGQGDPDJB == BGHGDPDJB
&& BGQCZCSXM == BGHCZCSXM
&& BGQTBXHDM == BGHTBXHDM
&& BGQZZSXDM == BGHZZSXDM
&& BGQMSSM == BGHMSSM
&& BGQDLBM == BGHDLBM
&& BGQKCXS == BGHKCXS
&& BGQGDDB == BGHGDDB)
{
continue;
}
#region 第一种情况
//BGQCZCSXM = "";
//1.其它变更要素至少产生一条变更一览表条目,其变更前后属性分别来自于更新过程层对应字段
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, BGMJ.ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
#endregion
#region 第二种情况
//扣除面积
BGQKCDLBM = dr["BGQKCDLBM"].ToString().Trim() == "" ? BGQDLBM : dr["BGQKCDLBM"].ToString().Trim();
BGHKCDLBM = dr["BGHKCDLBM"].ToString().Trim() == "" ? BGHDLBM : dr["BGHKCDLBM"].ToString().Trim();
//扣除面积
BGQKCMJ = 0.00;
BGHKCMJ = 0.00;
if (dr["BGQKCMJ"].ToString().Trim() != "")
BGQKCMJ = dr["BGQKCMJ"].ToString().Trim().ToDouble();
if (dr["BGHKCMJ"].ToString().Trim() != "")
BGHKCMJ = dr["BGHKCMJ"].ToString().Trim().ToDouble();
//2.若变更前扣除面积不等于变更后扣除面积,将产生如下的变更一览表条目
if (BGQKCMJ > BGHKCMJ)
{
//若变更前扣除面积>变更后扣除面积
if (BGQKCDLBM == "1203")
{
//如果是田坎,变更前 BGQGDDB、BGQGDLX、BGQGDPDJB、BGQTBXHDM、BGQZZSXDM 属性不继承
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQKCDLBM, "", "", BGQCZCSXM, "", "", BGQMSSM, "", BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, (BGQKCMJ - BGHKCMJ).ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
else
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, (BGQKCMJ - BGHKCMJ).ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
}
else if (BGHKCMJ > BGQKCMJ)
{
//若变更后扣除面积>变更前扣除面积
if (BGHKCDLBM == "1203")
{
//如果是田坎,变更后 BGHGDDB、BGHGDLX、BGHGDPDJB、BGHTBXHDM、BGHZZSXDM 属性不继承
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, "", "", BGHCZCSXM, "", "", BGHMSSM, "", (BGHKCMJ - BGQKCMJ).ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
else
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, (BGQKCMJ - BGHKCMJ).ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
}
#endregion
#region 第三种情况
//3.若坐落单位代码、权属性质、城镇村属性码、描述说明属性字段有任意一个或多个发生变化,
//且变更前后扣除地类面积均不为 0
if (BGQKCMJ != 0 && BGHKCMJ != 0)
{
if (BGQZLDWDM != BGHZLDWDM || BGQZLDWMC != BGHZLDWMC || BGQQSDWDM != BGHQSDWDM || BGQQSDWMC != BGHQSDWMC || BGQQSXZ != BGHQSXZ || BGQCZCSXM != BGHCZCSXM || BGQMSSM != BGHMSSM)
{
BGMJ = BGQKCMJ >= BGHKCMJ ? BGHKCMJ : BGQKCMJ;
#region 处理面积
if (BGQKCDLBM == "1203" && BGHKCDLBM != "1203")
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, "", "", BGQCZCSXM, "", "", BGQMSSM, "", BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, BGMJ.ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
else if (BGQKCDLBM != "1203" && BGHKCDLBM == "1203")
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, "", "", BGHCZCSXM, "", "", BGHMSSM, "", BGMJ.ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
else if (BGQKCDLBM == "1203" && BGHKCDLBM == "1203")
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQKCDLBM, "", "", BGQCZCSXM, "", "", BGQMSSM, "", BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, "", "", BGHCZCSXM, "", "", BGHMSSM, "", BGMJ.ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
else
{
sSQLTemp = string.Format(sqlTemp, BGQTBBSM, BGQTBBH, BGQZLDWDM, BGQZLDWMC, BGQQSDWDM, BGQQSDWMC, BGQQSXZ, BGQDLBM, BGQGDLX, BGQGDPDJB, BGQCZCSXM, BGQTBXHDM, BGQZZSXDM, BGQMSSM, BGQGDDB, BGHTBBSM, BGHTBBH, BGHZLDWDM, BGHZLDWMC, BGHQSDWDM, BGHQSDWMC, BGHQSXZ, BGHKCDLBM, BGHGDLX, BGHGDPDJB, BGHCZCSXM, BGHTBXHDM, BGHZZSXDM, BGHMSSM, BGHGDDB, BGMJ.ToString("f2"), XZQTZLX);
lstSql.Add(sSQLTemp);
}
#endregion
}
}
#endregion
}
InsertSQLiteData(dbPath, lstSql);
lstSql.Clear();
Console.WriteLine("正在生成统计基础表,请稍后...");
BaseTableHelper.GetTheBaseSumTable(pParm);
}
}
catch (Exception ex)
{
LogAPI.Debug("生成失败:" + ex.Message);
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
public void InsertSQLiteData(string dbPath, List<string> sqlList)
{
try
{
using (SQLiteConnection conn = new SQLiteConnection("Data Source=" + dbPath))
{
conn.Open();
using (SQLiteTransaction pTrans = conn.BeginTransaction())
{
using (SQLiteCommand cmd = new SQLiteCommand(conn))
{
for (int i = 0; i < sqlList.Count(); i++)
{
cmd.CommandText = sqlList[i];
cmd.ExecuteNonQuery();
}
pTrans.Commit();
}
}
conn.Close();
}
}
catch (Exception ex)
{
LogAPI.Debug("批量插入SQLite数据(地址:" + dbPath + ") 执行失败,异常原因: " + ex + " ; ");
return;
}
}
/// <summary>
/// 多线程插入数据到db中
/// </summary>
/// <param name="listSQL"></param>
/// <param name="dbPath"></param>
private void InsertDB(List<string> listSQL, string dbPath)
{
try
{
using (BlockingCollection<string> blockingCollection = new BlockingCollection<string>())
{
listSQL.ForEach(x => blockingCollection.Add(x));
blockingCollection.CompleteAdding();
int taskNum = 5;
Task[] tasks = new Task[taskNum];
for (int i = 0; i < taskNum; i++)
{
tasks[i] = Task.Factory.StartNew(() =>
{
ExcuteThead(blockingCollection, dbPath);
});
}
Task.WaitAll(tasks);
for (int i = 0; i < taskNum; i++)
{
tasks[i].Dispose();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
private void ExcuteThead(BlockingCollection<string> blockingCollection, string dbPath)
{
IRDBHelper rdbHelper = null;
string sqlDe = string.Empty;
try
{
rdbHelper = RDBFactory.CreateDbHelper(string.Format("Data Source={0};Initial Catalog=sqlite;Integrated Security=True;Max Pool Size=10;", dbPath), DatabaseType.SQLite);
if (rdbHelper == null)
{
throw new Exception("执行成果接收时打开数据库连接字符串失败!");
}
rdbHelper.BeginTransaction();
foreach (string sql in blockingCollection.GetConsumingEnumerable())
{
sqlDe = sql;
rdbHelper.ExecuteNonQueryWithException(sql, CommandType.Text);
}
rdbHelper.Commit();
}
catch (Exception ex)
{
if (rdbHelper != null)
{
rdbHelper.Rollback();
}
LogAPI.Debug(sqlDe);
LogAPI.Debug(ex);
throw ex;
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
#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
#region GetFeatures
private ShapeInfo m_FeatureInfo;
public List<ShapeInfo> GetFeatures(bool IsAdjustment = true)
{
List<ShapeInfo> result = new List<ShapeInfo>();
//将多环图形打散
List<IGeometry> geoList = FeatureAPI.DissolveGeometryByRing(m_FeatureInfo.Shape);
foreach (IGeometry item in geoList)
{
result.Add(new ShapeInfo(item));
//Marshal.ReleaseComObject(item);
}
if (m_FeatureInfo.Area == 0)
{
m_FeatureInfo.CalculationArea();
}
if (result.Count == 1)
{
result[0].SetArea(m_FeatureInfo.Area);
}
else if (result.Count > 1 && IsAdjustment)
{
AreaHandle.AreaAdjustment(result, m_FeatureInfo.Area);
}
return result;
}
#endregion
public class ShapeInfo
{
private string m_BGXW;
private string m_BGQCZCSXM;
private string m_ISInterSect;
private string m_TBBSM;
private string m_TBBH;
private string m_ZLDWDM;
private double m_Area;
private IGeometry m_Shape;
private IFeature m_AttrSourceFeature;
public int ID { get; set; }
public IFeature AttrSourceFeature { get { return m_AttrSourceFeature; } }
/// <summary>
/// 变更行为
/// </summary>
public string BGXW { get { return m_BGXW; } }
/// <summary>
/// 变更行为
/// </summary>
public string BGQCZCSXM { get { return m_BGQCZCSXM; } }
public string ISInterSect { get { return m_ISInterSect; } }
/// <summary>
/// 图斑标识码
/// </summary>
public string TBBSM { get { return m_TBBSM; } }
/// <summary>
/// 图斑编号
/// </summary>
public string TBBH { get { return m_TBBH; } }
/// <summary>
/// 图斑编号
/// </summary>
public string ZLDWDM { get { return m_ZLDWDM; } }
/// <summary>
/// 图斑面积
/// </summary>
public double Area { get { return Math.Round(m_Area, 2); } }
public IGeometry Shape { get { return m_Shape; } }
public ShapeInfo() { }
public ShapeInfo(IGeometry pGeo)
{
m_Shape = pGeo;
}
public void SetAttrSourceFeature(IFeature pFeature)
{
m_AttrSourceFeature = pFeature;
}
public void SetShape(IGeometry pGeo)
{
m_Shape = pGeo;
}
public void CalculationArea()
{
m_Area = GetEllipseArea(m_Shape as IPolygon);
}
public void SetArea(double pArea)
{
m_Area = pArea;
}
public void SetBGXW(string pBGXW)
{
m_BGXW = pBGXW;
}
public void SetBGQCZCSXM(string pBGQCZCSXM)
{
m_BGQCZCSXM = pBGQCZCSXM;
}
public void SetISInterSect(string isInterSect)
{
m_ISInterSect = isInterSect;
}
public void SetTBBSM(string pTBBSM)
{
m_TBBSM = pTBBSM;
}
public void SetTBBH(string pTBBH)
{
m_TBBH = pTBBH;
}
public void SetZLDWDM(string pZLDWDM)
{
m_ZLDWDM = pZLDWDM;
}
private 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 class AreaHandle
{
/// <summary>
/// 面积平差
/// </summary>
/// <param name="shpList">需要平差的对象集合</param>
/// <param name="pKZMJ">控制面积</param>
public static void AreaAdjustment(List<ShapeInfo> shpList, double pKZMJ)
{
//如果面积=0,计算椭球面积
shpList.ForEach(f =>
{
if (f.Area == 0)
f.CalculationArea();
});
shpList = shpList.OrderByDescending(o => o.Area).ToList();
double mjc = Math.Round(shpList.Sum(s => s.Area) - pKZMJ, 2);
//平差
while (Math.Round(mjc, 2) != 0)
{
int tpsm = (int)(Math.Abs(Math.Round(mjc, 2)) / 0.01);
int e = tpsm / shpList.Count;
int f = tpsm % shpList.Count;
if (f != 0)
{
double tpmj = (e + 1) * 0.01;
for (int i = 0; i < f; i++)
{
if (mjc < 0)
shpList[i].SetArea(shpList[i].Area + tpmj);
else
shpList[i].SetArea(shpList[i].Area - tpmj);
}
}
if (e != 0)
{
double tpmj = e * 0.01;
for (int i = f; i < shpList.Count; i++)
{
if (mjc < 0)
shpList[i].SetArea(shpList[i].Area + tpmj);
else
shpList[i].SetArea(shpList[i].Area - tpmj);
}
}
mjc = Math.Round(shpList.Sum(s => s.Area), 2) - pKZMJ;
}
}
}
public class CalcAreaParm
{
public string StrGxgcLayer { get; set; }
public string StrUnionLayer { get; set; }
public int StartIndex { get; set; }
public List<int> OidList { get; set; }
public string InsertSQL { get; set; }
public List<string> ListSQL { get; set; }
public List<PCModel> PcList { get; set; }
}
public class PCModel
{
public int FID { get; set; }
public int FID_Gxgc { get; set; }
public string BGQTBBSM { get; set; }
public string BGHTBBSM { get; set; }
public string BGQCZCSXM { get; set; }
public double MJ { get; set; }
public double ZMJ { get; set; }
public double ZGeoMJ { get; set; }
public string IsIntersect { get; set; }
}
}
public class ZLHZ_Param
{
public IFeatureLayer GXGCTBLayer { get; set; }
public IFeatureLayer JCCZCLayer { get; set; }
}
}