//using ESRI.ArcGIS.AnalysisTools; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.DataSourcesGDB; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Geoprocessing; using ESRI.ArcGIS.Geoprocessor; using KGIS.Framework.AE; using KGIS.Framework.AE.Enum; //using KGIS.Framework.AE.GPHelper; using KGIS.Framework.AE.ExtensionMethod; using KGIS.Framework.DBOperator; //using KGIS.Framework.Maps; using KGIS.Framework.Platform; using KGIS.Framework.Utils; using KGIS.Framework.Utils.ExtensionMethod; using KGIS.Framework.Utils.Helper; using Kingo.PluginServiceInterface; //using KUI.Windows; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Runtime.InteropServices; using Kingo.PluginServiceInterface.Model; using ESRI.ArcGIS.AnalysisTools; using KGIS.Framework.ThreadManager; using KGIS.Framework.AE.GPHelper; using ESRI.ArcGIS.esriSystem; //using IDEParameter; namespace IDGForNDBG { public class XZQ_IDGHelper : BaseIDG { public string IDataChangeName { get => "XZQ_IDGHelper"; } private string TempGDBPath = string.Empty; private string TempDBPath = string.Empty; private string TempDir = string.Empty; IDGParameter IDGParm = null; public void Execute(IDGParameter pParm) { ThreadManager.Instance.QueueUserWorkItem(new System.Threading.WaitCallback(ExeXZQ), pParm); //ExeXZQ(pParm); } public void ExeXZQ(object obj) { IFeatureCursor _Cursor = null; IFeature f = null; IQueryFilter _Filter = null; IWorkspaceAPI _WsAPI = null; try { Kingo.ThreadManager.TaskParameter taskParm = obj as Kingo.ThreadManager.TaskParameter; IDGParameter Parm = taskParm.Data as IDGParameter; //IDGParameter Parm = obj as IDGParameter; IDGParm = Parm; DateTime StartTime = DateTime.Now; Console.WriteLine("Log:正在进行行政区数据提取,请稍候..."); GPParamClass paramClass = new GPParamClass(); TempDir = CreateTempDB("XZQ"); TempGDBPath = System.IO.Path.Combine(TempDir, "TempGDB.gdb"); TempDBPath = TempDir + @"\Temp" + ".sqlite"; DBLayerSourceHelper layerSourceHelper = OpenDB(Parm); IRDBHelper rdbHelper = null; List qsDic = null; try { rdbHelper = RDBFactory.CreateDbHelper(System.IO.Path.Combine(Parm.PrjInfo.ProjDir, "BGTJ.sqlite"), DatabaseType.SQLite); DataTable dicDt = rdbHelper.ExecuteDatatable("Dic", string.Format("SELECT * from Sys_Dicdetail where OWNERDIC=(select id from Sys_DicManage where ALIASNAME='QSDM')"), true); qsDic = KGIS.Framework.Utils.Utility.TBToList.ToList(dicDt);// Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM); } catch (Exception ex) { Console.WriteLine("Err:获取权属字典失败_行政区!" + ex.Message); LogAPI.Debug(ex); } finally { if (rdbHelper != null) rdbHelper.DisConnect(); } IFeatureLayer tempjcXzqLayer = layerSourceHelper.JcXzqLayer; string HRXZQ = Parm.PrjInfo.DR_XZQPath; if (!string.IsNullOrWhiteSpace(HRXZQ)) { IWorkspaceAPI hrWsAPI = null; IFeatureClassAPI hrFcAPI = null; IFeatureLayer hrXZQLayer = null; if (HRXZQ.ToLower().Contains(".gdb")) { string hr_dbPath = HRXZQ.Substring(0, HRXZQ.ToLower().IndexOf(".gdb")); hr_dbPath = hr_dbPath + ".gdb"; hrWsAPI = new WorkspaceAPI(hr_dbPath, WorkspaceTypeEnum.GDBFile, true); FileInfo fInfo = new FileInfo(HRXZQ); hrFcAPI = hrWsAPI.OpenFeatureClass(fInfo.Name); hrXZQLayer = new FeatureLayerClass() { FeatureClass = hrFcAPI.FeatureClass }; } else if (HRXZQ.ToLower().Contains(".shp")) { FileInfo fInfo = new FileInfo(HRXZQ); Console.WriteLine("Log:正在加载行政区数据" + fInfo.Name); IWorkspaceFactory pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(fInfo.DirectoryName, 0); hrWsAPI = new WorkspaceAPI(pWorkspace); hrFcAPI = hrWsAPI.OpenFeatureClass2(fInfo.Name.Split('.')[0]); hrXZQLayer = new FeatureLayerClass() { FeatureClass = hrFcAPI.FeatureClass }; } GPParamClass gPParamClass = new GPParamClass(); gPParamClass.FirstFeatureLayer = layerSourceHelper.JcXzqLayer; gPParamClass.SecondFeatureLayer = hrXZQLayer; //gPParamClass.TempGDBPath = TempGDBPath; gPParamClass.IsGetOutPutFeature = true; gPParamClass.GPType = EnumGPType.Erase; //gPParamClass.FcName = "CJDCQ"; gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "XZQ"); GPHelper.Instance.ExeGPForProces(gPParamClass, ref tempjcXzqLayer); hrFcAPI.FcToFc(tempjcXzqLayer.FeatureClass, null, false); tempjcXzqLayer.Name = "行政区"; } IFeatureLayer ptempLayer = null; GPParamClass gPParamClass2 = new GPParamClass(); gPParamClass2.FirstFeatureLayer = tempjcXzqLayer; gPParamClass2.GPType = EnumGPType.Default; GPHelper.Instance.ExeGPForProces(gPParamClass2, ref ptempLayer); Console.WriteLine("Log:正在处理行政区数据"); IVariantArray GPParam = new VarArrayClass(); GPParam.Add(layerSourceHelper.GxgcTBLayer); GPParam.Add(tempjcXzqLayer); GPParam.Add(layerSourceHelper.NmTbLayer); GPParam.Add(TempGDBPath); GPParam.Add(TempDBPath); GPParam.Add("XZQBG"); GPHelper.Instance.ExeGp(GPParam); _WsAPI = new WorkspaceAPI(TempGDBPath, WorkspaceTypeEnum.GDBFile, true); IFeatureClassAPI GcFcAPI = _WsAPI.OpenFeatureClass("XZQGXGC"); IFeatureLayer tempGxGcLayer = new FeatureLayerClass() { FeatureClass = GcFcAPI.FeatureClass }; Console.WriteLine("Log:正在生成行政区更新过程数据"); rdbHelper = RDBFactory.CreateDbHelper(TempDBPath, DatabaseType.SQLite); DataTable tempDt = rdbHelper.ExecuteDatatable("temp", string.Format("select * from XZQGXGC"), true); if (tempDt != null) { int idxXZQMC_1 = tempGxGcLayer.FeatureClass.FindField("XZQMC_1"); foreach (DataRow dr in tempDt.Rows) { if (!(qsDic != null && qsDic.Count > 0)) continue; string xzqdm = dr["XZQDM_1"].ToTrim(); string xzqmc = dr["XZQMC_1"].ToTrim(); if (string.IsNullOrWhiteSpace(xzqmc)) { DataDicTionary dic = qsDic.FirstOrDefault(d => d.CODE == xzqdm); if (dic != null) { xzqmc = dic.NAME; } int oid = dr["OBJECTID"].ToInt(); rdbHelper.ExecuteSQL($"update XZQGXGC set XZQMC_1='{xzqmc}' where OBJECTID={oid}"); if (idxXZQMC_1 != -1) { IFeature tempF = tempGxGcLayer.FeatureClass.GetFeature(oid); tempF.Value[idxXZQMC_1] = xzqmc; tempF.Store(); } } } } rdbHelper.ExecuteSQL(@"ALTER TABLE XZQGXGC ADD COLUMN xzqtzlx VARCHAR(2);"); rdbHelper.ExecuteSQL(@"update XZQGXGC set xzqtzlx='2',XZQDM_1='',XZQMC_1='',mssm_1='',hdmc_1='' where objectid in ( select FID_XZQGXGC from xzqgxgc_dltbnm where xzqtzlx=2 group by FID_XZQGXGC )"); rdbHelper.ExecuteSQL(@"update XZQGXGC set xzqtzlx='3' where objectid in ( select FID_XZQGXGC from xzqgxgc_dltbnm where xzqtzlx=3 group by FID_XZQGXGC )"); rdbHelper.ExecuteSQL("update XZQGXGC set bgxw='1' where XZQDM != XZQDM_1 or XZQMC != XZQMC_1 or mssm != mssm_1 or IfNull(hdmc,'') != IfNull(hdmc_1,'')"); //rdbHelper.ExecuteSQL("update XZQGXGC set bgxw='2' where FID_XZQGX in (select FID_XZQGX from XZQGXGC group by FID_XZQGX HAVING count(1)>1)"); //rdbHelper.ExecuteSQL("update XZQGXGC set bgxw='2' where FID_XZQ in (select FID_XZQ from XZQGXGC group by FID_XZQ HAVING count(1)>1)"); rdbHelper.ExecuteSQL("update XZQGXGC set bgxw='2' where FID_XZQGX in (select FID_XZQGX from XZQGXGC group by FID_XZQGX HAVING count(1)>1) or FID_XZQ in (select FID_XZQ from XZQGXGC group by FID_XZQ HAVING count(1)>1)"); rdbHelper.ExecuteSQL("update XZQGXGC set bgxw='0' where bgxw is null and XZQDM = XZQDM_1 and XZQMC = XZQMC_1 and mssm = mssm_1 and IfNull(hdmc,'') = IfNull(hdmc_1,'')"); rdbHelper.ExecuteSQL("update XZQGXGC set bgxw='3' where XZQTZLX='3' and FID_XZQ=-1"); DataTable gcDt = rdbHelper.ExecuteDatatable("Gc", string.Format("select objectid,FID_XZQGX,bgxw,xzqdm,xzqdm_1,mssm,mssm_1,XZQTZLX from XZQGXGC"), true); Dictionary delOIDs = new Dictionary(); Dictionary msOIDs = new Dictionary(); Dictionary BgxwList = new Dictionary(); List listBGDM = new List(); if (gcDt != null && gcDt.Rows.Count > 0) { foreach (DataRow dr in gcDt.Rows) { string strXZQTZLX = dr["XZQTZLX"].ToTrim(); string strBgxw = dr["BGXW"].ToTrim(); int oid = dr["OBJECTID"].ToInt(); int gxOID = dr["FID_XZQGX"].ToInt(); if (strXZQTZLX == "2" || strXZQTZLX == "4") { msOIDs.Add(oid, gxOID); BgxwList.Add(oid, strBgxw); } else if (strBgxw == "0") { delOIDs.Add(oid, dr["FID_XZQGX"].ToInt()); } else { BgxwList.Add(oid, strBgxw); string bgqdm = dr["XZQDM"].ToTrim() + "_" + dr["MSSM"].ToTrim(); string bghdm = dr["XZQDM_1"].ToTrim() + "_" + dr["MSSM_1"].ToTrim(); if (!listBGDM.Contains(bgqdm)) listBGDM.Add(bgqdm); if (!listBGDM.Contains(bghdm)) listBGDM.Add(bghdm); } } } _Filter = new QueryFilterClass(); _Filter.SubFields = "OBJECTID,BGXW,XZQDM,XZQDM_1,MSSM,MSSM_1,XZQMC_1,HDMC_1"; _Cursor = tempGxGcLayer.FeatureClass.Update(_Filter, true); int idx = tempGxGcLayer.FeatureClass.FindField("BGXW"); int idxBGQDM = tempGxGcLayer.FeatureClass.FindField("XZQDM"); int idxBGQMSSM = tempGxGcLayer.FeatureClass.FindField("MSSM"); int idxBGHDM = tempGxGcLayer.FeatureClass.FindField("XZQDM_1"); int idxBGHMSSM = tempGxGcLayer.FeatureClass.FindField("MSSM_1"); int idxBGHZLDWMC = tempGxGcLayer.FeatureClass.FindField("XZQMC_1"); int idxBGHHDMC = tempGxGcLayer.FeatureClass.FindField("HDMC_1"); while ((f = _Cursor.NextFeature()) != null) { string bgqdm = f.Value[idxBGQDM].ToTrim() + "_" + f.Value[idxBGQMSSM].ToTrim(); string bghdm = f.Value[idxBGHDM].ToTrim() + "_" + f.Value[idxBGHMSSM].ToTrim(); if (msOIDs.ContainsKey(f.OID)) { if (BgxwList.ContainsKey(f.OID)) f.Value[idx] = BgxwList[f.OID]; else f.Value[idx] = "1"; f.Value[idxBGHDM] = ""; f.Value[idxBGHMSSM] = ""; f.Value[idxBGHZLDWMC] = ""; f.Value[idxBGHHDMC] = ""; } else if (delOIDs.ContainsKey(f.OID) && !listBGDM.Contains(bgqdm) && !listBGDM.Contains(bghdm)) f.Value[idx] = "0"; else if (BgxwList.ContainsKey(f.OID)) f.Value[idx] = BgxwList[f.OID]; else f.Value[idx] = "1"; _Cursor.UpdateFeature(f); } _Cursor.Flush(); _Filter = new QueryFilterClass(); _Filter.WhereClause = "BGXW = '0'"; (tempGxGcLayer.FeatureClass as ITable).DeleteSearchedRows(_Filter); IWorkspaceAPI wsAPI = new WorkspaceAPI(TempGDBPath, WorkspaceTypeEnum.GDBFile); IFeatureClassAPI fcAPI = wsAPI.OpenFeatureClass("XZQGX"); _Filter.WhereClause = ""; _Cursor = fcAPI.FeatureClass.Update(_Filter, true); idx = fcAPI.FeatureClass.FindField("HDMC"); int idxXZQDM = fcAPI.FeatureClass.FindField("XZQDM"); int idxMSSM = fcAPI.FeatureClass.FindField("MSSM"); while ((f = _Cursor.NextFeature()) != null) { string xzqdm = f.Value[idxXZQDM].ToTrim() + "_" + f.Value[idxMSSM].ToTrim(); if ((delOIDs.ContainsValue(f.OID) && !listBGDM.Contains(xzqdm)) || msOIDs.ContainsValue(f.OID)) { f.Value[idx] = "-1"; _Cursor.UpdateFeature(f); } } _Cursor.Flush(); _Filter.WhereClause = "HDMC = '-1'"; (fcAPI.FeatureClass as ITable).DeleteSearchedRows(_Filter); DataTable dtBGMJ = rdbHelper.ExecuteDatatable("bgmj", "SELECT FID_XZQGXGC,FID_DLTB_NMK,TBMJ FROM XZQGXGC_DLTBNM", true); Dictionary DicBGMJs = new Dictionary(); if (dtBGMJ != null) { foreach (DataRow dr in dtBGMJ.Rows) { int oid = dr["FID_XZQGXGC"].ToInt(); double area = dr["TBMJ"].ToDouble(2); if (area < 0.01) continue; if (DicBGMJs.ContainsKey(oid)) { DicBGMJs[oid] = (DicBGMJs[oid] + area).ToDouble(2); } else { DicBGMJs.Add(oid, area); } } } DataTable dtBGHMJ = rdbHelper.ExecuteDatatable("BGHMJ", "SELECT XZQDM_1,XZQMC_1,MSSM_1,FID_DLTB_NMK,TBMJ FROM XZQGXGC_DLTBNM", true); Dictionary DicBGHMJs = new Dictionary(); Dictionary DicTBMJs = new Dictionary(); if (dtBGHMJ != null) { foreach (DataRow dr in dtBGHMJ.Rows) { string dm = dr["XZQDM_1"].ToTrim(); string mc = dr["XZQMC_1"].ToTrim(); string mssm = dr["MSSM_1"].ToTrim(); if (string.IsNullOrWhiteSpace(mc) && qsDic != null) { DataDicTionary dic = qsDic.FirstOrDefault(d => d.CODE == dm); if (dic != null) { mc = dic.NAME; } } string zl = $"{dm}_{mc}_{mssm}"; int nmOid = dr["FID_DLTB_NMK"].ToInt(); double area = dr["TBMJ"].ToDouble(2); if (area < 0.01) continue; if (DicTBMJs.ContainsKey(nmOid)) { continue; } else { DicTBMJs.Add(nmOid, area); } if (DicBGHMJs.ContainsKey(zl)) { DicBGHMJs[zl] = (DicBGHMJs[zl] + area).ToDouble(2); } else { DicBGHMJs.Add(zl, area); } } } //(layerSourceHelper.GxgcXzqLayer.FeatureClass as ITable).DeleteSearchedRows(null); (layerSourceHelper.GxgcXzqLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL("Delete From XZQGXGC WHERE 1=1"); Dictionary GXAttribute = new Dictionary(); GXGCFcToFc(tempGxGcLayer.FeatureClass, layerSourceHelper.GxgcXzqLayer.FeatureClass, DicBGMJs, DicBGHMJs, Parm.PrjInfo.CODE, qsDic, ref GXAttribute, layerSourceHelper); Console.WriteLine("Log:正在生成行政区更新数据"); //(layerSourceHelper.GxXzqLayer.FeatureClass as ITable).DeleteSearchedRows(null); (layerSourceHelper.GxXzqLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL("Delete From XZQGX WHERE 1=1"); GXFcToFc(fcAPI.FeatureClass, layerSourceHelper.GxXzqLayer.FeatureClass, GXAttribute, qsDic); _Filter = new QueryFilterClass(); //_Filter.WhereClause = "BGXW<>'1'"; if (layerSourceHelper.GxgcXzqLayer.FeatureClass.FeatureCount(_Filter) > 0) { Console.WriteLine("Log:正在生成行政区界线更新数据"); XZQExtractExe(Parm, layerSourceHelper); } Console.WriteLine($"Log:行政区数据提取完成。耗时:{GetTime(StartTime)}"); } catch (Exception ex) { Console.WriteLine("Log:行政区数据提取失败"); Console.WriteLine("Log:行政区数据提取失败。" + ex.Message); Console.WriteLine("Log:行政区数据提取失败。" + ex.StackTrace); throw ex; } } public bool GXGCFcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, Dictionary pDicBGMJ, Dictionary pDicBGHMJ, string Code, List pQsDic, ref Dictionary pGxAttribure, DBLayerSourceHelper pDBLayerSourceHelper) { IFeatureCursor S_Cursor = null; IFeatureCursor T_Cursor = null; try { if (FeatureClass == null || pFc == null) return false; if (pGxAttribure == null) pGxAttribure = new Dictionary(); //获取对应关系 Dictionary dicField = new Dictionary(); Dictionary dicField1 = new Dictionary(); for (int i = 0; i < pFc.Fields.FieldCount; i++) { IField field = pFc.Fields.Field[i]; if (field.Name == pFc.ShapeFieldName || field.Name.Contains(pFc.ShapeFieldName) || field.Name == pFc.OIDFieldName || !field.Editable) continue; int index = -1; if (field.Name.Contains("BGQ")) { string fieldName = field.Name.Replace("BGQTB", "").Replace("BGQ", ""); if ("BGQTBBH,BGQTBMJ,BGQTBXHDM,BGQTBXHMC,BGQTBDLMJ".Contains(field.Name)) fieldName = field.Name.Replace("BGQ", ""); index = FeatureClass.Fields.FindField($"{fieldName}"); if (index == -1) index = FeatureClass.Fields.FindField(fieldName); } else if (field.Name.Contains("BGH")) { string fieldName = field.Name.Replace("BGHTB", "").Replace("BGH", ""); if ("BGHTBBH,BGHTBMJ,BGHTBXHDM,BGHTBXHMC,BGHTBDLMJ".Contains(field.Name)) fieldName = field.Name.Replace("BGH", ""); index = FeatureClass.Fields.FindField($"{fieldName}_1"); } else if (field.Name.ToUpper() == "BGXW") { index = FeatureClass.Fields.FindField(field.Name); } if (index == -1) continue; dicField.Add(i, index); string fName = field.Name.Replace("BGQTB", "").Replace("BGHTB", "").Replace("BGQ", "").Replace("BGH", ""); index = FeatureClass.Fields.FindField($"{fName}_1"); if ("BGQTBBH,BGQTBMJ,BGQTBXHDM,BGQTBXHMC,BGQTBDLMJ,BGHTBBH,BGHTBMJ,BGHTBXHDM,BGHTBXHMC,BGHTBDLMJ".Contains(field.Name)) fName = field.Name.Replace("BGH", "").Replace("BGQ", ""); index = FeatureClass.Fields.FindField(fName); if (index == -1) index = FeatureClass.Fields.FindField($"{fName}_1"); if (index == -1) continue; dicField1.Add(i, index); } (pFc as ITable).DeleteSearchedRows(null); string s = (pFc as FeatureClass).Workspace.PathName; IFeatureClassLoad pFclsLoad = pFc as IFeatureClassLoad; if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = true; //此处写编辑的代码 S_Cursor = FeatureClass.Search(null, true); IFeature f = null; T_Cursor = pFc.Insert(true); IFeatureBuffer buffer = pFc.CreateFeatureBuffer(); var iFID_DLTBBG = FeatureClass.FindField("FID_XZQGX"); var iFID_DLTB = FeatureClass.FindField("FID_XZQ"); var idxBGQBSM = FeatureClass.FindField("BSM"); var idxTempBGHDM = FeatureClass.FindField("XZQDM_1"); var ibgxw = pFc.FindField("BGXW"); var itbbgmj = pFc.FindField("BGMJ"); var ibsm = pFc.FindField("BSM"); var igxsj = pFc.FindField("GXSJ"); var idxBGHBSM = pFc.FindField("BGHBSM"); var idxZLDM = pFc.FindField("BGHXZQDM"); var idxZLMC = pFc.FindField("BGHXZQMC"); var idxMSSM = pFc.FindField("BGHMSSM"); var idxHDMC = pFc.FindField("BGHHDMC"); var idxBGHDCMJ = pFc.FindField("BGHDCMJ"); var tbbgmj = 0.00; int bsm = 1; string MaxBSM = string.Empty; if (string.IsNullOrWhiteSpace(MaxBSM)) MaxBSM = GetNewBSM(new List() { pDBLayerSourceHelper.JcXzqLayer.FeatureClass }); while ((f = S_Cursor.NextFeature()) != null) { if (pDicBGMJ.ContainsKey(f.OID)) { tbbgmj = pDicBGMJ[f.OID]; if (tbbgmj == 0) continue; } var FID_DLTBBG = f.Value[iFID_DLTBBG].ToString(); var FID_DLTB = f.Value[iFID_DLTB].ToString(); //var row = data_BSM.Select($"FID_DLTBBG={FID_DLTBBG} and FID_DLTB={FID_DLTB} "); //if (row == null || row.Length == 0) continue; buffer.Shape = f.ShapeCopy; if (FID_DLTBBG == "-1") { foreach (int item in dicField1.Keys)//被动变更的图斑 变更前后属性相同 { try { if (f.Value[dicField1[item]].ToString().Contains(" ") || f.Value[dicField1[item]] is DBNull) { buffer.Value[item] = f.Value[dicField1[item]].ToTrim(); } else { buffer.Value[item] = f.Value[dicField1[item]]; } } catch { buffer.Value[item] = f.Value[dicField1[item]]; } } } else { foreach (int item in dicField.Keys) { if (item == 57 || item == 58) { } try { buffer.Value[item] = f.Value[dicField[item]]; } catch { buffer.Value[item] = f.Value[dicField[item]]; } } } string xzqmc = buffer.Value[idxZLMC].ToTrim(); if (string.IsNullOrWhiteSpace(xzqmc) && pQsDic != null) { string xzqdm = buffer.Value[idxZLDM].ToTrim(); DataDicTionary dic = pQsDic.FirstOrDefault(d => d.CODE == xzqdm); if (dic != null) { xzqmc = dic.NAME; } buffer.Value[idxZLMC] = xzqmc; } if (pDicBGMJ.ContainsKey(f.OID)) tbbgmj = pDicBGMJ[f.OID]; buffer.Value[itbbgmj] = Math.Round(tbbgmj, 2);//图斑变更面积 buffer.Value[ibsm] = $"{Code}1211{(bsm++).ToString().PadLeft(8, '0')}"; buffer.Value[igxsj] = new DateTime(2023, 12, 31); string key = buffer.Value[idxZLDM].ToTrim() + "_" + buffer.Value[idxZLMC].ToTrim() + "_" + buffer.Value[idxMSSM].ToTrim(); if (pDicBGHMJ.ContainsKey(key)) { buffer.Value[idxBGHDCMJ] = pDicBGHMJ[key]; } string bgxw = buffer.Value[ibgxw].ToTrim(); string strTempBGHDM = f.Value[idxTempBGHDM].ToTrim(); if (string.IsNullOrWhiteSpace(strTempBGHDM)) { buffer.Value[idxBGHDCMJ] = 0; buffer.Value[idxBGHBSM] = ""; buffer.Value[idxZLDM] = ""; buffer.Value[idxZLMC] = ""; buffer.Value[idxMSSM] = ""; if (idxHDMC != -1) buffer.Value[idxHDMC] = ""; } if (bgxw == "1" && !string.IsNullOrWhiteSpace(strTempBGHDM)) { string attr = f.Value[idxBGQBSM].ToTrim() + "_" + buffer.Value[idxBGHDCMJ]; if (!pGxAttribure.ContainsKey(FID_DLTBBG.ToInt())) pGxAttribure.Add(FID_DLTBBG.ToInt(), attr); buffer.Value[idxBGHBSM] = f.Value[idxBGQBSM]; } string strBGHBSM = buffer.Value[idxBGHBSM].ToTrim(); if (((bgxw == "2" || bgxw == "4") && !string.IsNullOrWhiteSpace(strTempBGHDM)) || bgxw == "3" || (!strBGHBSM.StartsWith(IDGParm.PrjInfo.CODE) && !string.IsNullOrWhiteSpace(strTempBGHDM))) { string attr = string.Empty; string bghBSM = string.Empty; if (pGxAttribure.ContainsKey(FID_DLTBBG.ToInt())) { attr = pGxAttribure[FID_DLTBBG.ToInt()]; if (!attr.Split('_')[0].StartsWith(IDGParm.PrjInfo.CODE)) { string bsmPrefix = IDGParm.PrjInfo.CODE + MaxBSM.Substring(6, 4); int MaxNum = Convert.ToInt32(MaxBSM.Substring(9)); bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); pGxAttribure[FID_DLTBBG.ToInt()] = pGxAttribure[FID_DLTBBG.ToInt()].Replace(strBGHBSM, bghBSM); MaxBSM = bghBSM; //attr = bghBSM + "_" + buffer.Value[idxBGHDCMJ]; //pGxAttribure.Add(FID_DLTBBG.ToInt(), attr); } else { bghBSM = attr.Split('_')[0]; } //bghBSM = attr.Split('_')[0]; } else { string bsmPrefix = IDGParm.PrjInfo.CODE + MaxBSM.Substring(6, 4); int MaxNum = Convert.ToInt32(MaxBSM.Substring(9)); bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); MaxBSM = bghBSM; attr = bghBSM + "_" + buffer.Value[idxBGHDCMJ]; pGxAttribure.Add(FID_DLTBBG.ToInt(), attr); } buffer.Value[idxBGHBSM] = bghBSM; } T_Cursor.InsertFeature(buffer); } T_Cursor.Flush(); if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = false; return true; } catch (Exception ex) { throw ex; } } public bool GXFcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, Dictionary pGXAttribute, List pQsDic) { IFeatureCursor S_Cursor = null; IFeatureCursor T_Cursor = null; try { if (FeatureClass == null || pFc == null) return false; Dictionary dicField = new Dictionary(); int index = -1; for (int i = 0; i < pFc.Fields.FieldCount; i++) { IField field = pFc.Fields.Field[i]; if (field.Name == pFc.ShapeFieldName || field.Name.Contains(pFc.ShapeFieldName) || field.Name == pFc.OIDFieldName || !field.Editable) continue; index = FeatureClass.Fields.FindField(field.Name); if (index == -1) continue; dicField.Add(i, index); } IFeatureClassLoad pFclsLoad = pFc as IFeatureClassLoad; if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = true; //此处写编辑的代码 S_Cursor = FeatureClass.Search(null, true); IFeature f = null; T_Cursor = pFc.Insert(true); IFeatureBuffer buffer = pFc.CreateFeatureBuffer(); int idxBSM = pFc.FindField("BSM"); int idxYSDM = pFc.FindField("YSDM"); int idxXZQDM = pFc.FindField("XZQDM"); int idxXZQMC = pFc.FindField("XZQMC"); int idxDCMJ = pFc.FindField("DCMJ"); int idxJSMJ = pFc.FindField("JSMJ"); int idxGXSJ = pFc.FindField("GXSJ"); while ((f = S_Cursor.NextFeature()) != null) { buffer.Shape = f.ShapeCopy; foreach (int item in dicField.Keys) { buffer.Value[item] = f.Value[dicField[item]]; } if (pQsDic != null) { DataDicTionary dic = pQsDic.FirstOrDefault(d => d.CODE == buffer.Value[idxXZQDM].ToTrim()); if (dic != null) { buffer.Value[idxXZQMC] = dic.NAME; } } if (pGXAttribute != null && pGXAttribute.ContainsKey(f.OID)) { string[] attrs = pGXAttribute[f.OID].Split('_'); buffer.Value[idxBSM] = attrs[0]; buffer.Value[idxDCMJ] = attrs[1]; } buffer.Value[idxJSMJ] = f.ShapeCopy.GetEllipseArea(); buffer.Value[idxYSDM] = "1000600100"; if (idxGXSJ != -1) { buffer.Value[idxGXSJ] = new DateTime(2023, 12, 31); } T_Cursor.InsertFeature(buffer); } T_Cursor.Flush(); if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = false; return true; } catch (Exception) { throw; } } public DBLayerSourceHelper OpenDB(IDGParameter parm) { DBLayerSourceHelper result = new DBLayerSourceHelper(); 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); } 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"); result.BgWsAPI = new WorkspaceAPI(PathBgDB, WorkspaceTypeEnum.GDBFile); if (result.BgWsAPI.CurrentWorkspace == null) { Console.WriteLine("打开变更数据库失败!"); return result; } result.ZlWsAPI = new WorkspaceAPI(PathZLDB, WorkspaceTypeEnum.GDBFile); if (result.ZlWsAPI.CurrentWorkspace == null) { Console.WriteLine("打开增量数据库失败!"); return result; } result.NmWsAPI = new WorkspaceAPI(PathNMDB, WorkspaceTypeEnum.GDBFile); LayerCfg JCLayerInfo = layerInfo.Layers.FirstOrDefault(f => f.LayerName == "年初数据"); if (JCLayerInfo == null) { throw new Exception("Err:获取年初数据库失败!"); } List NcList = JCLayerInfo.GetAllItem(); //if (parm.ExeDLTB) //{ // LayerCfg _JcTBLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "地类图斑"); // _jcTbLayer = OpenLayer(_JcTBLayerInfo); // if (_jcTbLayer == null) // { // throw new Exception("Err:获取年初地类图斑数据失败!"); // } //} { LayerCfg _JcXzqLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "行政区"); result.JcXzqLayer = OpenLayer(_JcXzqLayerInfo); if (result.JcXzqLayer == null) throw new Exception("Err:获取年初行政区数据失败!"); LayerCfg _JcXzqJxLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "行政区界线"); result.JcXzqJxLayer = OpenLayer(_JcXzqJxLayerInfo); if (result.JcXzqJxLayer == null) throw new Exception("Err:获取年初行政区界线数据失败!"); result.GxXzqLayer = OpenLayer(result.ZlWsAPI, "XZQGX"); result.GxgcXzqLayer = OpenLayer(result.ZlWsAPI, "XZQGXGC"); result.GxXzqJxLayer = OpenLayer(result.ZlWsAPI, "XZQJXGX"); result.GxgcTBLayer = OpenLayer(result.ZlWsAPI, "DLTBGXGC"); if (result.NmTbLayer == null) result.NmTbLayer = OpenLayer(result.NmWsAPI, "DLTB_NMK"); } return result; } catch (Exception ex) { throw ex; } } #region 提取行政区界线 public void XZQExtractExe(IDGParameter pParm, DBLayerSourceHelper pLayerSourceHelper) { bool cb_XZQDMChange = false; //IFeatureClass XZQGXFeatureClass = null; //IFeatureClass XZQGXGCFeatureClass = null; //IFeatureLayer JCXZQFeatureLayer = null; //IFeatureLayer JCXZQJXFeatureLayer = null; //IFeatureClassAPI xzqgxgcfcAPI = null; //IFeatureLayer gx_xzqLayer = null; //IFeatureLayer gxgc_xzqLayer = null; //IFeatureLayer gx_xzqjxLayer = null; try { //if (_MapService == null) // _MapService = MapsManager.Instance.MapService; //gx_xzqLayer = GxXzqLayer; //gxgc_xzqLayer = GxgcXzqLayer; //gx_xzqjxLayer = GxXzqJxLayer; //XZQGXFeatureClass = gx_xzqLayer.FeatureClass;// _MapService.GetFeatureClassByName("XZQGX");//行政区更新层 //XZQGXGCFeatureClass = gxgc_xzqLayer.FeatureClass;// _MapService.GetFeatureClassByName("XZQGXGC");//行政区更新过程层 //JCXZQFeatureLayer = JcXzqLayer;// _MapService.GetFeatureLayerByLayerName("行政区");//基础行政区 //JCXZQJXFeatureLayer = JcXzqJxLayer;// _MapService.GetFeatureLayerByLayerName("行政区界线");//基础行政区界线 //if (XZQGXGCFeatureClass.FeatureCount(null) == 0) return; //xzqgxgcfcAPI = new FeatureClassAPI(XZQGXGCFeatureClass); //List xzqgxgcList = xzqgxgcfcAPI.QueryFeatures(null); //IFeature xzqGXGC = FeatureAPI.MergeFeature(xzqgxgcList); //if (xzqGXGC == null) //{ // LogAPI.Debug("行政区更新过程层数据为空!"); // return; //} //List features = FeatureAPI.Identify(xzqGXGC.ShapeCopy, JCXZQFeatureLayer); //IFeatureClassAPI tempxzqgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("XZQGX_TEMP", (pLayerSourceHelper.GxXzqLayer.FeatureClass as IGeoDataset).SpatialReference, pLayerSourceHelper.GxXzqLayer.FeatureClass.Fields); //tempxzqgxFeatureclassAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); //JCXZQInsertGX(features, tempxzqgxFeatureclassAPI.FeatureClass, null);//将基础村级调查区数据插入到更新过程层,变更前变更后的属性数据一致 //IFeatureClassAPI xzqgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("XZQGX", (pLayerSourceHelper.GxXzqLayer.FeatureClass as IGeoDataset).SpatialReference, pLayerSourceHelper.GxXzqLayer.FeatureClass.Fields); //xzqgxFeatureclassAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); //IFeatureClassAPI fcAPI = new FeatureClassAPI(pLayerSourceHelper.GxXzqLayer.FeatureClass); //fcAPI.FcToFc(xzqgxFeatureclassAPI.FeatureClass, null, false); //IQueryFilter filter = new QueryFilterClass(); //filter.WhereClause = string.Format(" BGHXZQDM is null or BGHXZQDM =''"); //XZQGXMSInsertGX(pLayerSourceHelper.GxgcXzqLayer.FeatureClass, xzqgxFeatureclassAPI.FeatureClass, filter); //IFeatureLayer xzqgxJCLayer = null; //GPParamClass gPParamClass = new GPParamClass(); //gPParamClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = tempxzqgxFeatureclassAPI.FeatureClass }; //gPParamClass.SecondFeatureLayer = new FeatureLayerClass() { FeatureClass = xzqgxFeatureclassAPI.FeatureClass }; //gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "XZQGX_JC"); //gPParamClass.IsGetOutPutFeature = true; //gPParamClass.GPType = EnumGPType.Erase; ////GeoprocessorHelper gpHelper = new GeoprocessorHelper(); //GPHelper.Instance.ExeGPForProces(gPParamClass, ref xzqgxJCLayer); //fcAPI = new FeatureClassAPI(xzqgxJCLayer.FeatureClass); //fcAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); //fcAPI = new FeatureClassAPI(xzqgxJCLayer.FeatureClass); //fcAPI.FcToFc(xzqgxFeatureclassAPI.FeatureClass, null, false); //filter = new QueryFilterClass(); //filter.WhereClause = string.Format("SHAPE_AREA<0.1"); //(xzqgxFeatureclassAPI.FeatureClass as ITable).DeleteSearchedRows(filter); //// 村级调查区更新过程要素转线 //IFeatureLayer xzqgxjxLayer = null; //gPParamClass = new GPParamClass(); //gPParamClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = xzqgxFeatureclassAPI.FeatureClass }; //gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "XZQGX_JX"); //gPParamClass.IsGetOutPutFeature = true; //gPParamClass.GPType = EnumGPType.PolygonToLine; //GPHelper.Instance.ExeGPForProces(gPParamClass, ref xzqgxjxLayer); //// 村级调查区更新过程界线取消线分割 //IFeatureLayer gxjxUnsplitLayer = null; //gPParamClass = new GPParamClass(); //gPParamClass.FirstFeatureLayer = xzqgxjxLayer; //gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "XZQGXJX_Unsplit"); //gPParamClass.IsGetOutPutFeature = true; //gPParamClass.ListDissolveFiledName = new List() { "LEFT_FID", "RIGHT_FID" }; //gPParamClass.GPType = EnumGPType.UnsplitLine; //GPHelper.Instance.ExeGPForProces(gPParamClass, ref gxjxUnsplitLayer); if (pLayerSourceHelper.GxgcXzqLayer.FeatureClass.FeatureCount(null) == 0) return; IVariantArray parameters = new VarArrayClass(); parameters.Add(pLayerSourceHelper.GxXzqLayer); parameters.Add(pLayerSourceHelper.GxgcXzqLayer); parameters.Add(pLayerSourceHelper.JcXzqLayer); parameters.Add(TempGDBPath); parameters.Add("XZQJX"); GPHelper.Instance.ExeGp(parameters); IWorkspaceAPI psTempWorkspaceAPI = new WorkspaceAPI(TempGDBPath, WorkspaceTypeEnum.GDBFile); IFeatureClassAPI xzqgxFeatureclassAPI = psTempWorkspaceAPI.OpenFeatureClass("GXTB"); IFeatureClassAPI gxjxUnsplitLayer = psTempWorkspaceAPI.OpenFeatureClass("XZQGXGCJX_Unsplit"); Dictionary xzqdmDic = new Dictionary(); Dictionary isjctbDic = new Dictionary(); int objectidIndex = xzqgxFeatureclassAPI.FeatureClass.Fields.FindField("OBJECTID"); int bghXZQDMIndex = xzqgxFeatureclassAPI.FeatureClass.Fields.FindField("XZQDM"); int bghMSSMIndex = xzqgxFeatureclassAPI.FeatureClass.Fields.FindField("MSSM"); int gxgcIndex = xzqgxFeatureclassAPI.FeatureClass.Fields.FindField("IsJCTB"); IFeatureCursor gxgcjxCursor = xzqgxFeatureclassAPI.FeatureClass.Search(null, true); IFeature gxgcFeature = null; while ((gxgcFeature = gxgcjxCursor.NextFeature()) != null) { if (objectidIndex == -1) continue; int objectid = int.Parse(gxgcFeature.Value[objectidIndex].ToString()); string strMSSM = string.Empty; if (bghMSSMIndex != -1) { strMSSM = gxgcFeature.Value[bghMSSMIndex].ToTrim(); } if (bghXZQDMIndex != -1) { string XZQDM = gxgcFeature.Value[bghXZQDMIndex].ToString() + "_" + strMSSM; if (objectid != 0) xzqdmDic.Add(objectid, XZQDM); } if (gxgcIndex != -1) { string jctb = gxgcFeature.Value[gxgcIndex].ToString(); if (objectid != 0) isjctbDic.Add(objectid, jctb); } Marshal.ReleaseComObject(gxgcFeature); } IFeatureClass XZQJXGXFeatureClass = pLayerSourceHelper.GxXzqJxLayer.FeatureClass;// gx_xzqjxLayer.FeatureClass;// _MapService.GetFeatureClassByName("XZQJXGX"); ITable table = XZQJXGXFeatureClass as ITable; table.DeleteSearchedRows(null); int leftidIndex = gxjxUnsplitLayer.FeatureClass.Fields.FindField("LEFT_FID"); int rightIndex = gxjxUnsplitLayer.FeatureClass.Fields.FindField("RIGHT_FID"); int shapeLengthIndex = gxjxUnsplitLayer.FeatureClass.Fields.FindField("SHAPE_LENGTH"); IFeatureCursor gxgcjxUnsplitCursor = gxjxUnsplitLayer.FeatureClass.Search(null, true); IFeature f = null; List JC_OID = new List(); List MS_OID = new List(); IFeatureCursor xzqgxCur = pLayerSourceHelper.GxXzqLayer.FeatureClass.Search(null, true); IFeature xzqgx = null; while ((xzqgx = xzqgxCur.NextFeature()) != null) { List jcjx_features = FeatureAPI.Identify2(xzqgx.ShapeCopy, pLayerSourceHelper.JcXzqJxLayer); foreach (var item in jcjx_features) { if (!MS_OID.Contains(item.OID)) MS_OID.Add(item.OID); } } while ((f = gxgcjxUnsplitCursor.NextFeature()) != null) { IPolyline line = f.ShapeCopy as IPolyline; IPoint p = line.FromPoint; List lines = FeatureAPI.Identify2(p, new FeatureLayerClass() { FeatureClass = gxjxUnsplitLayer.FeatureClass, SpatialReference = (gxjxUnsplitLayer.FeatureClass as IGeoDataset).SpatialReference }); if (lines.Count < 3) { foreach (var item in lines) { if (item.OID == f.OID) continue; try { IFeatureEdit edit = item as IFeatureEdit; edit.Split(p); } catch (Exception ex) { } } } } if (cb_XZQDMChange == true) { gxgcjxUnsplitCursor = pLayerSourceHelper.JcXzqJxLayer.FeatureClass.Search(null, true); while ((f = gxgcjxUnsplitCursor.NextFeature()) != null) { string jcjxlx2 = f.Value[f.Fields.FindField("JXLX")].ToString(); string jcjxxz2 = f.Value[f.Fields.FindField("JXXZ")].ToString(); InsertXZQGXFeature(f, 0, jcjxlx2, jcjxxz2, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); if (MS_OID.Contains(f.OID)) MS_OID.Remove(f.OID); } } gxgcjxUnsplitCursor = gxjxUnsplitLayer.FeatureClass.Search(null, true); while ((f = gxgcjxUnsplitCursor.NextFeature()) != null) { if (leftidIndex == -1 || rightIndex == -1) { continue; } if (f.OID == 13) { } List jcjx_features = FeatureAPI.Identify2(f.ShapeCopy, pLayerSourceHelper.JcXzqJxLayer); int leftID = int.Parse(f.Value[leftidIndex].ToString()); int rightID = int.Parse(f.Value[rightIndex].ToString()); double gxshapeLength = f.Value[shapeLengthIndex].ToDouble(2); string leftxzqdm = leftID == -1 ? "" : xzqdmDic[leftID]; string rightxzqdm = rightID == -1 ? "" : xzqdmDic[rightID]; string leftIsjctb = leftID == -1 ? "0" : isjctbDic[leftID]; string rightIsjctb = rightID == -1 ? "0" : isjctbDic[rightID]; string bghJXLX = string.Empty; if (!string.IsNullOrWhiteSpace(leftIsjctb) && !string.IsNullOrWhiteSpace(rightIsjctb) && jcjx_features.Count > 1) { foreach (var item in jcjx_features) { if (MS_OID.Contains(item.OID)) MS_OID.Remove(item.OID); } continue; } if (leftxzqdm.Replace("_", "").Length == rightxzqdm.Replace("_", "").Length) { if (leftxzqdm.Length < 6) { bghJXLX = ""; } else if (leftxzqdm.Substring(0, 6) != rightxzqdm.Substring(0, 6)) { //县界 bghJXLX = "650200"; } else if (leftxzqdm.Substring(0, 9) == rightxzqdm.Substring(0, 9)) { //乡镇界 bghJXLX = ""; } else { //乡镇界 bghJXLX = "660200"; } } else if (rightxzqdm.Contains("_01") || leftxzqdm.Contains("_01")) { bghJXLX = "250202"; } else if (rightxzqdm == "_" && leftxzqdm == "_") { bghJXLX = ""; } else { //县界 bghJXLX = "650200"; } if (cb_XZQDMChange == true) { InsertXZQGXFeature(f, 3, bghJXLX, "600001", pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); continue; } if (jcjx_features.Count > 1) { //相关基础界线标记删除,新生成的界线标记新增 foreach (var item in jcjx_features) { if (JC_OID.Contains(item.OID)) continue; JC_OID.Add(item.OID); string jcjxlx2 = item.Value[item.Fields.FindField("JXLX")].ToString(); string jcjxxz2 = item.Value[item.Fields.FindField("JXXZ")].ToString(); InsertXZQGXFeature(item, 0, jcjxlx2, jcjxxz2, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); if (MS_OID.Contains(item.OID)) MS_OID.Remove(item.OID); } if (!string.IsNullOrWhiteSpace(bghJXLX)) InsertXZQGXFeature(f, 3, bghJXLX, "600001", pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); continue; } if (jcjx_features.Count == 0) { //新生成的界线标记新增 InsertXZQGXFeature(f, 3, bghJXLX, "600001", pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); continue; } IFeature jcfeature = jcjx_features[0]; string jcjxlx = jcfeature.Value[jcfeature.Fields.FindField("JXLX")].ToString(); string jcjxxz = jcfeature.Value[jcfeature.Fields.FindField("JXXZ")].ToString(); double jcshapeLength = jcfeature.Value[jcfeature.Fields.FindField("SHAPE_LENGTH")].ToDouble(2); if (string.IsNullOrWhiteSpace(bghJXLX)) { if (!JC_OID.Contains(jcfeature.OID)) { JC_OID.Add(jcfeature.OID); InsertXZQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); if (MS_OID.Contains(jcfeature.OID)) MS_OID.Remove(jcfeature.OID); } continue; } if (gxshapeLength == jcshapeLength) { if (!string.IsNullOrWhiteSpace(leftIsjctb) && !string.IsNullOrWhiteSpace(rightIsjctb) && jcjxlx == bghJXLX) { continue; } //长度一样,表示界线图形为变化 if (bghJXLX == jcjxlx) { InsertXZQGXFeature(jcfeature, 4, jcjxlx, jcjxxz, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); if (MS_OID.Contains(jcfeature.OID)) MS_OID.Remove(jcfeature.OID); continue; } else { if (!JC_OID.Contains(jcfeature.OID)) { JC_OID.Add(jcfeature.OID); InsertXZQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); if (MS_OID.Contains(jcfeature.OID)) MS_OID.Remove(jcfeature.OID); } //相关基础界线标记删除,新生成的界线标记新增 InsertXZQGXFeature(f, 3, bghJXLX, jcjxxz, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); } } else { if (!JC_OID.Contains(jcfeature.OID)) { JC_OID.Add(jcfeature.OID); InsertXZQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); if (MS_OID.Contains(jcfeature.OID)) MS_OID.Remove(jcfeature.OID); } //相关基础界线标记删除,新生成的界线标记新增 InsertXZQGXFeature(f, 3, bghJXLX, jcjxxz, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); } } foreach (var item in MS_OID) { IFeature jcfeature = pLayerSourceHelper.JcXzqJxLayer.FeatureClass.GetFeature(item); string jcjxlx = jcfeature.Value[jcfeature.Fields.FindField("JXLX")].ToString(); string jcjxxz = jcfeature.Value[jcfeature.Fields.FindField("JXXZ")].ToString(); InsertXZQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcXzqJxLayer.FeatureClass, XZQJXGXFeatureClass); } } catch (Exception ex) { LogAPI.Debug("行政区数据提取发生异常!异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("异常信息结束"); } } private void JCXZQInsertGX(List jcfeatures, IFeatureClass gxfeatureClass, IQueryFilter pFilter) { IFeatureCursor T_Cursor = null; try { Dictionary fieldsDic = new Dictionary(); for (int i = 0; i < gxfeatureClass.Fields.FieldCount; i++) { IField field = gxfeatureClass.Fields.Field[i]; if (field.Name == gxfeatureClass.ShapeFieldName || field.Name.Contains(gxfeatureClass.ShapeFieldName) || field.Name == gxfeatureClass.OIDFieldName || !field.Editable) continue; int index = -1; index = jcfeatures[0].Fields.FindField(field.Name); if (index == -1) index = jcfeatures[0].Fields.FindField(field.AliasName); if (index == -1) continue; fieldsDic.Add(i, index); } if (fieldsDic.Count != 0) { IFeatureBuffer buffer = gxfeatureClass.CreateFeatureBuffer(); T_Cursor = gxfeatureClass.Insert(true); int gxgcIndex = gxfeatureClass.FindField("IsJCTB"); for (int i = 0; i < jcfeatures.Count; i++) { IFeature f = jcfeatures[i]; buffer.Shape = f.ShapeCopy; foreach (int item in fieldsDic.Keys) { if (string.IsNullOrWhiteSpace(f.Value[fieldsDic[item]].ToTrim())) buffer.Value[item] = DBNull.Value; buffer.Value[item] = f.Value[fieldsDic[item]]; } if (gxgcIndex != -1) { buffer.Value[gxgcIndex] = "1"; } T_Cursor.InsertFeature(buffer); } T_Cursor.Flush(); } } catch (Exception ex) { LogAPI.Debug("基础村级调查区向临时库村级调查区更新层插入数据失败:" + ex.Message); } } private void XZQGXMSInsertGX(IFeatureClass gxgcfeatureClass, IFeatureClass gxfeatureClass, IQueryFilter pFilter) { IFeatureCursor T_Cursor = null; IFeatureCursor S_Cursor = null; try { Dictionary fieldsDic = new Dictionary(); for (int i = 0; i < gxfeatureClass.Fields.FieldCount; i++) { IField field = gxfeatureClass.Fields.Field[i]; if (field.Name == gxfeatureClass.ShapeFieldName || field.Name.Contains(gxfeatureClass.ShapeFieldName) || field.Name == gxfeatureClass.OIDFieldName || !field.Editable) continue; int index = -1; string gxgcfield = "BGH" + field.Name; index = gxgcfeatureClass.Fields.FindField(gxgcfield); if (index == -1) continue; fieldsDic.Add(i, index); } if (fieldsDic.Count != 0) { IFeatureBuffer buffer = gxfeatureClass.CreateFeatureBuffer(); T_Cursor = gxfeatureClass.Insert(true); int gxgcIndex = gxfeatureClass.FindField("IsJCTB"); IFeature gxgcfeature = null; S_Cursor = gxgcfeatureClass.Search(pFilter, true); while ((gxgcfeature = S_Cursor.NextFeature()) != null) { buffer.Shape = gxgcfeature.ShapeCopy; foreach (int item in fieldsDic.Keys) { if (string.IsNullOrWhiteSpace(gxgcfeature.Value[fieldsDic[item]].ToTrim())) buffer.Value[item] = DBNull.Value; buffer.Value[item] = gxgcfeature.Value[fieldsDic[item]]; } T_Cursor.InsertFeature(buffer); Marshal.ReleaseComObject(gxgcfeature); } T_Cursor.Flush(); } } catch (Exception ex) { LogAPI.Debug("基础行政区向临时库行政区更新层插入数据失败:" + ex.Message); } } public void InsertXZQGXFeature(IFeature pGXJX, int BGXW, string JXLX, string JXXZ, IFeatureClass JC_XZQJX, IFeatureClass XZQJXGX) { IFeatureCursor gx_cursor = null; IFeatureBuffer gx_buffer = null; try { bool IsInsert = true; var Identify = FeatureAPI.Identify2(pGXJX.Shape, new FeatureLayer() { FeatureClass = XZQJXGX }); if (Identify.Count > 0) { foreach (var item in Identify) { if (FeatureAPI.GetEqual(item.ShapeCopy, pGXJX.Shape) && FeatureAPI.GetEqual(pGXJX.Shape, item.ShapeCopy) && BGXW != 3) { IsInsert = false; break; } } } if (IsInsert) { if (string.IsNullOrWhiteSpace(strXZQJXMaxBSM)) { strXZQJXMaxBSM = SetMaxBSM(JC_XZQJX, XZQJXGX); if (!strXZQJXMaxBSM.StartsWith(IDGParm.PrjInfo.CODE)) strXZQJXMaxBSM = IDGParm.PrjInfo.CODE + "1220" + "1".PadLeft(8, '0'); } else { string bsmPrefix = IDGParm.PrjInfo.CODE + strXZQJXMaxBSM.Substring(6, 4); int MaxNum = Convert.ToInt32(strXZQJXMaxBSM.Substring(9)); strXZQJXMaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); } gx_cursor = XZQJXGX.Insert(true); gx_buffer = XZQJXGX.CreateFeatureBuffer(); gx_buffer.Shape = pGXJX.Shape; gx_buffer.set_Value(gx_buffer.Fields.FindField("BSM"), BGXW == 3 ? strXZQJXMaxBSM : pGXJX.Value[pGXJX.Fields.FindField("BSM")]); gx_buffer.set_Value(gx_buffer.Fields.FindField("JXLX"), JXLX); gx_buffer.set_Value(gx_buffer.Fields.FindField("JXXZ"), JXXZ); gx_buffer.set_Value(gx_buffer.Fields.FindField("JXSM"), BGXW == 3 ? string.Empty : pGXJX.Value[pGXJX.Fields.FindField("JXSM")]); gx_buffer.set_Value(gx_buffer.Fields.FindField("BZ"), BGXW == 3 ? string.Empty : pGXJX.Value[pGXJX.Fields.FindField("BZ")]); gx_buffer.set_Value(gx_buffer.Fields.FindField("BGXW"), BGXW); gx_buffer.set_Value(gx_buffer.Fields.FindField("GXSJ"), new DateTime(2023, 12, 31)); gx_buffer.set_Value(gx_buffer.Fields.FindField("YSDM"), "1000600200"); gx_cursor.InsertFeature(gx_buffer); gx_cursor.Flush(); Marshal.ReleaseComObject(gx_buffer); } } catch (Exception ex) { LogAPI.Debug("写入村级调查区界线更新层数据时发生异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("异常信息结束"); } finally { if (gx_cursor != null) Marshal.ReleaseComObject(gx_cursor); if (gx_buffer != null) Marshal.ReleaseComObject(gx_buffer); } } private string strXZQJXMaxBSM = string.Empty; private string SetMaxBSM(IFeatureClass JC_XZQJX, IFeatureClass XZQJXGC) { var MaxBSM = GetMaxBSM(new List() { JC_XZQJX, XZQJXGC }); string bsmPrefix = IDGParm.PrjInfo.CODE + MaxBSM.Substring(6, 4); int MaxNum = Convert.ToInt32(MaxBSM.Substring(9)); MaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); return MaxBSM; } private string GetMaxBSM(List fcList) { int xh = 0; string MaxBSM = ""; string leftStr = string.Empty; foreach (var fc in fcList) { string BSM = string.Empty; int BSMIndex = fc.FindField("BSM"); if (BSMIndex == -1) return BSM; ITable table = (ITable)fc; // 创建一个ITableSort接口对象 ITableSort tableSort = new TableSortClass(); tableSort.Table = table; tableSort.Fields = "BSM"; tableSort.set_Ascending("BSM", false); tableSort.Sort(null); ICursor cursor = tableSort.Rows; IRow row = cursor.NextRow(); if (row != null) { int maxBSM = 0; int currBSM = 0; string BSMStr = row.Value[BSMIndex].ToString(); if (BSMStr.Length != 18) return BSM; string subBSMStr = BSMStr.Substring(9); try { currBSM = Convert.ToInt32(subBSMStr); } catch (Exception) { return BSM; } if (currBSM > maxBSM) maxBSM = currBSM; if (BSMStr.Length != 18) return BSM; string maxStr = maxBSM.ToString(); int zeroNum = 9 - maxStr.Length; for (int i = 0; i < zeroNum; i++) { maxStr = 0 + maxStr; } BSM = BSMStr.Substring(0, 9) + maxStr; } if (BSM.Length != 18) continue; int xh2 = Convert.ToInt32(BSM.Substring(10)); leftStr = BSM.Substring(0, 10); if (xh < xh2) { xh = xh2; MaxBSM = BSM; } } return MaxBSM; } #endregion #region DelectDir 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 + ":删除错误不处理"); } } #endregion #region 获取最新标识码 public string GetNewBSM(List fcList) { string result = string.Empty; int xh = 0; string leftStr = string.Empty; foreach (var item in fcList) { string MaxBSM = GetMaxBSM(item); if (MaxBSM.Length != 18) continue; int xh2 = Convert.ToInt32(MaxBSM.Substring(10)); leftStr = MaxBSM.Substring(0, 10); if (xh < xh2) xh = xh2; } xh++; if (string.IsNullOrWhiteSpace(leftStr)) leftStr = IDGParm.PrjInfo.CODE + "1210"; result = leftStr + xh.ToString().PadLeft(8, '0'); return result; } private string GetMaxBSM(IFeatureClass fc) { //System.Windows.Forms.Application.DoEvents(); string BSM = string.Empty; int BSMIndex = fc.FindField("BSM"); if (BSMIndex == -1) return BSM; ITable table = (ITable)fc; ITableSort tableSort = new TableSortClass(); tableSort.Table = table; tableSort.Fields = "BSM"; tableSort.set_Ascending("BSM", false); tableSort.Sort(null); ICursor cursor = tableSort.Rows; IRow row = cursor.NextRow(); if (row != null) { int maxBSM = 0; int currBSM = 0; string BSMStr = row.Value[BSMIndex].ToString(); if (BSMStr.Length != 18) return BSM; string subBSMStr = BSMStr.Substring(9); try { currBSM = Convert.ToInt32(subBSMStr); } catch (Exception) { return BSM; } if (currBSM > maxBSM) maxBSM = currBSM; if (BSMStr.Length != 18) return BSM; string maxStr = maxBSM.ToString(); int zeroNum = 9 - maxStr.Length; for (int i = 0; i < zeroNum; i++) { maxStr = 0 + maxStr; } BSM = BSMStr.Substring(0, 9) + maxStr; } return BSM; } #endregion } }