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.
1677 lines
83 KiB
1677 lines
83 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.ExtensionMethod; |
|
//using KGIS.Framework.AE.GPHelper; |
|
using KGIS.Framework.DBOperator; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Platform.Helper; |
|
using KGIS.Framework.ThreadManager; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Utils.Utility; |
|
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 IDGForNDBG |
|
{ |
|
public class CZCDYDHelper : BaseIDG |
|
{ |
|
//private IFeatureLayer _DLTBFc = null; |
|
public string IDataChangeName { get => "CZCDYDHelper"; } |
|
private string TempGDBPath = string.Empty; |
|
private string TempDBPath = string.Empty; |
|
#region ExecuteDataChange |
|
public void Execute(IDGParameter3 pParm) |
|
{ |
|
try |
|
{ |
|
|
|
ThreadManager.Instance.QueueUserWorkItem(new System.Threading.WaitCallback(ExtractExe), pParm); |
|
|
|
//IFeatureClass _CZCFc = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("城镇村等用地").FeatureClass; |
|
//Implement(_CZCFc, true, false); |
|
//ExtractExe(pParm, bgParm); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
#endregion |
|
|
|
public void OpenDB(IDGParameter3 parm, ref CZC_Param pCzcParm) |
|
{ |
|
IFeatureClassAPI BgTBFcAPI = null; |
|
IFeatureClassAPI JcTBFcAPI = null; |
|
IFeatureClassAPI JcCZCFcAPI = null; |
|
IFeatureClassAPI GxTBFcAPI = null; |
|
IFeatureClassAPI GxGcCZCFcAPI = null; |
|
IFeatureClassAPI GxCZCFcAPI = null; |
|
GPParamClass paramClass = null;// new GPParamClass(); |
|
//GeoprocessorHelper gpHelper = new GeoprocessorHelper(); |
|
try |
|
{ |
|
BgWsAPI = new WorkspaceAPI(parm.BgDbPath, WorkspaceTypeEnum.GDBFile); |
|
if (BgWsAPI.CurrentWorkspace == null) |
|
{ |
|
Console.WriteLine("打开变更数据库失败!"); |
|
return; |
|
} |
|
JcWsAPI = new WorkspaceAPI(parm.JcDbPath, WorkspaceTypeEnum.GDBFile); |
|
if (JcWsAPI.CurrentWorkspace == null) |
|
{ |
|
Console.WriteLine("打开基础数据库失败!"); |
|
return; |
|
} |
|
ZlWsAPI = new WorkspaceAPI(parm.ZLDbPath, WorkspaceTypeEnum.GDBFile); |
|
if (ZlWsAPI.CurrentWorkspace == null) |
|
{ |
|
Console.WriteLine("打开增量数据库失败!"); |
|
return; |
|
} |
|
NmWsAPI = new WorkspaceAPI(parm.NmDbPath, WorkspaceTypeEnum.GDBFile); |
|
|
|
BgTBFcAPI = BgWsAPI.OpenFeatureClass("DLTBBG"); |
|
JcTBFcAPI = JcWsAPI.OpenFeatureClass("DLTB"); |
|
JcCZCFcAPI = JcWsAPI.OpenFeatureClass("CZCDYD"); |
|
GxTBFcAPI = ZlWsAPI.OpenFeatureClass("DLTBGX"); |
|
GxCZCFcAPI = ZlWsAPI.OpenFeatureClass("CZCDYDGX"); |
|
GxGcCZCFcAPI = ZlWsAPI.OpenFeatureClass("CZCDYDGXGC"); |
|
|
|
IFeatureLayer pJCTBLayer = null; |
|
if (JcTBFcAPI.FeatureClass != null) |
|
{ |
|
//paramClass = new GPParamClass(); |
|
//paramClass.FirstFeatureClass = JcTBFcAPI.FeatureClass; |
|
//paramClass.OutFeatureClassPath = "DLTB"; |
|
//paramClass.IsGetOutPutFeature = true; |
|
//gpHelper.MakeFeatureLayer(paramClass, ref pJCTBLayer); |
|
IFeatureLayer pFeatureLayer = new FeatureLayerClass(); |
|
pFeatureLayer.FeatureClass = JcTBFcAPI.FeatureClass; |
|
pFeatureLayer.Name = JcTBFcAPI.FeatureClass.AliasName; |
|
pCzcParm.JCTBLayer = pFeatureLayer; |
|
} |
|
IFeatureLayer pJCCZCLayer = null; |
|
if (JcCZCFcAPI.FeatureClass != null) |
|
{ |
|
//paramClass = new GPParamClass(); |
|
//paramClass.FirstFeatureClass = JcCZCFcAPI.FeatureClass; |
|
//paramClass.OutFeatureClassPath = "CZCDYD"; |
|
//paramClass.IsGetOutPutFeature = true; |
|
//gpHelper.MakeFeatureLayer(paramClass, ref pJCCZCLayer); |
|
|
|
IFeatureLayer pFeatureLayer = new FeatureLayerClass(); |
|
pFeatureLayer.FeatureClass = JcCZCFcAPI.FeatureClass; |
|
pFeatureLayer.Name = JcCZCFcAPI.FeatureClass.AliasName; |
|
pCzcParm.JCCZCLayer = pFeatureLayer; |
|
} |
|
IFeatureLayer pGXTBLayer = null; |
|
if (GxTBFcAPI.FeatureClass != null) |
|
{ |
|
//paramClass = new GPParamClass(); |
|
//paramClass.FirstFeatureClass = GxTBFcAPI.FeatureClass; |
|
//paramClass.OutFeatureClassPath = "DLTBGX"; |
|
//paramClass.IsGetOutPutFeature = true; |
|
//gpHelper.MakeFeatureLayer(paramClass, ref pGXTBLayer); |
|
|
|
IFeatureLayer pFeatureLayer = new FeatureLayerClass(); |
|
pFeatureLayer.FeatureClass = GxTBFcAPI.FeatureClass; |
|
pFeatureLayer.Name = GxTBFcAPI.FeatureClass.AliasName; |
|
pCzcParm.GXTBLayer = pFeatureLayer; |
|
} |
|
IFeatureLayer pGXCZCLayer = null; |
|
if (GxCZCFcAPI.FeatureClass != null) |
|
{ |
|
//paramClass = new GPParamClass(); |
|
//paramClass.FirstFeatureClass = GxCZCFcAPI.FeatureClass; |
|
//paramClass.OutFeatureClassPath = "CZCDYDGX"; |
|
//paramClass.IsGetOutPutFeature = true; |
|
//gpHelper.MakeFeatureLayer(paramClass, ref pGXCZCLayer); |
|
|
|
IFeatureLayer pFeatureLayer = new FeatureLayerClass(); |
|
pFeatureLayer.FeatureClass = GxCZCFcAPI.FeatureClass; |
|
pFeatureLayer.Name = GxCZCFcAPI.FeatureClass.AliasName; |
|
pCzcParm.GXCZCLayer = pFeatureLayer; |
|
} |
|
IFeatureLayer pGXGCCZCLayer = null; |
|
if (GxGcCZCFcAPI.FeatureClass != null) |
|
{ |
|
//paramClass = new GPParamClass(); |
|
//paramClass.FirstFeatureClass = GxGcCZCFcAPI.FeatureClass; |
|
//paramClass.OutFeatureClassPath = "CZCDYDGXGC"; |
|
//paramClass.IsGetOutPutFeature = true; |
|
//gpHelper.MakeFeatureLayer(paramClass, ref pGXGCCZCLayer); |
|
|
|
IFeatureLayer pFeatureLayer = new FeatureLayerClass(); |
|
pFeatureLayer.FeatureClass = GxGcCZCFcAPI.FeatureClass; |
|
pFeatureLayer.Name = GxGcCZCFcAPI.FeatureClass.AliasName; |
|
pCzcParm.GXGCCZCLayer = pFeatureLayer; |
|
} |
|
IFeatureLayer pBGTBLayer = null; |
|
if (BgTBFcAPI.FeatureClass != null) |
|
{ |
|
//paramClass = new GPParamClass(); |
|
//paramClass.FirstFeatureClass = BgTBFcAPI.FeatureClass; |
|
//paramClass.OutFeatureClassPath = "DLTBBG"; |
|
//paramClass.IsGetOutPutFeature = true; |
|
//gpHelper.MakeFeatureLayer(paramClass, ref pBGTBLayer); |
|
|
|
IFeatureLayer pFeatureLayer = new FeatureLayerClass(); |
|
pFeatureLayer.FeatureClass = BgTBFcAPI.FeatureClass; |
|
pFeatureLayer.Name = BgTBFcAPI.FeatureClass.AliasName; |
|
pCzcParm.BGTBLayer = pFeatureLayer; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
|
|
|
|
private void ExtractExe(object parm) |
|
{ |
|
IFeatureLayer jc_czcLayer = null; |
|
IFeatureLayer dltbgxLayer = null; |
|
IFeatureLayer dltbhrLayer = null; |
|
IFeatureLayer jcdltbLayer = null; |
|
IFeatureLayer dltbTempNMKLayer = null; |
|
IWorkspaceAPI Tempworkspace = null; |
|
IWorkspaceAPI Schemeworkspace = null; |
|
IFeatureClassAPI dltbFeatureClassAPI = null; |
|
IFeatureClassAPI czcdydFeatureClassAPI = null; |
|
IFeatureCursor pFeatureCursor = null; |
|
IFeatureCursor pInsertCursor = null; |
|
IFeatureClassAPI LSczcdydFeatureclassAPI = null; |
|
//IFeatureClassAPI pFeatureClass_4 = null; |
|
IFeatureClassAPI CZCDLTBFeatureClass = null; |
|
IWorkspaceFactory outputWorkspaceFactory = null; |
|
IWorkspaceFactory pOutWorkFactory = null; |
|
string TempfilePath = string.Empty; |
|
try |
|
{ |
|
IDGParameter3 pParm = parm as IDGParameter3; |
|
CZC_Param bgParm = new CZC_Param(); |
|
OpenDB(pParm, ref bgParm); |
|
string TempDir = CreateTempDB("CZC"); |
|
TempGDBPath = System.IO.Path.Combine(TempDir, "TempGDB.gdb"); |
|
TempDBPath = TempDir + @"\Temp" + ".sqlite"; |
|
|
|
IRDBHelper rdbHelper = null; |
|
List<DataDicTionary> qsDic = null; |
|
try |
|
{ |
|
|
|
rdbHelper = RDBFactory.CreateDbHelper(System.IO.Path.Combine(pParm.ProjDir, "BGTJ.sqlite"), DatabaseType.SQLite); |
|
DataTable dicDt = rdbHelper.ExecuteDatatable("Dic", string.Format("SELECT * from Sys_Dicdetail where OWNERDIC=1"), true); |
|
|
|
//jccjdcqLayer = Parm.JC_CJDCQLay as IFeatureLayer; |
|
qsDic = KGIS.Framework.Utils.Utility.TBToList.ToList<DataDicTionary>(dicDt);// Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM); |
|
|
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine("获取权属字典失败!" + ex.Message); |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
rdbHelper.DisConnect(); |
|
} |
|
if (qsDic == null) |
|
{ |
|
LogAPI.Debug($"权属单位代码表获取失败。"); |
|
return; |
|
} |
|
//string filePath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjDBPath(); |
|
//string schemeDBPath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetSchemeDBPath(); |
|
//ProjGDBwkspace = new WorkspaceAPI(filePath, WorkspaceTypeEnum.GDBFile); |
|
//Schemeworkspace = new WorkspaceAPI(schemeDBPath, WorkspaceTypeEnum.GDBFile); |
|
|
|
#region 临时数据 |
|
Console.WriteLine("正在提取城镇村等用地数据......"); |
|
//TempfilePath = GetTempPath();//临时数据存放路径 |
|
TempfilePath = TempGDBPath; |
|
if (string.IsNullOrEmpty(TempfilePath)) |
|
{ |
|
LogAPI.Debug($"获取到城镇村等用地数据模板失败。"); |
|
return; |
|
} |
|
|
|
#region 地类图斑 |
|
IFeatureClass bgtbFc = bgParm.BGTBLayer.FeatureClass;// MapsManager.Instance.MapService.GetFeatureClassByName("DLTBBG"); |
|
dltbgxLayer = bgParm.GXTBLayer;// MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBGX"); |
|
//dltbhrLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBHR"); |
|
jcdltbLayer = bgParm.JCTBLayer;// MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑"); |
|
jc_czcLayer = bgParm.JCCZCLayer;// MapsManager.Instance.MapService.GetFeatureLayerByLayerName("城镇村等用地"); |
|
FeatureClass featureClass = jc_czcLayer.FeatureClass as FeatureClass; |
|
if (jc_czcLayer.FeatureClass.FeatureCount(null) == 0) |
|
{ |
|
Console.WriteLine("基础城镇村等用地图层未找到数据,请确认基础城镇村数据是否导入!"); |
|
return; |
|
} |
|
|
|
IFeatureLayer tempJCCZCLayer = null; |
|
//设置基础地类图斑选中 |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = jc_czcLayer; |
|
gPParamClass.SecondFeatureLayer = dltbgxLayer; |
|
//gPParamClass.Tolerance = "-0.0001655555"; |
|
//GeoprocessorHelper gpHelper = new GeoprocessorHelper(); |
|
gPParamClass.GPType = EnumGPType.SelectLayerByLocation; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.Overlap_type = "INTERSECT"; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref tempJCCZCLayer); |
|
|
|
IFeatureLayer _TempLayer = null; |
|
//选中的基础地类图斑导出至临时gdb |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer= tempJCCZCLayer; |
|
gPParamClass.OutFeatureClassPath = TempfilePath; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.FcToFc; |
|
gPParamClass.FcName = "JC_CZCDYD"; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref _TempLayer); |
|
try |
|
{ |
|
ESRI.ArcGIS.Carto.IFeatureSelection selection = jc_czcLayer as IFeatureSelection; |
|
selection.Clear(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
tempJCCZCLayer = _TempLayer; |
|
IFeatureLayer TempJCDLTB = null;// GeoDBAPI.CreateFeatureLayerInmemeory("CZC203", "城镇村203范围", (jcdltbLayer.FeatureClass as IGeoDataset).SpatialReference, jcdltbLayer.FeatureClass.ShapeType, jcdltbLayer.FeatureClass.Fields); |
|
|
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = jcdltbLayer; |
|
gPParamClass.SecondFeatureLayer = tempJCCZCLayer; |
|
gPParamClass.OutFeatureClassPath = TempfilePath + "\\" + "TempJCDLTB20X"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.Intersect; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref dltbTempNMKLayer); |
|
IWorkspace tempWs = (dltbTempNMKLayer.FeatureClass as FeatureClass).Workspace; |
|
|
|
tempWs.ExecuteSQL("Update TempJCDLTB20X set CZCSXM='201' where CZCLX='201'"); |
|
tempWs.ExecuteSQL("Update TempJCDLTB20X set CZCSXM='201A' where CZCLX='201A'"); |
|
tempWs.ExecuteSQL("Update TempJCDLTB20X set CZCSXM='202' where CZCLX='202'"); |
|
tempWs.ExecuteSQL("Update TempJCDLTB20X set CZCSXM='202A' where CZCLX='202A'"); |
|
tempWs.ExecuteSQL("Update TempJCDLTB20X set CZCSXM='203' where CZCLX='203'"); |
|
tempWs.ExecuteSQL("Update TempJCDLTB20X set CZCSXM='203A' where CZCLX='203A'"); |
|
tempWs.ExecuteSQL("Update TempJCDLTB20X set CZCSXM='204' where CZCLX='204'"); |
|
tempWs.ExecuteSQL("Update TempJCDLTB20X set CZCSXM='205' where CZCLX='205'"); |
|
|
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = dltbTempNMKLayer; |
|
gPParamClass.OutFeatureClassPath = TempfilePath; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.FcToFc; |
|
gPParamClass.FcName = "CZC203"; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref TempJCDLTB); |
|
|
|
//IFeatureClassAPI dltb20xAPI = new FeatureClassAPI(dltbTempNMKLayer.FeatureClass); |
|
//dltb20xAPI.FcToFc(TempJCDLTB.FeatureClass, null, false); |
|
|
|
IFeatureLayer msTBLayer = GeoDBAPI.CreateFeatureLayerInmemeory("MSDLTB", "灭失图斑", (bgtbFc as IGeoDataset).SpatialReference, bgtbFc.ShapeType, bgtbFc.Fields); |
|
IQueryFilter filter2 = new QueryFilterClass(); |
|
filter2.WhereClause = " XZQTZLX='2' or XZQTZLX='4'"; |
|
(msTBLayer.FeatureClass as ITable).DeleteSearchedRows(null); |
|
InsertDataToMemeoryLayer(bgtbFc, msTBLayer.FeatureClass, filter2); |
|
|
|
IFeatureLayer pjbntFeatureLayer = null; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = TempJCDLTB; |
|
gPParamClass.SecondFeatureLayer = msTBLayer; |
|
gPParamClass.OutFeatureClassPath = TempfilePath + "\\" + "TempDLTBNM"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.Erase; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref pjbntFeatureLayer); |
|
|
|
IFeatureLayer TempDLTB_MToS = null; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = pjbntFeatureLayer; |
|
gPParamClass.OutFeatureClassPath = TempfilePath + "\\" + "TempDLTBNM_MToS"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.MultipartToSinglePath; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref TempDLTB_MToS); |
|
|
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = TempDLTB_MToS; |
|
gPParamClass.SecondFeatureLayer = dltbgxLayer; |
|
gPParamClass.OutFeatureClassPath = TempfilePath + "\\" + "DLTBGXGC"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.Erase; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref dltbTempNMKLayer); |
|
|
|
|
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(dltbgxLayer.FeatureClass); |
|
fcAPI.FcToFc(dltbTempNMKLayer.FeatureClass, null, false); |
|
//fcAPI = new FeatureClassAPI(dltbhrLayer.FeatureClass); |
|
//fcAPI.FcToFc(dltbTempNMKLayer.FeatureClass, null, false); |
|
fcAPI = new FeatureClassAPI(dltbTempNMKLayer.FeatureClass); |
|
|
|
//string dbPath = $"{pParm.ProjDir}\\BGTJ.sqlite"; |
|
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + TempDBPath, DatabaseType.SQLite); |
|
|
|
|
|
ITable nmkTable = dltbTempNMKLayer.FeatureClass as ITable; |
|
IQueryFilter filter = new QueryFilterClass(); |
|
//foreach (string bsm in hcbghbsmList) |
|
//{ |
|
// filter.WhereClause = string.Format("BSM ='{0}' ", bsm); |
|
// nmkTable.DeleteSearchedRows(filter); |
|
//} |
|
|
|
ICursor nmkCur = nmkTable.Update(null, true); |
|
IRow nmkRow = null; |
|
int bsmIdx = nmkTable.FindField("BSM"); |
|
int zldwIdx = nmkTable.FindField("ZLDWDM"); |
|
int zldwmcIdx = nmkTable.FindField("ZLDWMC"); |
|
int sjnfIdx = nmkTable.FindField("SJNF");//数据年份 |
|
int num1 = 0; |
|
while ((nmkRow = nmkCur.NextRow()) != null) |
|
{ |
|
num1++; |
|
string bsm = nmkRow.Value[bsmIdx].ToTrim(); |
|
//if (zlbgList.ContainsKey(bsm)) |
|
//{ |
|
// DataRow dr = zlbgList[bsm]; |
|
// nmkRow.Value[zldwIdx] = dr["BGHZLDWDM"]; |
|
// nmkRow.Value[zldwmcIdx] = dr["BGHZLDWMC"]; |
|
//} |
|
//else |
|
//if (bhxxDic.ContainsKey(bsm)) |
|
//{ |
|
// for (int i = 0; i < nmkRow.Fields.FieldCount; i++) |
|
// { |
|
// IField field = nmkRow.Fields.Field[i]; |
|
// string bghField = "BGH" + field.Name; |
|
// DataRow dr = bhxxDic[bsm]; |
|
// if (!dr.Table.Columns.Contains(bghField)) |
|
// bghField = "BGHTB" + field.Name; |
|
// if (dr.Table.Columns.Contains(bghField)) |
|
// { |
|
// if (field.Type == esriFieldType.esriFieldTypeString) |
|
// nmkRow.Value[i] = dr[bghField]; |
|
// else if (field.Type == esriFieldType.esriFieldTypeDouble) |
|
// nmkRow.Value[i] = dr[bghField].ToDouble(); |
|
// } |
|
// } |
|
//} |
|
|
|
if (sjnfIdx != -1) |
|
{ |
|
nmkRow.Value[sjnfIdx] = "2020"; |
|
} |
|
nmkCur.UpdateRow(nmkRow); |
|
|
|
if (num1 % 1000 == 0) |
|
{ |
|
nmkCur.Flush(); |
|
} |
|
} |
|
nmkCur.Flush(); |
|
#endregion |
|
|
|
|
|
IWorkspaceFactory TempWorkspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass(); |
|
Tempworkspace = new WorkspaceAPI(TempWorkspaceFactory.OpenFromFile(TempfilePath, 0)); |
|
dltbFeatureClassAPI = Tempworkspace.OpenFeatureClass("DLTBGXGC"); |
|
#endregion |
|
|
|
czcdydFeatureClassAPI = new FeatureClassAPI(bgParm.GXCZCLayer.FeatureClass);// Schemeworkspace.OpenFeatureClass("CZCDYDGX"); |
|
if (dltbFeatureClassAPI.FeatureClass.FeatureCount(null) <= 0) |
|
{ |
|
return; |
|
} |
|
if (Tempworkspace.ExistFeatureClass("LSczcdyd")) |
|
{ |
|
Tempworkspace.DeleteFeatureClass("LSczcdyd"); |
|
} |
|
// 创建临时层 |
|
LSczcdydFeatureclassAPI = Tempworkspace.CreateFeatureClass("LSczcdyd", (czcdydFeatureClassAPI.FeatureClass as IGeoDataset).SpatialReference, null); |
|
LSczcdydFeatureclassAPI.AddField("CZCLX", esriFieldType.esriFieldTypeString, "CZCLX"); |
|
LSczcdydFeatureclassAPI.AddField("CZCDM", esriFieldType.esriFieldTypeString, "CZCDM"); |
|
LSczcdydFeatureclassAPI.AddField("CZCMC", esriFieldType.esriFieldTypeString, "CZCMC"); |
|
LSczcdydFeatureclassAPI.AddField("ZLDWDM", esriFieldType.esriFieldTypeString, "ZLDWDM"); |
|
LSczcdydFeatureclassAPI.AddField("ZLDWMC", esriFieldType.esriFieldTypeString, "ZLDWMC"); |
|
if (czcdydFeatureClassAPI == null || czcdydFeatureClassAPI.FeatureClass == null) |
|
{ |
|
Console.WriteLine("当前工程数据库未找到城镇村等用地(CZCDYDGX)图层!"); |
|
return; |
|
} |
|
int czcsxmIndex = dltbFeatureClassAPI.FeatureClass.Fields.FindField("CZCSXM"); |
|
int czclxIndex = czcdydFeatureClassAPI.FeatureClass.Fields.FindField("CZCLX"); |
|
int LSczclxIndex = LSczcdydFeatureclassAPI.FeatureClass.Fields.FindField("CZCLX"); |
|
IQueryFilter queryFilter = new QueryFilter() |
|
{ |
|
WhereClause = "CZCSXM IN('201','202','203','204','205','201A','202A','203A')" |
|
}; |
|
int count = dltbFeatureClassAPI.FeatureClass.FeatureCount(queryFilter); |
|
if (czcdydFeatureClassAPI.FeatureClass.FeatureCount(null) > 0) |
|
{ |
|
ITable pTable = czcdydFeatureClassAPI.FeatureClass as ITable; |
|
if (pTable != null) |
|
{ |
|
pTable.DeleteSearchedRows(null); |
|
} |
|
else |
|
{ |
|
Console.WriteLine("城镇村等用地数据清除失败!"); |
|
return; |
|
} |
|
} |
|
pFeatureCursor = dltbFeatureClassAPI.FeatureClass.Search(queryFilter, false); |
|
pInsertCursor = LSczcdydFeatureclassAPI.FeatureClass.Insert(true); |
|
|
|
IFeatureBuffer featureAdd = LSczcdydFeatureclassAPI.FeatureClass.CreateFeatureBuffer(); |
|
IFeature pFeature = null; |
|
int num = 0; |
|
int zldwdm = dltbFeatureClassAPI.FeatureClass.Fields.FindField("ZLDWDM"); |
|
int zldwmc = dltbFeatureClassAPI.FeatureClass.Fields.FindField("ZLDWMC"); |
|
int lszldwdm = LSczcdydFeatureclassAPI.FeatureClass.Fields.FindField("ZLDWDM"); |
|
int lszldwmc = LSczcdydFeatureclassAPI.FeatureClass.Fields.FindField("ZLDWMC"); |
|
while ((pFeature = pFeatureCursor.NextFeature()) != null) |
|
{ |
|
featureAdd.Shape = pFeature.Shape; |
|
if (LSczclxIndex > -1) |
|
{ |
|
featureAdd.set_Value(LSczclxIndex, pFeature.get_Value(czcsxmIndex)); |
|
} |
|
if (lszldwdm != -1) |
|
{ |
|
featureAdd.set_Value(lszldwdm, pFeature.get_Value(zldwdm)); |
|
} |
|
if (lszldwmc != -1) |
|
{ |
|
featureAdd.set_Value(lszldwmc, pFeature.get_Value(zldwmc)); |
|
} |
|
pInsertCursor.InsertFeature(featureAdd); |
|
} |
|
pInsertCursor.Flush(); |
|
Console.WriteLine("正在对城镇村等用地更新进行赋值......"); |
|
pOutWorkFactory = new SqlWorkspaceFactoryClass(); |
|
IWorkspace pOutWork = pOutWorkFactory.OpenFromFile(TempDBPath, 0); |
|
//IFeatureWorkspace SchemeWork = GetGdbWorkspace(schemeDBPath); |
|
IFeatureWorkspace TempWork2 = GetGdbWorkspace(TempfilePath); |
|
rdbHelper.ExecuteSQL(" drop table LSczcdyd "); |
|
TableToTable(TempWork2, pOutWork, "LSczcdyd"); |
|
|
|
string updateSQL = string.Format("update {0} set CZCDM = substr(ZLDWDM,1,6) || '0000000000000' where CZCLX in ('201','201A')", "LSczcdyd"); |
|
rdbHelper.ExecuteSQL(updateSQL); |
|
updateSQL = string.Format("update {0} set CZCDM = substr(ZLDWDM,1,9) || '0000000000' where CZCLX in ('202','202A')", "LSczcdyd"); |
|
rdbHelper.ExecuteSQL(updateSQL); |
|
updateSQL = string.Format("update {0} set CZCDM = [ZLDWDM],CZCMC = [ZLDWMC] where CZCLX in ('203','203A','204','205')", "LSczcdyd"); |
|
var x = rdbHelper.ExecuteSQL(updateSQL); |
|
|
|
DataTable dtLSczcdyd = rdbHelper.ExecuteDatatable("LSczcdyd", "select OBJECTID,CZCDM,CZCMC from LSczcdyd", true); |
|
pFeatureCursor = Tempworkspace.OpenFeatureClass("LSczcdyd").FeatureClass.Update(null, false); |
|
while ((pFeature = pFeatureCursor.NextFeature()) != null) |
|
{ |
|
object czcdm = dtLSczcdyd.Select(string.Format(" OBJECTID={0} ", pFeature.get_Value(pFeature.Fields.FindField("OBJECTID"))))[0]["CZCDM"]; |
|
pFeature.set_Value(pFeature.Fields.FindField("CZCDM"), czcdm); |
|
object czcmc = dtLSczcdyd.Select(string.Format(" OBJECTID={0} ", pFeature.get_Value(pFeature.Fields.FindField("OBJECTID"))))[0]["CZCMC"]; |
|
pFeature.set_Value(pFeature.Fields.FindField("CZCMC"), czcmc); |
|
pFeatureCursor.UpdateFeature(pFeature); |
|
} |
|
pFeatureCursor.Flush(); |
|
LSczcdydFeatureclassAPI = Tempworkspace.OpenFeatureClass("LSczcdyd"); |
|
// 根据城镇村等用地类型及城镇村代码相同且相邻进行融合 |
|
List<string> columns = new List<string>() { "CZCLX", "CZCDM", "CZCMC" }; |
|
var beforeCount = LSczcdydFeatureclassAPI.FeatureClass.FeatureCount(null); |
|
var outFilePath = TempfilePath + "\\CZCDYD_Dissolve"; |
|
gPParamClass = new GPParamClass() |
|
{ |
|
FirstFeatureLayer =new FeatureLayerClass() { FeatureClass = LSczcdydFeatureclassAPI.FeatureClass }, |
|
OutFeatureClassPath = outFilePath, |
|
IsGetOutPutFeature = true, |
|
ListDissolveFiledName = columns, |
|
//Statistics_Fields = "BSM COUNT", |
|
}; |
|
if (Tempworkspace.ExistFeatureClass("CZCDYD_Dissolve")) |
|
{ |
|
Tempworkspace.DeleteFeatureClass("CZCDYD_Dissolve"); |
|
} |
|
if (Tempworkspace.ExistFeatureClass("CZCDYD_Dissolve_Result")) |
|
{ |
|
Tempworkspace.DeleteFeatureClass("CZCDYD_Dissolve_Result"); |
|
} |
|
string path = gPParamClass.OutFeatureClassPath; |
|
IFeatureLayer featureLayer = null; |
|
gPParamClass.GPType = EnumGPType.Dissolve; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref featureLayer); |
|
|
|
gPParamClass.FirstFeatureLayer = featureLayer; |
|
gPParamClass.OutFeatureClassPath = TempfilePath; |
|
gPParamClass.FcName = "CZCDYD_Dissolve_Result"; |
|
gPParamClass.GPType = EnumGPType.FcToFc; |
|
IFeatureLayer tempLayer = null; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref tempLayer); ; |
|
//pFeatureClass_4 = tempLayer.FeatureClass;// Tempworkspace.OpenFeatureClass("CZCDYD_Dissolve_Result"); |
|
|
|
int countt = tempLayer.FeatureClass.FeatureCount(null); |
|
if (countt <= 0) |
|
{ |
|
//Console.WriteLineTips("融合之后出错!,数据异常"); |
|
return; |
|
} |
|
pFeatureCursor = tempLayer.FeatureClass.Search(null, false); |
|
//网格大小引发的错误 |
|
if (czcdydFeatureClassAPI.FeatureClass is IFeatureClassLoad pFclsLoad) |
|
pFclsLoad.LoadOnlyMode = true; |
|
pInsertCursor = czcdydFeatureClassAPI.FeatureClass.Insert(true); |
|
int cxmIndex = tempLayer.FeatureClass.FindField("CZCLX"); |
|
int Index_1 = tempLayer.FeatureClass.FindField("CZCDM"); |
|
int Index_2 = czcdydFeatureClassAPI.FeatureClass.FindField("CZCDM"); |
|
int Index_3 = tempLayer.FeatureClass.FindField("CZCMC"); |
|
int Index_4 = czcdydFeatureClassAPI.FeatureClass.FindField("CZCMC"); |
|
featureAdd = czcdydFeatureClassAPI.FeatureClass.CreateFeatureBuffer(); |
|
pFeature = null; |
|
string substr = ""; |
|
num = 0; |
|
while ((pFeature = pFeatureCursor.NextFeature()) != null) |
|
{ |
|
featureAdd.Shape = pFeature.Shape; |
|
if (czclxIndex > -1) |
|
{ |
|
featureAdd.set_Value(czclxIndex, pFeature.get_Value(cxmIndex)); |
|
featureAdd.set_Value(Index_2, pFeature.get_Value(Index_1)); |
|
featureAdd.set_Value(Index_4, pFeature.get_Value(Index_3)); |
|
if (string.IsNullOrEmpty(substr)) |
|
{ |
|
substr = pFeature.get_Value(Index_1).ToString(); |
|
} |
|
} |
|
pInsertCursor.InsertFeature(featureAdd); |
|
} |
|
pInsertCursor.Flush(); |
|
if (czcdydFeatureClassAPI.FeatureClass is IFeatureClassLoad pFclsLoads) |
|
pFclsLoads.LoadOnlyMode = false; |
|
path = TempfilePath;// GetTempPath(); |
|
rdbHelper.ExecuteSQL(" drop table CZCDYDGX "); |
|
IFeatureWorkspace TempfeatureWorkspace = (bgParm.GXCZCLayer.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace; |
|
TableToTable(TempfeatureWorkspace, pOutWork, "CZCDYDGX"); |
|
|
|
#region 201 201A |
|
{ |
|
var result = GetXZQDic().Find(p => p.CODE == substr.Substring(0, 6)); |
|
if (result != null) |
|
{ |
|
string SQLstr = $"UPDATE CZCDYDGX SET CZCMC = '{result.NAME}' WHERE CZCLX in ('201','201A')"; |
|
rdbHelper.ExecuteSQL(SQLstr); |
|
} |
|
} |
|
#endregion |
|
|
|
rdbHelper.ExecuteSQL(" drop table CJDCQGX "); |
|
TableToTable(TempfeatureWorkspace, pOutWork, "CJDCQGX"); |
|
|
|
DataTable dt = rdbHelper.ExecuteDatatable("CZCDYDGX", "select objectid,CZCMC from CZCDYDGX", true); |
|
|
|
string time = new DateTime(DateTime.Now.Year - 1, 12, 31).ToShortDateString(); |
|
// 标识码赋值 |
|
int maxValue = 1; |
|
|
|
string MaxBSM = GetMaxBSM(new List<IFeatureClass>() { bgParm.JCCZCLayer.FeatureClass }); |
|
|
|
string BSM = pParm.XZQDM + "2931"; |
|
IFeatureCursor pFeatureCursor_LS = czcdydFeatureClassAPI.FeatureClass.Update(null, true); |
|
count = czcdydFeatureClassAPI.FeatureClass.FeatureCount(null); |
|
Console.WriteLine("正在对城镇村等用地更新进行赋值......"); |
|
int bsmIndexof = czcdydFeatureClassAPI.FeatureClass.FindField("BSM"); |
|
int czclxindex = czcdydFeatureClassAPI.FeatureClass.FindField("CZCLX"); |
|
num = 0; |
|
IFeature pfeaFeature = pFeatureCursor_LS.NextFeature(); |
|
int czcdmIdx = czcdydFeatureClassAPI.FeatureClass.Fields.FindField("CZCDM"); |
|
while (pfeaFeature != null) |
|
{ |
|
string bsmPrefix = pParm.XZQDM + MaxBSM.Substring(6, 4); |
|
int MaxNum = Convert.ToInt32(MaxBSM.Substring(10)); |
|
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); |
|
pfeaFeature.set_Value(bsmIndexof, MaxBSM); |
|
pfeaFeature.set_Value(czcdydFeatureClassAPI.FeatureClass.FindField("YSDM"), "2099030100"); |
|
string czclx = pfeaFeature.Value[czclxindex].ToTrim(); |
|
string czcmc = string.Empty; |
|
DataRow[] drSet = dt.Select(string.Format(" objectid='{0}' ", pfeaFeature.Value[0])); |
|
if (drSet != null && drSet.Length > 0) |
|
{ |
|
czcmc = drSet[0]["CZCMC"].ToString(); |
|
} |
|
if (string.IsNullOrWhiteSpace(czcmc) && czcdmIdx != -1 && qsDic != null) |
|
{ |
|
string strCZCDM = pfeaFeature.Value[czcdmIdx].ToTrim(); |
|
if (czclx == "203" || czclx == "203A" || czclx == "204" || czclx == "205") |
|
{ |
|
if (strCZCDM.Length > 12) |
|
{ |
|
DataDicTionary dic = qsDic.FirstOrDefault(qs => qs.CODE == strCZCDM || qs.CODE.StartsWith(strCZCDM.Substring(0, 12))); |
|
if (dic != null) |
|
czcmc = dic.NAME; |
|
} |
|
} |
|
else if (czclx == "202" || czclx == "202A") |
|
{ |
|
if (strCZCDM.Length > 9) |
|
{ |
|
DataDicTionary dic = qsDic.FirstOrDefault(qs => qs.CODE == strCZCDM || qs.CODE.StartsWith(strCZCDM.Substring(0, 9))); |
|
if (dic != null) |
|
czcmc = dic.NAME; |
|
} |
|
} |
|
else if (czclx == "201" || czclx == "201A") |
|
{ |
|
if (strCZCDM.Length > 6) |
|
{ |
|
DataDicTionary dic = qsDic.FirstOrDefault(qs => qs.CODE == strCZCDM || qs.CODE.StartsWith(strCZCDM.Substring(0, 6))); |
|
if (dic != null) |
|
czcmc = dic.NAME; |
|
} |
|
} |
|
} |
|
pfeaFeature.set_Value(czcdydFeatureClassAPI.FeatureClass.FindField("CZCMC"), czcmc); |
|
pfeaFeature.set_Value(czcdydFeatureClassAPI.FeatureClass.FindField("GXSJ"), time); |
|
pfeaFeature.set_Value(czcdydFeatureClassAPI.FeatureClass.FindField("CZCMJ"), pfeaFeature.ShapeCopy.GetEllipseArea()); |
|
pFeatureCursor_LS.UpdateFeature(pfeaFeature); |
|
maxValue++; |
|
pfeaFeature = pFeatureCursor_LS.NextFeature(); |
|
} |
|
pFeatureCursor_LS.Flush(); |
|
|
|
//设置基础城镇村选中 |
|
gPParamClass = new GPParamClass(); |
|
|
|
IFeatureWorkspace inWs = GetGdbWorkspace(path); |
|
|
|
IFeatureLayer czcUnionLayer = null; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = bgParm.JCCZCLayer;// MapsManager.Instance.MapService.GetFeatureLayerByLayerName("城镇村等用地"); |
|
gPParamClass.SecondFeatureLayer = new FeatureLayerClass() { FeatureClass = czcdydFeatureClassAPI.FeatureClass }; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "TempCZCGXGC2"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.Union; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref czcUnionLayer); |
|
|
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = czcUnionLayer; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "TempCZCGXGC"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.MultipartToSinglePath; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref czcUnionLayer); |
|
|
|
rdbHelper.ExecuteSQL(" drop table TempCZCGXGC "); |
|
TableToTable(inWs, pOutWork, "TempCZCGXGC"); |
|
string FID_JC_CZCDYD = $"FID_{featureClass.Name}"; |
|
string strSql = $"select objectid,fid_czcdydgx from (select count(1) num,objectid,{FID_JC_CZCDYD},czclx bgqczclx,czclx_1 bghczclx,czcdm bgqczcdm,czcdm_1 bghczcdm,czcmc bgqczcmc,czcmc_1 bghczcmc,FID_CZCDYDGX from TempCZCGXGC group by {FID_JC_CZCDYD}) where num=1 and bgqczclx=bghczclx and bgqczcdm=bghczcdm and bgqczcmc=bghczcmc"; |
|
DataTable gxgcDT = rdbHelper.ExecuteDatatable("tempgxgc", strSql, true); |
|
|
|
strSql = $"select objectid,fid_czcdydgx from (select count(1) num,objectid,{FID_JC_CZCDYD},czclx bgqczclx,czclx_1 bghczclx,czcdm bgqczcdm,czcdm_1 bghczcdm,czcmc bgqczcmc,czcmc_1 bghczcmc,FID_CZCDYDGX from TempCZCGXGC group by FID_CZCDYDGX) where num=1 and bgqczclx=bghczclx and bgqczcdm=bghczcdm and bgqczcmc=bghczcmc"; |
|
DataTable gxgcDT2 = rdbHelper.ExecuteDatatable("tempgxgc", strSql, true); |
|
List<int> AllowDelOIDs = new List<int>(); |
|
if (gxgcDT2 != null) |
|
{ |
|
foreach (DataRow row in gxgcDT2.Rows) |
|
{ |
|
AllowDelOIDs.Add(Convert.ToInt32(row["FID_CZCDYDGX"])); |
|
} |
|
} |
|
if (gxgcDT != null) |
|
{ |
|
List<string> SqlList = new List<string>(); |
|
foreach (DataRow row in gxgcDT.Rows) |
|
{ |
|
int oid = Convert.ToInt32(row["OBJECTID"]); |
|
int gxOID = Convert.ToInt32(row["FID_CZCDYDGX"]); |
|
if (!AllowDelOIDs.Contains(gxOID)) |
|
continue; |
|
IFeature gx = czcdydFeatureClassAPI.FeatureClass.GetFeature(gxOID); |
|
gx.Delete(); |
|
IFeature gcF = czcUnionLayer.FeatureClass.GetFeature(oid); |
|
gcF.Delete(); |
|
SqlList.Add(string.Format("Delete from TempCZCGXGC where OBJECTID={0}", oid)); |
|
} |
|
rdbHelper.BeginTransaction(); |
|
try |
|
{ |
|
foreach (var item in SqlList) |
|
{ |
|
rdbHelper.ExecuteSQL(item); |
|
} |
|
rdbHelper.Commit(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
rdbHelper.Rollback(); |
|
} |
|
} |
|
|
|
IFeatureClassAPI czcGXGCAPI = new FeatureClassAPI(bgParm.GXGCCZCLayer.FeatureClass);// .OpenFeatureClass("CZCDYDGXGC"); |
|
(czcGXGCAPI.FeatureClass as ITable).DeleteSearchedRows(null); |
|
IFeatureCursor cursor = czcUnionLayer.FeatureClass.Search(null, true); |
|
IFeature f = null; |
|
int idxBGQBSM = czcUnionLayer.FeatureClass.FindField("BSM"); |
|
int idxBGHBSM = czcUnionLayer.FeatureClass.FindField("BSM_1"); |
|
int idxBGQCZCLX = czcUnionLayer.FeatureClass.FindField("CZCLX"); |
|
int idxBGHCZCLX = czcUnionLayer.FeatureClass.FindField("CZCLX_1"); |
|
int idxBGQCZCDM = czcUnionLayer.FeatureClass.FindField("CZCDM"); |
|
int idxBGHCZCDM = czcUnionLayer.FeatureClass.FindField("CZCDM_1"); |
|
int idxBGQCZCMC = czcUnionLayer.FeatureClass.FindField("CZCMC"); |
|
int idxBGHCZCMC = czcUnionLayer.FeatureClass.FindField("CZCMC_1"); |
|
int idxCZCMJ = czcUnionLayer.FeatureClass.FindField("CZCMJ"); |
|
|
|
|
|
int t_idxBGQBSM = czcGXGCAPI.FeatureClass.FindField("BGQBSM"); |
|
int t_idxBGHBSM = czcGXGCAPI.FeatureClass.FindField("BGHBSM"); |
|
int t_idxBGQCZCLX = czcGXGCAPI.FeatureClass.FindField("BGQCZCLX"); |
|
int t_idxBGHCZCLX = czcGXGCAPI.FeatureClass.FindField("BGHCZCLX"); |
|
int t_idxBGQCZCDM = czcGXGCAPI.FeatureClass.FindField("BGQCZCDM"); |
|
int t_idxBGHCZCDM = czcGXGCAPI.FeatureClass.FindField("BGHCZCDM"); |
|
int t_idxBGQCZCMC = czcGXGCAPI.FeatureClass.FindField("BGQCZCMC"); |
|
int t_idxBGHCZCMC = czcGXGCAPI.FeatureClass.FindField("BGHCZCMC"); |
|
int t_idxBGMJ = czcGXGCAPI.FeatureClass.FindField("BGMJ"); |
|
int t_idxBGXW = czcGXGCAPI.FeatureClass.FindField("BGXW"); |
|
int t_idxGXSJ = czcGXGCAPI.FeatureClass.FindField("GXSJ"); |
|
//网格大小报错 |
|
if (czcGXGCAPI.FeatureClass is IFeatureClassLoad pFclsLoad2) |
|
pFclsLoad2.LoadOnlyMode = true; |
|
IFeatureCursor insertCur = czcGXGCAPI.FeatureClass.Insert(true); |
|
IFeatureBuffer buf = null; |
|
List<PCModel> pcList = new List<PCModel>(); |
|
IFeatureLayer czcgxLayer = bgParm.GXCZCLayer;// MapsManager.Instance.MapService.GetFeatureLayerByName("CZCDYDGX"); |
|
IFeatureLayer jcczcLayer = bgParm.JCCZCLayer;// MapsManager.Instance.MapService.GetFeatureLayerByLayerName("城镇村等用地"); |
|
int idxGXBSM = czcgxLayer.FeatureClass.FindField("BSM"); |
|
|
|
strSql = $"select BSM from (select count(1) num,objectid,bsm from TempCZCGXGC group by {FID_JC_CZCDYD}) where num>1"; |
|
DataTable txbgData = rdbHelper.ExecuteDatatable("tempgxgc", strSql, true); |
|
count = czcUnionLayer.FeatureClass.FeatureCount(null); |
|
num = 0; |
|
while ((f = cursor.NextFeature()) != null) |
|
{ |
|
string s_bgqbsm = f.Value[idxBGQBSM].ToTrim(); |
|
string s_bghbsm = f.Value[idxBGHBSM].ToTrim(); |
|
string s_bgqczclx = f.Value[idxBGQCZCLX].ToTrim(); |
|
string s_bghczclx = f.Value[idxBGHCZCLX].ToTrim(); |
|
string s_bgqczcdm = f.Value[idxBGQCZCDM].ToTrim(); |
|
string s_bghczcdm = f.Value[idxBGHCZCDM].ToTrim(); |
|
string s_bgqczcmc = f.Value[idxBGQCZCMC].ToTrim(); |
|
string s_bghczcmc = f.Value[idxBGHCZCMC].ToTrim(); |
|
double czcmj = f.Value[idxCZCMJ].ToDouble(2); |
|
if ((s_bgqczclx == "203" || s_bgqczclx == "203A") && s_bgqczclx == s_bghczclx && s_bgqczcdm.Substring(0, 12) == s_bghczcdm.Substring(0, 12)) |
|
{ |
|
List<IFeature> jcList = FeatureAPI.Identify2(f.ShapeCopy, jcczcLayer); |
|
if (jcList.Count == 1 && FeatureAPI.GetEqual(jcList[0].ShapeCopy, f.ShapeCopy)) |
|
{ |
|
List<IFeature> gxList = FeatureAPI.Identify2(f.ShapeCopy, czcgxLayer); |
|
foreach (var tempGxItem in gxList) |
|
{ |
|
tempGxItem.Shape = FeatureAPI.Difference(tempGxItem.ShapeCopy, f.ShapeCopy); |
|
tempGxItem.Store(); |
|
if (tempGxItem.Shape.IsEmpty) |
|
{ |
|
tempGxItem.Delete(); |
|
} |
|
} |
|
continue; |
|
} |
|
else |
|
{ |
|
} |
|
} |
|
string bgxw = string.Empty; |
|
if (string.IsNullOrWhiteSpace(s_bghczclx)) |
|
{ |
|
bgxw = "0"; |
|
List<IFeature> gxList = FeatureAPI.Identify2(f.ShapeCopy, dltbgxLayer); |
|
if (gxList.Count == 0) |
|
{ |
|
continue; |
|
} |
|
} |
|
else if (string.IsNullOrWhiteSpace(s_bgqczcdm)) |
|
{ |
|
bgxw = "3"; |
|
List<IFeature> gxList = FeatureAPI.Identify2(f.ShapeCopy, dltbgxLayer); |
|
if (gxList.Count == 0) |
|
{ |
|
List<IFeature> gxList2 = FeatureAPI.Identify2(f.ShapeCopy, czcgxLayer); |
|
foreach (var item in gxList2) |
|
{ |
|
if (FeatureAPI.GetEqual(item.ShapeCopy, f.ShapeCopy)) |
|
item.Delete(); |
|
else |
|
{ |
|
item.Shape = FeatureAPI.Difference(item.ShapeCopy, f.ShapeCopy); |
|
item.Store(); |
|
} |
|
} |
|
continue; |
|
} |
|
} |
|
else |
|
{ |
|
bgxw = "2"; |
|
if (txbgData.Select(string.Format("BSM='{0}'", s_bgqbsm)).Length == 0) |
|
{ |
|
List<IFeature> gxList = FeatureAPI.Identify2(f.ShapeCopy, czcgxLayer); |
|
if (gxList.Count == 1) |
|
{ |
|
if (FeatureAPI.GetEqual(f.ShapeCopy, gxList[0].ShapeCopy)) |
|
{ |
|
bgxw = "1"; |
|
s_bghbsm = s_bgqbsm; |
|
gxList[0].Value[idxGXBSM] = s_bghbsm; |
|
gxList[0].Store(); |
|
} |
|
} |
|
} |
|
} |
|
buf = czcGXGCAPI.FeatureClass.CreateFeatureBuffer(); |
|
buf.Shape = f.ShapeCopy; |
|
buf.Value[t_idxBGQCZCLX] = s_bgqczclx; |
|
buf.Value[t_idxBGQCZCDM] = s_bgqczcdm; |
|
buf.Value[t_idxBGQCZCMC] = s_bgqczcmc; |
|
buf.Value[t_idxBGQBSM] = s_bgqbsm; |
|
buf.Value[t_idxGXSJ] = time; |
|
|
|
buf.Value[t_idxBGXW] = bgxw; |
|
buf.Value[t_idxBGHCZCLX] = s_bghczclx; |
|
buf.Value[t_idxBGHCZCDM] = s_bghczcdm; |
|
buf.Value[t_idxBGHCZCMC] = s_bghczcmc; |
|
buf.Value[t_idxBGHBSM] = s_bghbsm; |
|
|
|
double bgmj = f.ShapeCopy.GetEllipseArea().ToDouble(2); |
|
if (bgxw == "3") |
|
{ |
|
buf.Value[t_idxBGMJ] = bgmj; |
|
} |
|
object oid = insertCur.InsertFeature(buf); |
|
|
|
if (bgxw != "3") |
|
{ |
|
PCModel pc = pcList.FirstOrDefault(e => e.BGQBSM == s_bgqbsm); |
|
if (pc == null) |
|
{ |
|
pc = new PCModel(); |
|
pc.BGQBSM = s_bgqbsm; |
|
pc.KZMJ = czcmj; |
|
pc.GCData.Add(new GCMJModel() { OID = Convert.ToInt32(oid), MJ = bgmj }); |
|
pcList.Add(pc); |
|
} |
|
else |
|
{ |
|
pc.GCData.Add(new GCMJModel() { OID = Convert.ToInt32(oid), MJ = bgmj }); |
|
} |
|
} |
|
} |
|
insertCur.Flush(); |
|
if (czcGXGCAPI.FeatureClass is IFeatureClassLoad pFclsLoad3) |
|
pFclsLoad3.LoadOnlyMode = false; |
|
foreach (var item in pcList) |
|
{ |
|
item.PC2(); |
|
foreach (var gcOID in item.GCData) |
|
{ |
|
IFeature gc = czcGXGCAPI.FeatureClass.GetFeature(gcOID.OID); |
|
gc.Value[t_idxBGMJ] = gcOID.MJ; |
|
gc.Store(); |
|
} |
|
} |
|
DataTable tempGcDt = new DataTable(); |
|
IQueryFilter filt = new QueryFilterClass(); |
|
filt.SubFields = "BGMJ,BGHBSM,BGQBSM,OBJECTID,BGXW"; |
|
filt.WhereClause = "BGXW <> '0'"; |
|
czcGXGCAPI.QueryFeaturesToDataTable(filt, -1, out tempGcDt); |
|
|
|
Dictionary<string, double> bghMJs = new Dictionary<string, double>(); |
|
foreach (DataRow item in tempGcDt.Rows) |
|
{ |
|
string bsm = item["BGHBSM"].ToTrim(); |
|
if (string.IsNullOrWhiteSpace(bsm)) continue; |
|
if (bghMJs.ContainsKey(bsm)) |
|
{ |
|
bghMJs[bsm] += item["BGMJ"].ToDouble(2); |
|
} |
|
else |
|
{ |
|
bghMJs.Add(bsm, item["BGMJ"].ToDouble(2)); |
|
} |
|
} |
|
//List<string> upMJSqlList = new List<string>(); |
|
//foreach (var item in bghMJs.Keys) |
|
//{ |
|
// upMJSqlList.Add(string.Format("Update CZCDYDGX set CZCMJ={0} where BSM='{1}'", bghMJs[item].ToDouble(2), item)); |
|
//} |
|
ICursor upCursor = (czcgxLayer.FeatureClass as ITable).Update(null, true); |
|
IRow upRow = null; |
|
int idxGXCZCMJ = czcgxLayer.FeatureClass.FindField("CZCMJ"); |
|
while ((upRow = upCursor.NextRow()) != null) |
|
{ |
|
string bsm = upRow.Value[idxGXBSM].ToTrim(); |
|
if (bghMJs.ContainsKey(bsm)) |
|
{ |
|
upRow.Value[idxGXCZCMJ] = bghMJs[bsm].ToDouble(2); |
|
upCursor.UpdateRow(upRow); |
|
} |
|
} |
|
|
|
IFeatureLayer JC_CZC203Layer_Mem = GeoDBAPI.CreateFeatureLayerInmemeory("JCCZC203", "城镇村203范围", (bgParm.JCCZCLayer.FeatureClass as IGeoDataset).SpatialReference, bgParm.JCCZCLayer.FeatureClass.ShapeType, bgParm.JCCZCLayer.FeatureClass.Fields); |
|
filter.WhereClause = "CZCLX='203' or CZCLX='203A'"; |
|
InsertDataToMemeoryLayer(tempJCCZCLayer.FeatureClass, JC_CZC203Layer_Mem.FeatureClass, filter); |
|
cursor = czcgxLayer.FeatureClass.Search(new QueryFilterClass() { WhereClause = " CZCLX='203' or CZCLX='203A'" }, true); |
|
f = null; |
|
List<int> feaOIDs = new List<int>(); |
|
//int czclxIdx = czcgxLayer.FeatureClass.FindField("CZCLX"); |
|
int jcczclxIdx = JC_CZC203Layer_Mem.FeatureClass.FindField("CZCLX"); |
|
while ((f = cursor.NextFeature()) != null) |
|
{ |
|
List<IFeature> jc203Features = FeatureAPI.Identify(f.ShapeCopy, JC_CZC203Layer_Mem); |
|
if (jc203Features != null) |
|
{ |
|
foreach (var jcF in jc203Features) |
|
{ |
|
if (FeatureAPI.GetEqual(jcF.ShapeCopy, f.ShapeCopy)) break; |
|
if (!FeatureAPI.IsInterSect(jcF.ShapeCopy, f.ShapeCopy)) continue; |
|
|
|
IGeometry InterGeo = FeatureAPI.InterSect(jcF.ShapeCopy, f.ShapeCopy); |
|
IGeometry DiffGeo = FeatureAPI.Difference(f.ShapeCopy, jcF.ShapeCopy); |
|
if (DiffGeo.IsEmpty) |
|
{ |
|
break; |
|
} |
|
if (!feaOIDs.Contains(f.OID)) |
|
feaOIDs.Add(f.OID); |
|
} |
|
} |
|
} |
|
idxGXBSM = czcgxLayer.FeatureClass.FindField("BSM"); |
|
int idxGXCZCLX = czcgxLayer.FeatureClass.FindField("CZCLX"); |
|
int idxGXCZCDM = czcgxLayer.FeatureClass.FindField("CZCDM"); |
|
int idxGXCZCMC = czcgxLayer.FeatureClass.FindField("CZCMC"); |
|
idxGXCZCMJ = czcgxLayer.FeatureClass.FindField("CZCMJ"); |
|
int idxGXGXSJ = czcgxLayer.FeatureClass.FindField("GXSJ"); |
|
IFeatureLayer czcgxgcLayer = bgParm.GXGCCZCLayer;// MapsManager.Instance.MapService.GetFeatureLayerByName("CZCDYDGXGC"); |
|
int idxGXGCBGMJ = czcgxgcLayer.FeatureClass.FindField("BGMJ"); |
|
int idxGXGCBGHBSM = czcgxgcLayer.FeatureClass.FindField("BGHBSM"); |
|
insertCur = czcgxLayer.FeatureClass.Insert(true); |
|
foreach (int oid in feaOIDs) |
|
{ |
|
f = czcgxLayer.FeatureClass.GetFeature(oid); |
|
string bsm = f.Value[idxGXBSM].ToTrim(); |
|
string czclx = f.Value[idxGXCZCLX].ToTrim(); |
|
List<IFeature> jc203Features = FeatureAPI.Identify(f.ShapeCopy, JC_CZC203Layer_Mem); |
|
if (jc203Features != null) |
|
{ |
|
IGeometry jc203 = null; |
|
foreach (var jcF in jc203Features) |
|
{ |
|
bool IsEquql = FeatureAPI.GetEqual(jcF.ShapeCopy, f.ShapeCopy); |
|
string jcczclx = jcF.Value[jcczclxIdx].ToTrim(); |
|
if (IsEquql && jcczclx == czclx) |
|
{ |
|
f.Delete(); |
|
break; |
|
} |
|
if (!FeatureAPI.IsInterSect(jcF.ShapeCopy, f.ShapeCopy)) continue; |
|
if (FeatureAPI.IsContains(jcF.ShapeCopy, f.ShapeCopy)) |
|
{ |
|
break; |
|
} |
|
if (jc203 == null) |
|
jc203 = jcF.ShapeCopy; |
|
else |
|
jc203 = FeatureAPI.Union(jc203, jcF.ShapeCopy); |
|
} |
|
IGeometry InterGeo = FeatureAPI.InterSect(jc203, f.ShapeCopy); |
|
IGeometry DiffGeo = FeatureAPI.Difference(f.ShapeCopy, jc203); |
|
|
|
if (DiffGeo.IsEmpty) |
|
{ |
|
continue; |
|
} |
|
List<IGeometry> Rings = FeatureAPI.DissolveGeometryByRing(InterGeo); |
|
List<IGeometry> Rings2 = FeatureAPI.DissolveGeometryByRing(DiffGeo); |
|
if (Rings == null) Rings = new List<IGeometry>(); |
|
if (Rings2 == null) Rings2 = new List<IGeometry>(); |
|
if (Rings2.Count == 0) |
|
{ |
|
f.Delete(); |
|
} |
|
else |
|
{ |
|
IGeometry tempGeo = f.ShapeCopy; |
|
if (Rings2.Count > 0) |
|
tempGeo = Rings2[0]; |
|
ITopologicalOperator topo = tempGeo as ITopologicalOperator; |
|
IGeometry tempGeo2 = topo.Buffer(-0.00015); |
|
List<IFeature> gcList = FeatureAPI.Identify(tempGeo2, czcgxgcLayer); |
|
Marshal.ReleaseComObject(tempGeo2); |
|
double czcmj = 0; |
|
foreach (IFeature gcF in gcList) |
|
{ |
|
if (!FeatureAPI.IsInterSect(tempGeo, gcF.ShapeCopy)) continue; |
|
czcmj += gcF.Value[idxGXGCBGMJ].ToDouble(2); |
|
gcF.Store(); |
|
} |
|
f.Value[idxGXCZCMJ] = czcmj.ToDouble(2); |
|
|
|
f.Shape = tempGeo; |
|
f.Store(); |
|
if (Rings2.Count > 0) |
|
Rings2.RemoveAt(0); |
|
} |
|
if (Rings2.Count > 0) |
|
Rings.AddRange(Rings2); |
|
foreach (var GeoRing in Rings) |
|
{ |
|
|
|
string bsmPrefix = pParm.XZQDM + MaxBSM.Substring(6, 4); |
|
int MaxNum = Convert.ToInt32(MaxBSM.Substring(10)); |
|
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); |
|
|
|
IFeatureBuffer buff = czcgxLayer.FeatureClass.CreateFeatureBuffer(); |
|
buff.Value[idxGXBSM] = MaxBSM; |
|
buff.Value[idxGXCZCLX] = f.Value[idxGXCZCLX]; |
|
buff.Value[idxGXCZCDM] = f.Value[idxGXCZCDM]; |
|
buff.Value[idxGXCZCMC] = f.Value[idxGXCZCMC]; |
|
buff.Value[idxGXGXSJ] = time; |
|
buff.Shape = GeoRing; |
|
List<IFeature> gcList = FeatureAPI.Identify2(GeoRing, czcgxgcLayer); |
|
double czcmj = 0; |
|
foreach (IFeature gcF in gcList) |
|
{ |
|
if (!FeatureAPI.IsInterSect(GeoRing, gcF.ShapeCopy)) continue; |
|
czcmj += gcF.Value[idxGXGCBGMJ].ToDouble(2); |
|
gcF.Value[idxGXGCBGHBSM] = MaxBSM; |
|
gcF.Store(); |
|
} |
|
buff.Value[idxGXCZCMJ] = czcmj.ToDouble(2); |
|
object addOid = insertCur.InsertFeature(buff); |
|
} |
|
} |
|
insertCur.Flush(); |
|
Marshal.ReleaseComObject(f); |
|
} |
|
cursor = czcgxLayer.FeatureClass.Search(null, true); |
|
f = null; |
|
List<int> oids = new List<int>(); |
|
while ((f = cursor.NextFeature()) != null) |
|
{ |
|
List<IGeometry> Rings = FeatureAPI.DissolveGeometryByRing(f.ShapeCopy); |
|
if (Rings == null) continue; |
|
if (Rings.Count == 1) continue; |
|
oids.Add(f.OID); |
|
} |
|
foreach (int oid in oids) |
|
{ |
|
IFeature gxFeature = czcgxLayer.FeatureClass.GetFeature(oid); |
|
|
|
List<IGeometry> Rings = FeatureAPI.DissolveGeometryByRing(gxFeature.ShapeCopy); |
|
if (Rings.Count > 1) |
|
{ |
|
gxFeature.Shape = Rings[0]; |
|
{ |
|
List<IFeature> gcList = FeatureAPI.Identify2(Rings[0], czcgxgcLayer); |
|
double czcmj = 0; |
|
foreach (IFeature gcF in gcList) |
|
{ |
|
czcmj += gcF.Value[idxGXGCBGMJ].ToDouble(2); |
|
gcF.Store(); |
|
} |
|
gxFeature.Value[idxGXCZCMJ] = czcmj.ToDouble(2); |
|
} |
|
gxFeature.Store(); |
|
for (int i = 1; i < Rings.Count; i++) |
|
{ |
|
if (Rings[i].IsEmpty) continue; |
|
string bsmPrefix = pParm.XZQDM + MaxBSM.Substring(6, 4); |
|
int MaxNum = Convert.ToInt32(MaxBSM.Substring(10)); |
|
MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); |
|
|
|
IFeatureBuffer buff = czcgxLayer.FeatureClass.CreateFeatureBuffer(); |
|
buff.Value[idxGXBSM] = MaxBSM; |
|
buff.Value[idxGXCZCLX] = gxFeature.Value[idxGXCZCLX]; |
|
buff.Value[idxGXCZCDM] = gxFeature.Value[idxGXCZCDM]; |
|
buff.Value[idxGXCZCMC] = gxFeature.Value[idxGXCZCMC]; |
|
buff.Value[idxGXGXSJ] = time; |
|
buff.Shape = Rings[i]; |
|
List<IFeature> gcList = FeatureAPI.Identify2(Rings[i], czcgxgcLayer); |
|
double czcmj = 0; |
|
foreach (IFeature gcF in gcList) |
|
{ |
|
czcmj += gcF.Value[idxGXGCBGMJ].ToDouble(2); |
|
gcF.Value[idxGXGCBGHBSM] = MaxBSM; |
|
gcF.Store(); |
|
} |
|
buff.Value[idxGXCZCMJ] = czcmj.ToDouble(2); |
|
insertCur.InsertFeature(buff); |
|
} |
|
} |
|
} |
|
insertCur.Flush(); |
|
if (false) |
|
{ |
|
(czcgxLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL("Delete from CZCDYDGX where CZCMJ=0"); |
|
(czcgxgcLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL("Delete from CZCDYDGXGC where BGMJ=0"); |
|
} |
|
rdbHelper.ExecuteSQL(" drop table CZCDYDGXGC "); |
|
TableToTable(TempfeatureWorkspace, pOutWork, "CZCDYDGXGC"); |
|
rdbHelper.ExecuteSQL(" drop table CZCDYDGX "); |
|
TableToTable(TempfeatureWorkspace, pOutWork, "CZCDYDGX"); |
|
string sql = "select a.bsm aoid,b.objectid boid from czcdydgx a left join czcdydgxgc b on a.bsm=b.bghbsm where boid is null"; |
|
DataTable gxDT = rdbHelper.ExecuteDatatable("tempgx", sql, true); |
|
if (gxDT != null && gxDT.Rows.Count > 0) |
|
{ |
|
foreach (DataRow dr in gxDT.Rows) |
|
{ |
|
(czcgxLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL(string.Format("Delete from CZCDYDGX where bsm='{0}'", dr["AOID"])); |
|
} |
|
} |
|
rdbHelper.ExecuteSQL(" drop table CZCDYDGXGC "); |
|
TableToTable(TempfeatureWorkspace, pOutWork, "CZCDYDGXGC"); |
|
rdbHelper.ExecuteSQL(" drop table CZCDYDGX "); |
|
TableToTable(TempfeatureWorkspace, pOutWork, "CZCDYDGX"); |
|
sql = "select bgqbsm from czcdydgxgc where bgqbsm in (select bgqbsm from czcdydgxgc where bghbsm in (select bghbsm from czcdydgxgc group by bghbsm HAVING count(1)=1) and bgqbsm!='')group by bgqbsm HAVING count(1)=1"; |
|
gxgcDT = rdbHelper.ExecuteDatatable("tempgxgc", sql, true); |
|
string PrjCode = pParm.XZQDM; |
|
sql = "select * from CZCDYDGXGC"; |
|
DataTable gxgcDTAll = rdbHelper.ExecuteDatatable("CZCDYDGXGC", sql, true); |
|
if (gxgcDT != null && gxgcDT.Rows.Count > 0) |
|
{ |
|
foreach (DataRow dr in gxgcDT.Rows) |
|
{ |
|
DataRow[] drs = gxgcDTAll.Select(string.Format("BGQBSM='{0}'", dr["BGQBSM"])); |
|
if (drs != null && drs.Length == 1) |
|
{ |
|
if (drs[0]["BGQCZCLX"].ToTrim() == drs[0]["BGHCZCLX"].ToTrim() && |
|
drs[0]["BGQCZCDM"].ToTrim() == drs[0]["BGHCZCDM"].ToTrim() && |
|
drs[0]["BGQCZCMC"].ToTrim() == drs[0]["BGHCZCMC"].ToTrim()) |
|
{ |
|
(czcgxLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL(string.Format("Delete from CZCDYDGX where bsm='{0}'", drs[0]["BGHBSM"])); |
|
(czcgxgcLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL(string.Format("Delete from CZCDYDGXGC where BGQBSM='{0}'", drs[0]["BGQBSM"])); |
|
} |
|
else |
|
{ |
|
string bsm = dr["BGQBSM"].ToTrim(); |
|
if (!dr["BGQBSM"].ToTrim().StartsWith(PrjCode)) |
|
bsm = bsm.Replace(bsm.Substring(0, 6), PrjCode); |
|
(czcgxLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL(string.Format("Update CZCDYDGX set BSM='{0}' where bsm='{1}'", bsm, drs[0]["BGHBSM"])); |
|
|
|
(czcgxgcLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL(string.Format("Update CZCDYDGXGC set BGXW='1',BGHBSM='{0}' where BGQBSM='{1}' and BGHBSM='{2}'", bsm, dr["BGQBSM"], drs[0]["BGHBSM"])); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("提取城镇村等用地数据异常:" + ex.Message); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (LSczcdydFeatureclassAPI != null) |
|
LSczcdydFeatureclassAPI.CloseFeatureClass(); |
|
if (CZCDLTBFeatureClass != null) |
|
CZCDLTBFeatureClass.CloseFeatureClass(); |
|
//if (pFeatureClass_4 != null) |
|
// pFeatureClass_4.CloseFeatureClass(); |
|
if (pFeatureCursor != null) |
|
Marshal.ReleaseComObject(pFeatureCursor); |
|
if (pInsertCursor != null) |
|
Marshal.ReleaseComObject(pInsertCursor); |
|
if (czcdydFeatureClassAPI != null) |
|
czcdydFeatureClassAPI.CloseFeatureClass(); |
|
if (dltbFeatureClassAPI != null) |
|
dltbFeatureClassAPI.CloseFeatureClass(); |
|
if (Schemeworkspace != null) |
|
Schemeworkspace.CloseWorkspace(); |
|
if (Tempworkspace != null) |
|
Tempworkspace.CloseWorkspace(); |
|
if (pOutWorkFactory != null) |
|
Marshal.ReleaseComObject(pOutWorkFactory); |
|
if (outputWorkspaceFactory != null) |
|
Marshal.ReleaseComObject(outputWorkspaceFactory); |
|
} |
|
} |
|
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($"获取城镇村范围数据失败:{ex.Message}"); |
|
LogAPI.Debug(ex); |
|
} |
|
} |
|
private string GetMaxBSM(List<IFeatureClass> fcList) |
|
{ |
|
int xh = 0; |
|
string MaxBSM = ""; |
|
string leftStr = string.Empty; |
|
foreach (var fc in fcList) |
|
{ |
|
string BSM = string.Empty; |
|
int BSMIndex = fc.FindField("BSM"); |
|
if (BSMIndex == -1) return BSM; |
|
|
|
ITable table = (ITable)fc; |
|
// 创建一个ITableSort接口对象 |
|
ITableSort tableSort = new TableSortClass(); |
|
tableSort.Table = table; |
|
tableSort.Fields = "BSM"; |
|
tableSort.set_Ascending("BSM", false); |
|
tableSort.Sort(null); |
|
ICursor cursor = tableSort.Rows; |
|
IRow row = cursor.NextRow(); |
|
if (row != null) |
|
{ |
|
int maxBSM = 0; |
|
int currBSM = 0; |
|
string BSMStr = row.Value[BSMIndex].ToString(); |
|
if (BSMStr.Length != 18) return BSM; |
|
string subBSMStr = BSMStr.Substring(9); |
|
try |
|
{ |
|
currBSM = Convert.ToInt32(subBSMStr); |
|
} |
|
catch (Exception) |
|
{ |
|
return BSM; |
|
} |
|
if (currBSM > maxBSM) maxBSM = currBSM; |
|
|
|
if (BSMStr.Length != 18) return BSM; |
|
string maxStr = maxBSM.ToString(); |
|
int zeroNum = 9 - maxStr.Length; |
|
for (int i = 0; i < zeroNum; i++) |
|
{ |
|
maxStr = 0 + maxStr; |
|
} |
|
BSM = BSMStr.Substring(0, 9) + maxStr; |
|
} |
|
if (BSM.Length != 18) |
|
continue; |
|
int xh2 = Convert.ToInt32(BSM.Substring(10)); |
|
leftStr = BSM.Substring(0, 10); |
|
if (xh < xh2) |
|
{ |
|
xh = xh2; |
|
MaxBSM = BSM; |
|
} |
|
} |
|
return MaxBSM; |
|
|
|
} |
|
public static void DelectDir(string srcPath) |
|
{ |
|
try |
|
{ |
|
DirectoryInfo dir = new DirectoryInfo(srcPath); |
|
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录 |
|
foreach (FileSystemInfo i in fileinfo) |
|
{ |
|
if (i is DirectoryInfo) //判断是否文件夹 |
|
{ |
|
DirectoryInfo subdir = new DirectoryInfo(i.FullName); |
|
subdir.Delete(true); //删除子目录和文件 |
|
} |
|
else |
|
{ |
|
File.Delete(i.FullName); //删除指定文件 |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex + ":删除错误不处理"); |
|
} |
|
} |
|
|
|
private string GetTempPath() |
|
{ |
|
string path = string.Empty; |
|
try |
|
{ |
|
string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\城镇村用地变更临时数据"; |
|
if (!System.IO.Directory.Exists(gdbFolder)) |
|
{ |
|
System.IO.Directory.CreateDirectory(gdbFolder); |
|
} |
|
try |
|
{ |
|
DelectDir(gdbFolder);//能删除就删除 删除报错不处理 |
|
} |
|
catch |
|
{ } |
|
string mdbFileName = Guid.NewGuid().ToString() + ".gdb"; |
|
path = System.IO.Path.Combine(gdbFolder, mdbFileName); |
|
var TempGDBPath = SysAppPath.GetTemplatePath() + "TempGDB.gdb";//模板 |
|
if (Directory.Exists(path)) |
|
{ |
|
Directory.Delete(path, true); |
|
} |
|
Directory.CreateDirectory(path); |
|
CopyDirectInfo(TempGDBPath, path); |
|
return path; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("提取城镇村等用地错误:" + ex.Message.ToString()); |
|
return path; |
|
} |
|
} |
|
private void CopyDirectInfo(string sourceDir, string toDir) |
|
{ |
|
if (!Directory.Exists(sourceDir)) |
|
{ |
|
throw new ApplicationException("未找到文件:" + sourceDir); |
|
} |
|
if (!Directory.Exists(toDir)) |
|
{ |
|
Directory.CreateDirectory(toDir); |
|
} |
|
DirectoryInfo directInfo = new DirectoryInfo(sourceDir); |
|
FileInfo[] filesInfos = directInfo.GetFiles(); |
|
foreach (FileInfo fileinfo in filesInfos) |
|
{ |
|
string fileName = fileinfo.Name; |
|
File.Copy(fileinfo.FullName, toDir + @"/" + fileName, true); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 获取全国区县代码字典 |
|
/// </summary> |
|
/// <returns></returns> |
|
public static List<DataDicTionary> GetXZQDic() |
|
{ |
|
List<DataDicTionary> result = new List<DataDicTionary>(); |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
string systemPath = SysAppPath.GetDataBasePath() + "System.mdb"; |
|
if (System.IO.File.Exists(systemPath)) |
|
{ |
|
string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection"); |
|
connStr = string.Format(connStr, systemPath); |
|
rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess); |
|
string strSQL = "select OBJECTID AS ID, XZQ AS CODE,XZQMC AS NAME from XZQ"; |
|
DataTable dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true); |
|
if (dt != null) |
|
{ |
|
result = TBToList.ToList<DataDicTionary>(dt); |
|
foreach (var item in result) |
|
{ |
|
item.DisplayName = item.CODE + "-" + item.NAME; |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
return result; |
|
} |
|
|
|
public IFeatureWorkspace GetGdbWorkspace(string pPathName) |
|
{ |
|
try |
|
{ |
|
IWorkspaceFactory factoryGdb = new FileGDBWorkspaceFactoryClass(); |
|
IWorkspace worckspace = factoryGdb.OpenFromFile(pPathName, 0); |
|
return worckspace as IFeatureWorkspace; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
return null; |
|
} |
|
} |
|
|
|
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; |
|
|
|
|
|
//Validate the field names because you are converting between different workspace types. |
|
IFieldChecker fieldChecker = new FieldCheckerClass(); |
|
IFields targetFeatureClassFields = pInTable.Fields; |
|
IFields sourceFeatureClassFields = pInTable.Fields; |
|
IEnumFieldError enumFieldError; |
|
|
|
|
|
// Most importantly set the input and validate workspaces! |
|
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; |
|
} |
|
} |
|
|
|
public class PCModel |
|
{ |
|
public string BGQBSM { get; set; } |
|
public string BGHBSM { get; set; } |
|
public double BGHMJ { get; set; } |
|
public double KZMJ { get; set; } |
|
//public Dictionary<int, double> GCData { get; set; } |
|
public List<GCMJModel> GCData { get; set; } |
|
public PCModel() |
|
{ |
|
GCData = new List<GCMJModel>(); |
|
} |
|
public void PC() |
|
{ |
|
//IOrderedEnumerable<KeyValuePair<int, double>> GCData2 = GCData.OrderByDescending(e => e.Value); |
|
//GCData = new Dictionary<int, double>(); |
|
//foreach (var item in GCData2) |
|
//{ |
|
// GCData.Add(item.Key, item.Value); |
|
//} |
|
GCData = GCData.OrderByDescending(o => o.MJ).ToList(); |
|
double zmj = GCData.Sum(s => s.MJ); |
|
double mjc = Math.Round(zmj - KZMJ, 2); |
|
if (Math.Round(mjc, 2) == 0) |
|
{ |
|
return; |
|
} |
|
int num = 0; |
|
//平差 |
|
while (Math.Round(mjc, 2) != 0 && num < 10) |
|
{ |
|
num++; |
|
int tpsm = (int)(Math.Abs(Math.Round(mjc, 2)) / 0.01); |
|
int e = tpsm / GCData.Count; |
|
int f = tpsm % GCData.Count; |
|
if (f != 0) |
|
{ |
|
double tpmj = (e + 1) * 0.01; |
|
for (int j = 0; j < f; j++) |
|
{ |
|
if (mjc < 0) |
|
GCData[j].MJ = GCData[j].MJ + tpmj; |
|
else if (GCData[j].MJ > 0.01) |
|
GCData[j].MJ = GCData[j].MJ - tpmj; |
|
} |
|
} |
|
if (e != 0) |
|
{ |
|
double tpmj = e * 0.01; |
|
for (int j = f; j < GCData.Count; j++) |
|
{ |
|
if (mjc < 0) |
|
GCData[j].MJ = GCData[j].MJ + tpmj; |
|
else if (GCData[j].MJ > 0.01) |
|
GCData[j].MJ = GCData[j].MJ - tpmj; |
|
} |
|
} |
|
zmj = GCData.Sum(s => s.MJ); |
|
mjc = Math.Round(zmj - KZMJ, 2); |
|
//mjc = Math.Round(shpList.Sum(s => s.MJ), 2) - pKZMJ; |
|
} |
|
} |
|
public void PC2() |
|
{ |
|
//IOrderedEnumerable<KeyValuePair<int, double>> GCData2 = GCData.OrderByDescending(e => e.Value); |
|
//GCData = new Dictionary<int, double>(); |
|
//foreach (var item in GCData2) |
|
//{ |
|
// GCData.Add(item.Key, item.Value); |
|
//} |
|
GCData = GCData.OrderByDescending(o => o.MJ).ToList(); |
|
double zmj = GCData.Sum(s => s.MJ); |
|
double mjc = Math.Round(zmj - KZMJ, 2); |
|
if (Math.Round(mjc, 2) == 0 || (zmj == 0 && mjc < 0)) |
|
{ |
|
return; |
|
} |
|
int num = 0; |
|
while (Math.Round(mjc, 2) != 0 && num < 10) |
|
{ |
|
foreach (var item in GCData) |
|
{ |
|
if (Math.Round(mjc, 2) == 0) break; |
|
if (mjc < 0) |
|
{ |
|
if (item.MJ <= 0.01) continue; |
|
item.MJ = Math.Round(item.MJ + 0.01, 2); |
|
zmj = GCData.Sum(s => s.MJ); |
|
mjc = Math.Round(zmj - KZMJ, 2); |
|
} |
|
else |
|
{ |
|
if (item.MJ <= 0.01) continue; |
|
item.MJ = Math.Round(item.MJ - 0.01, 2); |
|
zmj = GCData.Sum(s => s.MJ); |
|
mjc = Math.Round(zmj - KZMJ, 2); |
|
} |
|
} |
|
} |
|
////平差 |
|
//while (Math.Round(mjc, 2) != 0 && num < 10) |
|
//{ |
|
// num++; |
|
// int tpsm = (int)(Math.Abs(Math.Round(mjc, 2)) / (double)0.01); |
|
// int e = tpsm / GCData.Count; |
|
// int f = tpsm % GCData.Count; |
|
// if (f != 0) |
|
// { |
|
// double tpmj = (e + 1) * 0.01; |
|
// for (int j = 0; j < f; j++) |
|
// { |
|
// if (mjc < 0) |
|
// GCData[j].MJ = GCData[j].MJ + tpmj; |
|
// else if (GCData[j].MJ > 0.01) |
|
// GCData[j].MJ = GCData[j].MJ - tpmj; |
|
// } |
|
// } |
|
// if (e != 0) |
|
// { |
|
// double tpmj = e * 0.01; |
|
// for (int j = f; j < GCData.Count; j++) |
|
// { |
|
// if (mjc < 0) |
|
// GCData[j].MJ = GCData[j].MJ + tpmj; |
|
// else if (GCData[j].MJ > 0.01) |
|
// GCData[j].MJ = GCData[j].MJ - tpmj; |
|
// } |
|
// } |
|
// zmj = GCData.Sum(s => s.MJ); |
|
// mjc = Math.Round(zmj - KZMJ, 2); |
|
// //mjc = Math.Round(shpList.Sum(s => s.MJ), 2) - pKZMJ; |
|
//} |
|
} |
|
} |
|
|
|
public class GCMJModel |
|
{ |
|
public int OID { get; set; } |
|
public double MJ { get; set; } |
|
} |
|
public class CZC_Param |
|
{ |
|
public IFeatureLayer GXCZCLayer { get; set; } |
|
public IFeatureLayer GXGCCZCLayer { get; set; } |
|
public IFeatureLayer GXTBLayer { get; set; } |
|
public IFeatureLayer JCCZCLayer { get; set; } |
|
public IFeatureLayer JCTBLayer { get; set; } |
|
public IFeatureLayer BGTBLayer { get; set; } |
|
|
|
} |
|
} |
|
}
|
|
|