//using ESRI.ArcGIS.AnalysisTools; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.DataSourcesGDB; using ESRI.ArcGIS.esriSystem; 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.AE.GPHelper; using KGIS.Framework.DBOperator; using KGIS.Framework.Platform; using KGIS.Framework.ThreadManager; //using KGIS.Framework.Maps; using KGIS.Framework.Utils; using Kingo.PluginServiceInterface; using Kingo.PluginServiceInterface.Model; //using KUI.Windows; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Runtime.InteropServices; //using IDEParameter; namespace IDGForNDBG { public class CJDCQ_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(ExeCJDCQ), pParm, new System.Threading.WaitCallback(ComplateCallBack)); //ExeCJDCQ(pParm); } private DateTime StartTime = DateTime.Now; public void ComplateCallBack(object obj) { Console.WriteLine($"Log:村级调查区数据提取完成。耗时:{GetTime(StartTime)}"); } //string XZQCode = string.Empty; public void ExeCJDCQ(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; StartTime = DateTime.Now; Console.WriteLine("Log:正在进行村级调查区数据提取,请稍候..."); GPParamClass paramClass = new GPParamClass(); TempDir = CreateTempDB("CJDCQ"); 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=1"), 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 tempjcCjdcqLayer = layerSourceHelper.JcCjdcqLayer; string HRXZQ = Parm.PrjInfo.DR_CJDCQPath; if (!string.IsNullOrWhiteSpace(HRXZQ)) { IWorkspaceAPI hrWsAPI = null; IFeatureClassAPI hrFcAPI = null; IFeatureLayer hrCJDCQLayer = null; if (HRXZQ.ToLower().Contains(".gdb")) { string hr_dbPath = HRXZQ.Substring(0, HRXZQ.ToLower().IndexOf(".gdb")); hr_dbPath = hr_dbPath + ".gdb"; //Console.WriteLine(hr_dbPath); hrWsAPI = new WorkspaceAPI(hr_dbPath, WorkspaceTypeEnum.GDBFile); FileInfo fInfo = new FileInfo(HRXZQ); hrFcAPI = hrWsAPI.OpenFeatureClass(fInfo.Name); hrCJDCQLayer = 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]); hrCJDCQLayer = new FeatureLayerClass() { FeatureClass = hrFcAPI.FeatureClass }; } GPParamClass gPParamClass = new GPParamClass(); gPParamClass.FirstFeatureLayer = layerSourceHelper.JcCjdcqLayer; gPParamClass.SecondFeatureLayer = hrCJDCQLayer; //gPParamClass.TempGDBPath = TempGDBPath; gPParamClass.IsGetOutPutFeature = true; gPParamClass.GPType = EnumGPType.Erase; //gPParamClass.FcName = "CJDCQ"; gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "CJDCQ"); GPHelper.Instance.ExeGPForProces(gPParamClass, ref tempjcCjdcqLayer); hrFcAPI.FcToFc(tempjcCjdcqLayer.FeatureClass, null, false); tempjcCjdcqLayer.Name = "村级调查区"; } IFeatureLayer ptempLayer = null; GPParamClass gPParamClass2 = new GPParamClass(); gPParamClass2.FirstFeatureLayer = tempjcCjdcqLayer; gPParamClass2.GPType = EnumGPType.Default; GPHelper.Instance.ExeGPForProces(gPParamClass2, ref ptempLayer); IVariantArray GPParam = new VarArrayClass(); GPParam.Add(layerSourceHelper.GxgcTBLayer); GPParam.Add(tempjcCjdcqLayer); GPParam.Add(layerSourceHelper.NmTbLayer); GPParam.Add(TempGDBPath); GPParam.Add(TempDBPath); GPParam.Add("CJDCQBG"); Console.WriteLine("Log:正在处理村级调查区数据"); //GPHelper.Instance.ExeGPForProces(gPParamClass, ref tempGxGcLayer); GPHelper.Instance.ExeGp(GPParam); _WsAPI = new WorkspaceAPI(TempGDBPath, WorkspaceTypeEnum.GDBFile); IFeatureClassAPI GcFcAPI = _WsAPI.OpenFeatureClass("CJDCQGXGC"); IFeatureLayer tempGxGcLayer = new FeatureLayerClass() { FeatureClass = GcFcAPI.FeatureClass }; Console.WriteLine("Log:正在生成村级调查区更新过程数据"); rdbHelper = RDBFactory.CreateDbHelper(TempDBPath, DatabaseType.SQLite); rdbHelper.ExecuteSQL(@"ALTER TABLE cjdcqgxgc ADD COLUMN xzqtzlx VARCHAR(2);"); rdbHelper.ExecuteSQL(@"update cjdcqgxgc set xzqtzlx='2',zldwdm_1='',zldwmc_1='',mssm_1='',hdmc_1='' where objectid in ( select FID_CJDCQGXGC from cjdcqgxgc_dltbnm where xzqtzlx=2 group by FID_CJDCQGXGC )"); rdbHelper.ExecuteSQL(@"update cjdcqgxgc set xzqtzlx='3' where objectid in ( select FID_CJDCQGXGC from cjdcqgxgc_dltbnm where xzqtzlx=3 group by FID_CJDCQGXGC )"); rdbHelper.ExecuteSQL("update CJDCQGXGC set bgxw='1' where zldwdm != zldwdm_1 or zldwmc != zldwmc_1 or mssm != mssm_1 or IfNull(hdmc,'') != IfNull(hdmc_1,'')"); //rdbHelper.ExecuteSQL("update CJDCQGXGC set bgxw='2' where objectid in (select objectid from CJDCQGXGC group by FID_CJDCQGX HAVING count(1)>1)"); //rdbHelper.ExecuteSQL("update CJDCQGXGC set bgxw='2' where objectid in (select objectid from CJDCQGXGC group by FID_CJDCQ HAVING count(1)>1)"); rdbHelper.ExecuteSQL("update CJDCQGXGC set bgxw='2' where FID_CJDCQGX in (select FID_CJDCQGX from CJDCQGXGC group by FID_CJDCQGX HAVING count(1)>1) or FID_CJDCQ in (select FID_CJDCQ from CJDCQGXGC group by FID_CJDCQ HAVING count(1)>1)"); rdbHelper.ExecuteSQL("update CJDCQGXGC set bgxw='0' where bgxw is null and zldwdm = zldwdm_1 and zldwmc = zldwmc_1 and mssm = mssm_1 and IfNull(hdmc,'') = IfNull(hdmc_1,'')"); rdbHelper.ExecuteSQL("update CJDCQGXGC set bgxw='3' where XZQTZLX='3' and FID_CJDCQ=-1"); DataTable gcDt = rdbHelper.ExecuteDatatable("Gc", string.Format("select objectid,FID_CJDCQGX,bgxw,ZLDWDM,ZLDWDM_1,MSSM,MSSM_1,XZQTZLX from CJDCQGXGC"), 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_CJDCQGX"].ToInt(); if (strXZQTZLX == "2" || strXZQTZLX == "4") { msOIDs.Add(oid, gxOID); BgxwList.Add(oid, strBgxw); } else if (strBgxw == "0") { delOIDs.Add(oid, dr["FID_CJDCQGX"].ToInt()); } else { BgxwList.Add(oid, strBgxw); string bgqdm = dr["ZLDWDM"].ToTrim() + "_" + dr["MSSM"].ToTrim(); string bghdm = dr["ZLDWDM_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,ZLDWDM,ZLDWDM_1,MSSM,MSSM_1,ZLDWMC_1,HDMC_1"; _Cursor = tempGxGcLayer.FeatureClass.Update(_Filter, true); int idx = tempGxGcLayer.FeatureClass.FindField("BGXW"); int idxBGQDM = tempGxGcLayer.FeatureClass.FindField("ZLDWDM"); int idxBGQMSSM = tempGxGcLayer.FeatureClass.FindField("MSSM"); int idxBGHDM = tempGxGcLayer.FeatureClass.FindField("ZLDWDM_1"); int idxBGHMSSM = tempGxGcLayer.FeatureClass.FindField("MSSM_1"); int idxBGHZLDWMC = tempGxGcLayer.FeatureClass.FindField("ZLDWMC_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("CJDCQGX"); _Filter.WhereClause = ""; _Cursor = fcAPI.FeatureClass.Update(_Filter, true); idx = fcAPI.FeatureClass.FindField("HDMC"); int idxXZQDM = fcAPI.FeatureClass.FindField("ZLDWDM"); 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_CJDCQGXGC,FID_DLTB_NMK,TBMJ FROM CJDCQGXGC_DLTBNM ", true); Dictionary DicBGMJs = new Dictionary(); if (dtBGMJ != null) { foreach (DataRow dr in dtBGMJ.Rows) { int oid = dr["FID_CJDCQGXGC"].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("bgmj", "SELECT ZLDWDM_1,ZLDWMC_1,MSSM_1,FID_DLTB_NMK,TBMJ FROM CJDCQGXGC_DLTBNM", true); Dictionary DicBGHMJs = new Dictionary(); Dictionary DicTBMJs = new Dictionary(); if (dtBGHMJ != null) { foreach (DataRow dr in dtBGHMJ.Rows) { string oid = $"{dr["ZLDWDM_1"].ToTrim()}_{dr["ZLDWMC_1"].ToTrim()}_{dr["MSSM_1"].ToTrim()}"; 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(oid)) { DicBGHMJs[oid] = (DicBGHMJs[oid] + area).ToDouble(2); } else { DicBGHMJs.Add(oid, area); } } } (layerSourceHelper.GxgcCjdcqLayer.FeatureClass as ITable).DeleteSearchedRows(null); Dictionary GXAttribute = new Dictionary(); GXGCFcToFc(tempGxGcLayer.FeatureClass, layerSourceHelper.GxgcCjdcqLayer.FeatureClass, DicBGMJs, DicBGHMJs, Parm.PrjInfo.CODE, ref GXAttribute, layerSourceHelper); Console.WriteLine("Log:正在生成村级调查区更新数据"); (layerSourceHelper.GxCjdcqLayer.FeatureClass as ITable).DeleteSearchedRows(null); GXFcToFc(fcAPI.FeatureClass, layerSourceHelper.GxCjdcqLayer.FeatureClass, GXAttribute); _Filter = new QueryFilterClass(); //_Filter.WhereClause = "BGXW<>'1'"; if (layerSourceHelper.GxgcCjdcqLayer.FeatureClass.FeatureCount(_Filter) > 0) { Console.WriteLine("Log:正在生成村级调查区界线更新数据"); CJDCQExtractExe(Parm, layerSourceHelper); } Console.WriteLine($"Log:村级调查区数据提取完成。耗时:{GetTime(StartTime)}"); } catch (Exception ex) { Console.WriteLine("Err:村级调查区数据提取失败。" + ex.Message); Console.WriteLine("Err:村级调查区数据提取失败。" + ex.StackTrace); LogAPI.Debug("村级调查区数据提取失败:" + ex.Message + ex.StackTrace); throw ex; } } public bool GXGCFcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, Dictionary pDicBGMJ, Dictionary pDicBGHMJ, string Code, 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}"); 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_CJDCQGX"); var iFID_DLTB = FeatureClass.FindField("FID_CJDCQ"); var idxBGQBSM = FeatureClass.FindField("BSM"); var idxTempBGHDM = FeatureClass.FindField("ZLDWDM_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("BGHZLDWDM"); var idxZLMC = pFc.FindField("BGHZLDWMC"); 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.JcCjdcqLayer.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]]; } } } //buffer.Value[ibgxw] = row[0]["BGXW"]; if (pDicBGMJ.ContainsKey(f.OID)) tbbgmj = pDicBGMJ[f.OID]; buffer.Value[itbbgmj] = Math.Round(tbbgmj, 2);//图斑变更面积 buffer.Value[ibsm] = $"{Code}1241{(bsm++).ToString().PadLeft(8, '0')}"; buffer.Value[igxsj] = new DateTime(DateTime.Now.Year - 1, 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'); if (string.IsNullOrWhiteSpace(strBGHBSM)) continue; 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]; } } 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; //string bsmPrefix = IDGParm.PrjInfo.CODE + MaxBSM.Substring(6, 4); //int MaxNum = Convert.ToInt32(MaxBSM.Substring(9)); //string bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); //MaxBSM = bghBSM; //string attr = bghBSM + "_" + buffer.Value[idxBGHDCMJ]; //if (!pGxAttribure.ContainsKey(FID_DLTBBG.ToInt())) // 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) { 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 idxDCMJ = pFc.FindField("DCMJ"); int idxJSMJ = pFc.FindField("JSMJ"); int idxGXSJ = pFc.FindField("GXSJ"); int idxArea = FeatureClass.FindField("SHAPE_AREA"); while ((f = S_Cursor.NextFeature()) != null) { if (idxArea != -1) { double area = f.Value[idxArea].ToDouble(2); if (area == 0) continue; } buffer.Shape = f.ShapeCopy; foreach (int item in dicField.Keys) { buffer.Value[item] = f.Value[dicField[item]]; } 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] = "1000600400"; if (idxGXSJ != -1) { buffer.Value[idxGXSJ] = new DateTime(DateTime.Now.Year - 1, 12, 31); } T_Cursor.InsertFeature(buffer); } T_Cursor.Flush(); if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = false; return true; } catch (Exception) { throw; } } 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:获取年初地类图斑数据失败!"); // } //} //if (parm.ExeCJDCQ) //{ LayerCfg _JcCjdcqLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "村级调查区"); result.JcCjdcqLayer = OpenLayer(_JcCjdcqLayerInfo); if (result.JcCjdcqLayer == null) throw new Exception("Err:获取年初村级调查区数据失败!"); LayerCfg _JcCjdcqJxLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "村级调查区界线"); result.JcCjdcqJxLayer = OpenLayer(_JcCjdcqJxLayerInfo); if (result.JcCjdcqJxLayer == null) throw new Exception("Err:获取年初村级调查区界线数据失败!"); result.GxCjdcqLayer = OpenLayer(result.ZlWsAPI, "CJDCQGX"); result.GxgcCjdcqLayer = OpenLayer(result.ZlWsAPI, "CJDCQGXGC"); result.GxCjdcqJxLayer = OpenLayer(result.ZlWsAPI, "CJDCQJXGX"); 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 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(DateTime.Now.Year - 1, 12, 31)); gx_buffer.set_Value(gx_buffer.Fields.FindField("YSDM"), "1000600500"); 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 提取村级调查区界界线 public void CJDCQExtractExe(IDGParameter pParm, DBLayerSourceHelper pLayerSourceHelper) { bool cb_XZQDMChange = false; //IFeatureClass CJDCQGXFeatureClass = null; //IFeatureLayer JCCJDCQJXFeatureLayer = null; //IFeatureLayer gxgc_cjdcqLayer = null; //IFeatureLayer gx_cjdcqjxLayer = null; try { //if (_MapService == null) // _MapService = MapsManager.Instance.MapService; //gx_cjdcqLayer = pLayerSourceHelper.GxCjdcqLayer; //gxgc_cjdcqLayer = pLayerSourceHelper.GxgcCjdcqLayer; //gx_cjdcqjxLayer = pLayerSourceHelper.GxCjdcqJxLayer; //CJDCQGXFeatureClass = gx_cjdcqLayer.FeatureClass;// _MapService.GetFeatureClassByName("CJDCQGX");//村级调查区更新层 //CJDCQGXGCFeatureClass = gxgc_cjdcqLayer.FeatureClass;// _MapService.GetFeatureClassByName("CJDCQGXGC");//村级调查区更新过程层 //JCCJDCQFeatureLayer = pLayerSourceHelper.JcCjdcqLayer;// _MapService.GetFeatureLayerByLayerName("村级调查区");//基础村级调查区 //JCCJDCQJXFeatureLayer = pLayerSourceHelper.JcCjdcqJxLayer;// _MapService.GetFeatureLayerByLayerName("村级调查区界线");//基础村级调查区界线 //if (CJDCQGXGCFeatureClass.FeatureCount(null) == 0) return; //cjdcqgxgcfcAPI = new FeatureClassAPI(CJDCQGXGCFeatureClass); //List cjdcqgxgcList = cjdcqgxgcfcAPI.QueryFeatures(null); //IFeature cjdcqGXGC = FeatureAPI.MergeFeature(cjdcqgxgcList); //List features = FeatureAPI.Identify(cjdcqGXGC.ShapeCopy, JCCJDCQFeatureLayer); string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\CJDCQJXGX"; if (!System.IO.Directory.Exists(gdbFolder)) { System.IO.Directory.CreateDirectory(gdbFolder); } try { DelectDir(gdbFolder);//能删除就删除 删除报错不处理 } catch { } string gdbFileName = Guid.NewGuid().ToString() + ".gdb"; string path = System.IO.Path.Combine(gdbFolder, gdbFileName); IWorkspaceFactory pFtWsFct = new FileGDBWorkspaceFactory(); IWorkspaceName workspaceName = pFtWsFct.Create(gdbFolder, gdbFileName, null, 0); //IWorkspaceAPI psTempWorkspaceAPI = new WorkspaceAPI(path, WorkspaceTypeEnum.GDBFile); //IFeatureClassAPI tempcjdcqgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("CJDCQGX_TEMP", (CJDCQGXFeatureClass as IGeoDataset).SpatialReference, CJDCQGXFeatureClass.Fields); //tempcjdcqgxFeatureclassAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); //JCCJDCQInsertGX(features, tempcjdcqgxFeatureclassAPI.FeatureClass, null);//将基础村级调查区数据插入到更新过程层,变更前变更后的属性数据一致 //IFeatureClassAPI cjdcqgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("CJDCQGX", (CJDCQGXFeatureClass as IGeoDataset).SpatialReference, CJDCQGXFeatureClass.Fields); //cjdcqgxFeatureclassAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); //IFeatureClassAPI fcAPI = new FeatureClassAPI(CJDCQGXFeatureClass); //fcAPI.FcToFc(cjdcqgxFeatureclassAPI.FeatureClass, null, false); //IQueryFilter filter = new QueryFilterClass(); //filter.WhereClause = string.Format(" BGHZLDWDM is null or BGHZLDWDM=''"); //CJDCQGXMSInsertGX(CJDCQGXGCFeatureClass, cjdcqgxFeatureclassAPI.FeatureClass, filter); //IFeatureLayer cjdcqgxJCLayer = null; //GPParamClass gPParamClass = new GPParamClass(); //gPParamClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = tempcjdcqgxFeatureclassAPI.FeatureClass }; //gPParamClass.SecondFeatureLayer = new FeatureLayerClass() { FeatureClass = cjdcqgxFeatureclassAPI.FeatureClass }; //gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(path, "CJDCQGX_JC"); //gPParamClass.IsGetOutPutFeature = true; //gPParamClass.GPType = EnumGPType.Erase; ////GeoprocessorHelper gpHelper = new GeoprocessorHelper(); //GPHelper.Instance.ExeGPForProces(gPParamClass, ref cjdcqgxJCLayer); //fcAPI = new FeatureClassAPI(cjdcqgxJCLayer.FeatureClass); //fcAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); //fcAPI = new FeatureClassAPI(cjdcqgxJCLayer.FeatureClass); //fcAPI.FcToFc(cjdcqgxFeatureclassAPI.FeatureClass, null, false); //filter = new QueryFilterClass(); //filter.WhereClause = string.Format("SHAPE_AREA<0.1"); //(cjdcqgxFeatureclassAPI.FeatureClass as ITable).DeleteSearchedRows(filter); //// 村级调查区更新过程要素转线 //IFeatureLayer cjdcqgxgcjxLayer = null; //gPParamClass = new GPParamClass(); //gPParamClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = cjdcqgxFeatureclassAPI.FeatureClass }; //gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(path, "CJDCQGX_JX"); //gPParamClass.IsGetOutPutFeature = true; //gPParamClass.GPType = EnumGPType.PolygonToLine; //GPHelper.Instance.ExeGPForProces(gPParamClass, ref cjdcqgxgcjxLayer); //// 村级调查区更新过程界线取消线分割 //IFeatureLayer gxgcjxUnsplitLayer = null; //gPParamClass = new GPParamClass(); //gPParamClass.FirstFeatureLayer = cjdcqgxgcjxLayer; //gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(path, "CJDCQGXGCJX_Unsplit"); //gPParamClass.IsGetOutPutFeature = true; //gPParamClass.ListDissolveFiledName = new List() { "LEFT_FID", "RIGHT_FID" }; //gPParamClass.GPType = EnumGPType.UnsplitLine; //GPHelper.Instance.ExeGPForProces(gPParamClass, ref gxgcjxUnsplitLayer); if (pLayerSourceHelper.GxgcCjdcqLayer.FeatureClass.FeatureCount(null) == 0) return; IVariantArray parameters = new VarArrayClass(); parameters.Add(pLayerSourceHelper.GxCjdcqLayer); parameters.Add(pLayerSourceHelper.GxgcCjdcqLayer); parameters.Add(pLayerSourceHelper.JcCjdcqLayer); parameters.Add(path); parameters.Add("CJDCQJX"); GPHelper.Instance.ExeGp(parameters); IWorkspaceAPI psTempWorkspaceAPI = new WorkspaceAPI(path, WorkspaceTypeEnum.GDBFile); IFeatureClassAPI cjdcqgxFeatureclassAPI = psTempWorkspaceAPI.OpenFeatureClass("GXTB"); IFeatureClassAPI gxgcjxUnsplitLayer = psTempWorkspaceAPI.OpenFeatureClass("CJDCQGXGCJX_Unsplit"); Dictionary zldwdmDic = new Dictionary(); Dictionary isjctbDic = new Dictionary(); int objectidIndex = cjdcqgxFeatureclassAPI.FeatureClass.Fields.FindField("OBJECTID"); int bghzldwdmIndex = cjdcqgxFeatureclassAPI.FeatureClass.Fields.FindField("ZLDWDM"); int bghMSSMIndex = cjdcqgxFeatureclassAPI.FeatureClass.Fields.FindField("MSSM"); int gxgcIndex = cjdcqgxFeatureclassAPI.FeatureClass.Fields.FindField("IsJCTB"); IFeatureCursor gxgcjxCursor = cjdcqgxFeatureclassAPI.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 (bghzldwdmIndex != -1) { string zldwdm = gxgcFeature.Value[bghzldwdmIndex].ToString() + "_" + strMSSM; if (objectid != 0) zldwdmDic.Add(objectid, zldwdm); } if (gxgcIndex != -1) { string jctb = gxgcFeature.Value[gxgcIndex].ToString(); if (objectid != 0) isjctbDic.Add(objectid, jctb); } Marshal.ReleaseComObject(gxgcFeature); } IFeatureClass CJDCQJXGXFeatureClass = pLayerSourceHelper.GxCjdcqJxLayer.FeatureClass;// _MapService.GetFeatureClassByName("CJDCQJXGX"); ITable table = CJDCQJXGXFeatureClass as ITable; table.DeleteSearchedRows(null); int leftidIndex = gxgcjxUnsplitLayer.FeatureClass.Fields.FindField("LEFT_FID"); int rightIndex = gxgcjxUnsplitLayer.FeatureClass.Fields.FindField("RIGHT_FID"); int shapeLengthIndex = gxgcjxUnsplitLayer.FeatureClass.Fields.FindField("SHAPE_LENGTH"); IFeatureCursor gxgcjxUnsplitCursor = null; IFeature f = null; List MS_OID = new List(); IFeatureCursor xzqgxCur = pLayerSourceHelper.GxCjdcqLayer.FeatureClass.Search(null, true); IFeature xzqgx = null; while ((xzqgx = xzqgxCur.NextFeature()) != null) { List jcjx_features = FeatureAPI.Identify2(xzqgx.ShapeCopy, pLayerSourceHelper.JcCjdcqJxLayer); foreach (var item in jcjx_features) { if (!MS_OID.Contains(item.OID)) MS_OID.Add(item.OID); } } if (cb_XZQDMChange == true) { gxgcjxUnsplitCursor = pLayerSourceHelper.JcCjdcqJxLayer.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.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); if (MS_OID.Contains(f.OID)) MS_OID.Remove(f.OID); } } gxgcjxUnsplitCursor = gxgcjxUnsplitLayer.FeatureClass.Search(null, true); while ((f = gxgcjxUnsplitCursor.NextFeature()) != null) { IPolyline line = f.ShapeCopy as IPolyline; IPoint p = line.FromPoint; List lines = FeatureAPI.Identify2(p, new FeatureLayerClass() { FeatureClass = gxgcjxUnsplitLayer.FeatureClass, SpatialReference = (gxgcjxUnsplitLayer.FeatureClass as IGeoDataset).SpatialReference }); if (lines.Count < 3) { foreach (var item in lines) { if (item.OID == f.OID) continue; IFeatureEdit edit = item as IFeatureEdit; List splitLines = FeatureAPI.SplitLineAtPoint(p, item.ShapeCopy as IPolyline); if (splitLines.Count > 1) edit.Split(p); } } } gxgcjxUnsplitCursor = gxgcjxUnsplitLayer.FeatureClass.Search(null, true); string jxlx = "";//界线类型 List JC_OID = new List(); shapeLengthIndex = gxgcjxUnsplitLayer.FeatureClass.Fields.FindField("SHAPE_LENGTH"); while ((f = gxgcjxUnsplitCursor.NextFeature()) != null) { if (f.OID == 626) { } if (leftidIndex == -1 || rightIndex == -1) { continue; } List jcjx_features = FeatureAPI.Identify2(f.ShapeCopy, pLayerSourceHelper.JcCjdcqJxLayer); int leftID = int.Parse(f.Value[leftidIndex].ToString()); int rightID = int.Parse(f.Value[rightIndex].ToString()); double gxshapeLength = f.Value[shapeLengthIndex].ToDouble(2); if ((leftID != -1 && !zldwdmDic.ContainsKey(leftID)) || (rightID != -1 && !zldwdmDic.ContainsKey(rightID))) continue; string leftzldwdm = leftID == -1 ? "" : zldwdmDic[leftID]; string rightzldwdm = rightID == -1 ? "" : zldwdmDic[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 (leftzldwdm.Replace("_", "").Length == rightzldwdm.Replace("_", "").Length) { if (leftzldwdm.Length < 6) { bghJXLX = ""; } else if (leftzldwdm.Substring(0, 6) != rightzldwdm.Substring(0, 6)) { //县界 bghJXLX = "650200"; } else if (leftzldwdm.Substring(0, 9) != rightzldwdm.Substring(0, 9)) { //乡镇界 bghJXLX = "660200"; } else if (leftzldwdm.Substring(0, 12) == rightzldwdm.Substring(0, 12)) { bghJXLX = ""; } else { //村界 bghJXLX = "670500"; } } else if (rightzldwdm.Contains("_01")) { bghJXLX = "250202"; } else if (rightzldwdm == "_" && leftzldwdm == "_") { bghJXLX = ""; } else { //县界 bghJXLX = "650200"; } if (cb_XZQDMChange == true) { InsertCJDCQGXFeature(f, 3, bghJXLX, "600001", pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); 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(); InsertCJDCQGXFeature(item, 0, jcjxlx2, jcjxxz2, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); if (MS_OID.Contains(item.OID)) MS_OID.Remove(item.OID); } if (!string.IsNullOrWhiteSpace(bghJXLX)) InsertCJDCQGXFeature(f, 3, bghJXLX, "600001", pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); continue; } if (jcjx_features.Count == 0) { //新生成的界线标记新增 InsertCJDCQGXFeature(f, 3, bghJXLX, "600001", pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); 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); InsertCJDCQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); 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) { IPointCollection gxPs = f.ShapeCopy as IPointCollection; IPointCollection jcPs = jcfeature.ShapeCopy as IPointCollection; if (gxPs.PointCount != jcPs.PointCount) { InsertCJDCQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); InsertCJDCQGXFeature(f, 3, bghJXLX, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); } else { InsertCJDCQGXFeature(jcfeature, 4, jcjxlx, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); } if (MS_OID.Contains(jcfeature.OID)) MS_OID.Remove(jcfeature.OID); continue; } else { if (!JC_OID.Contains(jcfeature.OID)) { JC_OID.Add(jcfeature.OID); InsertCJDCQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); if (MS_OID.Contains(jcfeature.OID)) MS_OID.Remove(jcfeature.OID); } //相关基础界线标记删除,新生成的界线标记新增 InsertCJDCQGXFeature(f, 3, bghJXLX, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); } } else { if (!JC_OID.Contains(jcfeature.OID)) { JC_OID.Add(jcfeature.OID); InsertCJDCQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); if (MS_OID.Contains(jcfeature.OID)) MS_OID.Remove(jcfeature.OID); } //相关基础界线标记删除,新生成的界线标记新增 InsertCJDCQGXFeature(f, 3, bghJXLX, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); } } foreach (var item in MS_OID) { IFeature jcfeature = pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass.GetFeature(item); string jcjxlx = jcfeature.Value[jcfeature.Fields.FindField("JXLX")].ToString(); string jcjxxz = jcfeature.Value[jcfeature.Fields.FindField("JXXZ")].ToString(); InsertCJDCQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, pLayerSourceHelper.JcCjdcqJxLayer.FeatureClass, CJDCQJXGXFeatureClass); } } catch (Exception ex) { LogAPI.Debug("图斑变更发生异常!异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("异常信息结束"); throw; } } private void JCCJDCQInsertGX(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 CJDCQGXMSInsertGX(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 InsertCJDCQGXFeature(IFeature pGXJX, int BGXW, string JXLX, string JXXZ, IFeatureClass JC_CJDCQJX, IFeatureClass CJDCQJXGX) { IFeatureCursor gx_cursor = null; IFeatureBuffer gx_buffer = null; try { bool IsInsert = true; var Identify = FeatureAPI.Identify2(pGXJX.Shape, new FeatureLayer() { FeatureClass = CJDCQJXGX }); 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(strCJDCQJXMaxBSM)) { strCJDCQJXMaxBSM = SetMaxBSM(JC_CJDCQJX, CJDCQJXGX); if (!strCJDCQJXMaxBSM.StartsWith(IDGParm.PrjInfo.CODE)) strCJDCQJXMaxBSM = IDGParm.PrjInfo.CODE + "1250" + "1".PadLeft(8, '0'); } else { string bsmPrefix = IDGParm.PrjInfo.CODE + strCJDCQJXMaxBSM.Substring(6, 4); int MaxNum = Convert.ToInt32(strCJDCQJXMaxBSM.Substring(9)); strCJDCQJXMaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); } gx_cursor = CJDCQJXGX.Insert(true); gx_buffer = CJDCQJXGX.CreateFeatureBuffer(); gx_buffer.Shape = pGXJX.Shape; gx_buffer.set_Value(gx_buffer.Fields.FindField("BSM"), BGXW == 3 ? strCJDCQJXMaxBSM : 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(DateTime.Now.Year - 1, 12, 31)); gx_buffer.set_Value(gx_buffer.Fields.FindField("YSDM"), "1000600500"); 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 strCJDCQJXMaxBSM = string.Empty; #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 GenerateGxgcData string JCTBName = string.Empty; public void GenerateGxgcData(IDGParameter pParm) { Geoprocessor gp = null; IWorkspaceFactory pFtWsFct = null; IWorkspaceName workspaceName = null; try { bool IsZLMCBG = false; //IMapService _MapService = MapsManager.Instance.MapService; gp = new Geoprocessor() { OverwriteOutput = true }; //IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();//对两个要素类进行相交运算 //gpValueTableObject.SetColumns(2); object o1 = JcCjdcqLayer;//.JC_CJDCQLay; object o2 = GxCjdcqLayer;//.GX_CJDCQLay; //gpValueTableObject.AddRow(ref o2); //gpValueTableObject.AddRow(ref o1); //string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\GXGC"; //if (!Directory.Exists(gdbFolder)) //{ // Directory.CreateDirectory(gdbFolder); //} //try //{ DelectDir(gdbFolder); } //catch //{ } //pFtWsFct = new FileGDBWorkspaceFactory(); //string gdbFileName = Guid.NewGuid().ToString() + ".gdb"; //string path = System.IO.Path.Combine(gdbFolder, gdbFileName); //workspaceName = pFtWsFct.Create(gdbFolder, gdbFileName, null, 0); IFeatureLayer pjbntFeatureLayer = null; GPParamClass gPParamClass = new GPParamClass(); gPParamClass.FirstFeatureLayer = GxCjdcqLayer;//.GX_CJDCQLay as IFeatureLayer; //gPParamClass.FirstFeatureClassPath = pParm.ZLDbPath + "\\CJDCQGX"; gPParamClass.SecondFeatureLayer = JcCjdcqLayer;// pParm.JC_CJDCQLay as IFeatureLayer; //gPParamClass.SecondFeatureClassPath = pParm.JcDbPath + "\\CJDCQ"; gPParamClass.OutFeatureClassPath = TempGDBPath + "\\" + "TempCJDCQGXGC"; gPParamClass.IsGetOutPutFeature = true; gPParamClass.ListDissolveFiledName = new List(); gPParamClass.GPType = EnumGPType.Union; //GeoprocessorHelper gpHelper = new GeoprocessorHelper(); //gpHelper.UnionAnalysis(gPParamClass, ref pjbntFeatureLayer); GPHelper.Instance.ExeGPForProces(gPParamClass, ref pjbntFeatureLayer); IFeatureClass outFc = null; gPParamClass = new GPParamClass(); gPParamClass.FirstFeatureLayer = pjbntFeatureLayer; gPParamClass.OutFeatureClassPath = TempGDBPath + "\\" + "TempGXGC_MToS"; gPParamClass.IsGetOutPutFeature = true; gPParamClass.GPType = EnumGPType.MultipartToSinglePath; GPHelper.Instance.ExeGPForProces(gPParamClass, ref pjbntFeatureLayer); //gpHelper.MultipartToSinglePath(gPParamClass, ref pjbntFeatureLayer); //string dbPath = pParm.ProjDir + @"\BGTJ.sqlite"; IWorkspaceFactory pOutWorkFactory = new SqlWorkspaceFactoryClass(); IWorkspace pOutWork = pOutWorkFactory.OpenFromFile(TempDBPath, 0); IFeatureWorkspace SchemeWork = (pjbntFeatureLayer.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace; KGIS.Framework.DBOperator.IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + TempDBPath, DatabaseType.SQLite); rdbHelper.ExecuteSQL(" drop table TempGXGC_MToS "); TableToTable(SchemeWork, pOutWork, "TempGXGC_MToS"); JCTBName = (JcCjdcqLayer.FeatureClass as FeatureClass).Name; string strSql = $"select ZLDWDM,ZLDWDM_1,MSSM,MSSM_1,HDMC from TempGXGC_MToS where ZLDWDM<>ZLDWDM_1 or objectid not in (select objectid from (select * from TempGXGC_MToS group by FID_{JCTBName} HAVING count(0)=1) where FID_CJDCQGX>-1 and FID_{JCTBName}>-1)"; if (IsZLMCBG) { strSql = $"select ZLDWDM,ZLDWDM_1,zldwmc,zldwmc_1,MSSM,MSSM_1,HDMC from TempGXGC_MToS where ZLDWDM<>ZLDWDM_1 or zldwmc<>zldwmc_1 or objectid not in (select objectid from (select * from TempGXGC_MToS group by FID_{JCTBName} HAVING count(0)=1) where FID_CJDCQGX>-1 and FID_{JCTBName}>-1)"; } DataTable ChangeDT = rdbHelper.ExecuteDatatable("change", strSql, true); List listZL = new List(); if (ChangeDT != null) { if (ChangeDT.Rows.Count == 0) return; foreach (System.Data.DataRow dr in ChangeDT.Rows) { string zl = dr["ZLDWDM"].ToTrim(); if (string.IsNullOrWhiteSpace(zl)) zl = dr["ZLDWDM_1"].ToTrim(); string zlmc = ChangeDT.Columns.Contains("ZLDWMC") ? dr["ZLDWMC"].ToTrim() : ""; if (string.IsNullOrWhiteSpace(zlmc) && ChangeDT.Columns.Contains("ZLDWMC_1")) zlmc = dr["ZLDWMC_1"].ToTrim(); string mssm = dr["MSSM"].ToTrim(); if (string.IsNullOrWhiteSpace(mssm)) mssm = dr["MSSM_1"].ToTrim(); string hdmc = ""; string key = zl + "_" + mssm + "_" + hdmc; if (IsZLMCBG) { key = zl + "_" + zlmc + "_" + mssm + "_" + hdmc; } if (string.IsNullOrWhiteSpace(zl)) continue; if (listZL.Contains(key)) continue; listZL.Add(key); } } strSql = $"select objectid,ZLDWDM_1,MSSM_1,HDMC_1 from (select * from TempGXGC_MToS group by FID_{JCTBName} HAVING count(0)=1) where FID_CJDCQGX>-1 and FID_{JCTBName}>-1 and ZLDWDM=ZLDWDM_1"; if (IsZLMCBG) { strSql = $"select objectid,ZLDWDM_1,ZLDWMC_1,MSSM_1,HDMC_1 from (select * from TempGXGC_MToS group by FID_{JCTBName} HAVING count(0)=1) where FID_CJDCQGX>-1 and FID_{JCTBName}>-1 and ZLDWDM=ZLDWDM_1 and ZLDWMC=ZLDWMC_1"; } System.Data.DataTable delDt = rdbHelper.ExecuteDatatable("del", strSql, true); DataTable allDT = rdbHelper.ExecuteDatatable("All", "select * from TempGXGC_MToS", true); if (delDt != null) { foreach (System.Data.DataRow dr in delDt.Rows) { int oid = dr["OBJECTID"].ToInt(); string zl = dr["ZLDWDM_1"].ToTrim(); string zlmc = ChangeDT.Columns.Contains("ZLDWMC_1") ? dr["ZLDWMC_1"].ToTrim() : ""; string mssm = dr["MSSM_1"].ToTrim(); string xzqmc = ""; string key = zl + "_" + mssm + "_" + xzqmc; if (IsZLMCBG) { key = zl + "_" + zlmc + "_" + mssm + "_" + xzqmc; } if (listZL.Contains(key)) continue; try { pjbntFeatureLayer.FeatureClass.GetFeature(oid).Delete(); } catch (Exception ex) { } } } outFc = pjbntFeatureLayer.FeatureClass; IFeatureClassAPI gcFcAPI = new FeatureClassAPI(outFc); gcFcAPI.AddField("XZQTZLX", esriFieldType.esriFieldTypeString, ""); Dictionary bghAttr = new Dictionary(); Dictionary gxAttr = new Dictionary(); SetAttribue(outFc, (JcCjdcqLayer as IFeatureLayer).FeatureClass, (GxCjdcqLayer as IFeatureLayer).FeatureClass, ref bghAttr, ref gxAttr); IFeatureClass gxgcFc = (GxgcCjdcqLayer as IFeatureLayer).FeatureClass; ITable cjdcqgxgcTb = gxgcFc as ITable; cjdcqgxgcTb.DeleteSearchedRows(null);//删除村级调查区更新过程所有数据 Dictionary target_SourMaping = new Dictionary(); Dictionary fieldValues = new Dictionary(); for (int i = 0; i < gxgcFc.Fields.FieldCount; i++) { IField field = gxgcFc.Fields.Field[i]; if (!field.Editable || field.Name.Contains(gxgcFc.ShapeFieldName)) continue; int sIndex = outFc.FindField(field.Name); if (field.Name.StartsWith("BGQ")) { if (sIndex == -1) sIndex = outFc.FindField(field.Name.Replace("BGQ", "") + "_1"); if (sIndex == -1) sIndex = outFc.FindField(field.Name.Replace("BGQTB", "") + "_1"); if (sIndex != -1) { target_SourMaping.Add(i, sIndex); fieldValues.Add(field.Name, sIndex); } continue; } else if (field.Name.StartsWith("BGH")) { if (sIndex == -1) sIndex = outFc.FindField(field.Name.Replace("BGH", "")); if (sIndex == -1) sIndex = outFc.FindField(field.Name.Replace("BGHTB", "")); if (sIndex != -1) { target_SourMaping.Add(i, sIndex); fieldValues.Add(field.Name, sIndex); } continue; } else if (field.Name == "BGMJ") { if (sIndex == -1) sIndex = outFc.FindField("TBMJ"); if (sIndex != -1) { target_SourMaping.Add(i, sIndex); fieldValues.Add(field.Name, sIndex); } continue; } if (sIndex != -1) { target_SourMaping.Add(i, sIndex); fieldValues.Add(field.Name, sIndex); } } IFeatureCursor t_cursor = gxgcFc.Insert(true); IFeatureCursor s_cursor = outFc.Search(null, true); IFeatureLayer _tempLayer = null; pjbntFeatureLayer.FeatureClass = outFc; gPParamClass = new GPParamClass(); gPParamClass.FirstFeatureLayer = pjbntFeatureLayer; gPParamClass.SecondFeatureLayer = NmTbLayer; gPParamClass.OutFeatureClassPath = TempGDBPath + "\\" + "TempCJDCQGXGC_DLTB"; gPParamClass.IsGetOutPutFeature = true; gPParamClass.GPType = EnumGPType.Intersect; GPHelper.Instance.ExeGPForProces(gPParamClass, ref _tempLayer); IFeatureClass outFc2 = _tempLayer.FeatureClass; Console.WriteLine("cjdcq"); ITable table = outFc2 as ITable; ICursor cursor = table.Search(new QueryFilterClass() { SubFields = "OBJECTID,SHAPE,FID_TempGXGC_MToS,FID_DLTB_NMK,BSM_12,ZLDWDM,ZLDWMC,TBMJ,MSSM,XZQTZLX_1" }, true); IRow row = null; List DicNMKOids = new List(); int nmkoidIdx = table.FindField("FID_DLTB_NMK"); int oidIdx = table.FindField("FID_TempGXGC_MToS"); int mjIdx = table.FindField("TBMJ"); int xzqdmIdx = table.FindField("ZLDWDM"); int xzqmcIdx = table.FindField("ZLDWMC"); int mssmIdx = table.FindField("MSSM"); int nmkBSMIdx = table.FindField("BSM_12"); int xzqtzlxIdx = table.FindField("XZQTZLX_1"); int ShapeIdx = table.FindField("SHAPE"); Dictionary> dicPcList = new Dictionary>(); Dictionary dicXZQTZLX = new Dictionary(); while ((row = cursor.NextRow()) != null) { if (nmkoidIdx == -1) break; if (mjIdx == -1) break; int gxoid = -1; if (oidIdx != -1) { gxoid = row.Value[oidIdx].ToInt(); if (xzqtzlxIdx != -1 && gxoid != -1) { if (!dicXZQTZLX.ContainsKey(gxoid)) { dicXZQTZLX.Add(gxoid, row.Value[xzqtzlxIdx].ToTrim()); } else { if (string.IsNullOrWhiteSpace(dicXZQTZLX[gxoid])) { dicXZQTZLX[gxoid] = row.Value[xzqtzlxIdx].ToTrim(); } } } } double mj = row.Value[mjIdx].ToDouble(); int oid = row.Value[nmkoidIdx].ToInt(); string nmkBSM = string.Empty; if (nmkBSMIdx != -1) nmkBSM = row.Value[nmkBSMIdx].ToTrim(); IGeometry geo = row.Value[ShapeIdx] as IGeometry; if (!dicPcList.ContainsKey(oid)) { PCModel dic = new PCModel(); dic.OID = row.OID; dic.NMKOID = oid; dic.NMKBSM = nmkBSM; dic.TBMJ = mj; if (geo != null && !geo.IsEmpty) dic.JSMJ = (geo as IPolygon).GetEllipseArea().ToDouble(2); if (dic.JSMJ != 0) { dicPcList.Add(oid, new List() { dic }); } else { dic.TBMJ = dic.JSMJ; IRow tempRow = table.GetRow(row.OID); tempRow.Value[mjIdx] = dic.JSMJ; tempRow.Store(); } } else { PCModel dic = new PCModel(); dic.OID = row.OID; dic.NMKOID = oid; dic.NMKBSM = nmkBSM; dic.TBMJ = mj; if (geo != null && !geo.IsEmpty) dic.JSMJ = (geo as IPolygon).GetEllipseArea().ToDouble(2); if (dic.JSMJ != 0) { dicPcList[oid].Add(dic); } else { dic.TBMJ = dic.JSMJ; IRow tempRow = table.GetRow(row.OID); tempRow.Value[mjIdx] = dic.JSMJ; tempRow.Store(); } } } xzqtzlxIdx = outFc.FindField("XZQTZLX"); foreach (var key in dicXZQTZLX.Keys) { if (string.IsNullOrWhiteSpace(dicXZQTZLX[key]) || xzqtzlxIdx == -1) continue; IFeature gcF = outFc.GetFeature(key); gcF.Value[xzqtzlxIdx] = dicXZQTZLX[key]; gcF.Store(); } List pcList = new List(); IFeatureLayer tempLayer = GxgcTBLayer as IFeatureLayer;// _MapService.GetFeatureLayerByName("DLTBGXGC"); IFeatureLayer jcDLTBLayer = JcTbLayer as IFeatureLayer;// _MapService.GetFeatureLayerByLayerName("地类图斑"); foreach (var item in dicPcList) { if (item.Value.Count > 1) { foreach (var pc in item.Value) { IFeature f = outFc2.GetFeature(pc.OID); List gcFList = FeatureAPI.Identify2(f.ShapeCopy, tempLayer); double bgmj = 0; if (gcFList.Count > 0) { int gcBgmjIdx = tempLayer.FeatureClass.FindField("TBBGMJ"); if (gcBgmjIdx != -1) { foreach (var gc in gcFList) { bgmj += gc.Value[gcBgmjIdx].ToDouble(2); } pc.JSMJ = bgmj; } else { pc.JSMJ = (f.ShapeCopy as IPolygon).GetEllipseArea().ToDouble(2); } } else { List jcFeatures = FeatureAPI.Identify2(f.ShapeCopy, jcDLTBLayer); int idx = jcDLTBLayer.FeatureClass.FindField("TBMJ"); foreach (var jc in jcFeatures) { bgmj = Math.Round(bgmj + jc.Value[idx].ToDouble(), 2); } if (bgmj == 0) continue; pc.JSMJ = bgmj; } } double jsmj = item.Value.Sum(p => p.JSMJ); double tbmj = item.Value[0].TBMJ; if (jsmj != tbmj) { List list = item.Value.OrderByDescending(desc => desc.JSMJ).ToList(); double mjc = (jsmj - tbmj).ToDouble(2); while (mjc != 0 && Math.Abs(mjc) < 500) { int tpsm = (int)(Math.Abs(Math.Round(mjc, 2)) / 0.01); int e = tpsm / list.Count; int f = tpsm % list.Count; if (f != 0) { double tpmj = (e + 1) * 0.01; for (int i = 0; i < f; i++) { if (mjc < 0) list[i].JSMJ += tpmj; else list[i].JSMJ -= tpmj; } } if (e != 0) { double tpmj = e * 0.01; for (int i = f; i < list.Count; i++) { if (mjc < 0) list[i].JSMJ += tpmj; else list[i].JSMJ -= tpmj; } } mjc = (list.Sum(sum => sum.JSMJ).ToDouble(2) - tbmj).ToDouble(2); } } pcList.AddRange(item.Value); } } Dictionary bgmjList = new Dictionary(); Dictionary dcmjList = new Dictionary(); cursor = table.Search(new QueryFilterClass() { SubFields = "OBJECTID,FID_TempGXGC_MToS,FID_DLTB_NMK,ZLDWDM,ZLDWMC,MSSM,TBMJ" }, true); while ((row = cursor.NextRow()) != null) { if (oidIdx != -1 && mjIdx != -1) { int oid = row.Value[oidIdx].ToInt(); double mj = row.Value[mjIdx].ToDouble(); PCModel pcModel = pcList.FirstOrDefault(m => m.OID == row.OID); if (pcModel != null) mj = pcModel.JSMJ; if (!bgmjList.ContainsKey(oid)) bgmjList.Add(oid, mj); else bgmjList[oid] += mj; if (xzqdmIdx != -1) { string xzqdm = row.Value[xzqdmIdx].ToTrim(); string mssm = row.Value[mssmIdx].ToTrim(); string xzqmc = "";// row.Value[xzqmcIdx].ToTrim(); if (IsZLMCBG) { xzqmc = row.Value[xzqmcIdx].ToTrim(); } string key = xzqdm + "_" + mssm + "_" + xzqmc; if (dcmjList.ContainsKey(key)) dcmjList[key] = Math.Round(dcmjList[key] + mj, 2); else dcmjList.Add(key, mj); } } } IFeature s = null; int gxsjIndex = gxgcFc.FindField("GXSJ"); int bghTBBSMIndex = gxgcFc.FindField("BGHBSM"); int bgmjIndex = gxgcFc.FindField("BGMJ"); int bgxwIndex = gxgcFc.FindField("BGXW"); int bgqDCMJIndex = gxgcFc.FindField("BGQDCMJ"); int bghDCMJIndex = gxgcFc.FindField("BGHDCMJ"); int bgqZLDWDMIndex = gxgcFc.FindField("BGQZLDWDM"); int bghZLDWDMIndex = gxgcFc.FindField("BGHZLDWDM"); int bghZLDWMCIndex = gxgcFc.FindField("BGHZLDWMC"); int bgqZLDWMCIndex = gxgcFc.FindField("BGQZLDWMC"); int bghMSSMIndex = gxgcFc.FindField("BGHMSSM"); int bgqMSSMIndex = gxgcFc.FindField("BGQMSSM"); int xzqtzlxIndex = outFc.FindField("XZQTZLX"); int bgqOIDIndex = outFc.FindField("FID_CJDCQGX"); IQueryFilter delFilter = new QueryFilterClass() { WhereClause = "1=2" }; while ((s = s_cursor.NextFeature()) != null) { IFeatureBuffer buf = gxgcFc.CreateFeatureBuffer(); buf.Shape = s.ShapeCopy; foreach (var item in target_SourMaping) { buf.Value[item.Key] = s.Value[item.Value]; } int gxOID = s.Value[bgqOIDIndex].ToInt(); int xzqtzlx = 0; if (xzqtzlxIndex != -1) { xzqtzlx = s.Value[xzqtzlxIndex].ToInt(); } if (gxsjIndex != -1) { buf.Value[gxsjIndex] = new DateTime(DateTime.Now.Year - 1, 12, 31); } if (bghDCMJIndex != -1 && bghZLDWDMIndex != -1) { string xzqdm = buf.Value[bghZLDWDMIndex].ToTrim(); string mssm = buf.Value[bghMSSMIndex].ToTrim(); string xzqmc = ""; if (IsZLMCBG) { xzqmc = buf.Value[bghZLDWMCIndex].ToTrim(); } string key = xzqdm + "_" + mssm + "_" + xzqmc; if (dcmjList.ContainsKey(key)) buf.Value[bghDCMJIndex] = Math.Round(dcmjList[key], 2); } if (bghAttr.ContainsKey(s.OID)) { if (bghTBBSMIndex != -1) buf.Value[bghTBBSMIndex] = bghAttr[s.OID].BGHBSM; if (bgmjIndex != -1 && bgmjList.ContainsKey(s.OID)) { buf.Value[bgmjIndex] = bgmjList[s.OID].ToDouble(2); } if (bgxwIndex != -1 && xzqtzlx != 4) buf.Value[bgxwIndex] = bghAttr[s.OID].BGXW; else buf.Value[bgxwIndex] = "0"; if (bghAttr[s.OID].BGXW == "0") { buf.Value[bghTBBSMIndex] = ""; List gcFeatures = FeatureAPI.Identify2(s.ShapeCopy, tempLayer); if (gcFeatures.Count != 0) { int idx = tempLayer.FeatureClass.FindField("TBBGMJ"); double bgmj = 0; IGeometry tempGeo = null; foreach (var item in gcFeatures) { if (tempGeo == null) tempGeo = item.ShapeCopy; else tempGeo = FeatureAPI.Union(tempGeo, item.ShapeCopy); bgmj = Math.Round(bgmj + item.Value[idx].ToDouble(), 2); } if (!FeatureAPI.GetEqual(tempGeo, s.ShapeCopy)) { tempGeo = FeatureAPI.Difference(s.ShapeCopy, tempGeo); List jcFeatures = FeatureAPI.Identify2(tempGeo, jcDLTBLayer); idx = jcDLTBLayer.FeatureClass.FindField("TBMJ"); foreach (var item in jcFeatures) { bgmj = Math.Round(bgmj + item.Value[idx].ToDouble(), 2); } } if (bgmj == 0) continue; buf.Value[bgmjIndex] = bgmj; } else { List jcFeatures = FeatureAPI.Identify2(s.ShapeCopy, jcDLTBLayer); int idx = jcDLTBLayer.FeatureClass.FindField("TBMJ"); double bgmj = 0; foreach (var item in jcFeatures) { bgmj = Math.Round(bgmj + item.Value[idx].ToDouble(), 2); } if (bgmj == 0) continue; buf.Value[bgmjIndex] = bgmj; } } else if (bghAttr[s.OID].BGXW == "3") { double jsmj = (s.ShapeCopy as IPolygon).GetEllipseArea().ToDouble(2); double bgmj = buf.Value[bgmjIndex].ToDouble(); if (Math.Abs(jsmj - bgmj) > 500) { string xzqdm = buf.Value[bghZLDWDMIndex].ToTrim(); string mssm = buf.Value[bghMSSMIndex].ToTrim(); string xzqmc = ""; if (IsZLMCBG) { xzqmc = buf.Value[bghZLDWMCIndex].ToTrim(); } string key = xzqdm + "_" + mssm + "_" + xzqmc; if (dcmjList.ContainsKey(key)) { dcmjList[key] = dcmjList[key] - bgmj; buf.Value[bghDCMJIndex] = dcmjList[key]; } buf.Value[bgmjIndex] = jsmj; } } } if (xzqtzlx == 2 || xzqtzlx == 4) { for (int i = 0; i < gxgcFc.Fields.FieldCount; i++) { IField field = gxgcFc.Fields.Field[i]; if (field.Name.ToUpper().StartsWith("BGH")) { if (field.Type == esriFieldType.esriFieldTypeString) buf.Value[i] = DBNull.Value; else if (field.Type == esriFieldType.esriFieldTypeDouble) buf.Value[i] = 0; } } } if (buf.Value[bgmjIndex].ToDouble() == 0 || (buf.Value[bgqDCMJIndex].ToDouble(2) == buf.Value[bghDCMJIndex].ToDouble(2) && buf.Value[bgqZLDWDMIndex].ToTrim() == buf.Value[bghZLDWDMIndex].ToTrim() && buf.Value[bgqMSSMIndex].ToTrim() == buf.Value[bghMSSMIndex].ToTrim() && buf.Value[bgqZLDWMCIndex].ToTrim() == buf.Value[bghZLDWMCIndex].ToTrim())) { if (gxOID != -1 && buf.Value[bgmjIndex].ToDouble() != 0) { delFilter.WhereClause = string.Format("OBJECTID = {0}", gxOID); (o2 as ITable).DeleteSearchedRows(delFilter); } continue; } t_cursor.InsertFeature(buf); } t_cursor.Flush(); cursor = (o2 as ITable).Update(null, true); row = null; int bsmIndex = (o2 as ITable).FindField("BSM"); int tbmjIndex = (o2 as ITable).FindField("TBMJ"); int kcxsIndex = (o2 as ITable).FindField("KCXS"); int tbdlmjIndex = (o2 as ITable).FindField("TBDLMJ"); int dcmjIndex = (o2 as ITable).FindField("DCMJ"); int mssmIndex = (o2 as ITable).FindField("MSSM"); int xzqdmIndex = (o2 as ITable).FindField("ZLDWDM"); int xzqmcIndex = (o2 as ITable).FindField("ZLDWMC"); xzqtzlxIndex = (o2 as ITable).FindField("XZQTZLX"); gxsjIndex = (o2 as ITable).FindField("GXSJ"); while ((row = cursor.NextRow()) != null) { int xzqtzlx = 0; if (xzqtzlxIndex != -1) { xzqtzlx = row.Value[xzqtzlxIndex].ToInt(); } if (gxsjIndex != -1) { row.Value[gxsjIndex] = new DateTime(DateTime.Now.Year - 1, 12, 31); } if (gxAttr.ContainsKey(row.OID) && xzqtzlx != 2 && xzqtzlx != 4) { if (bsmIndex != -1) row.Value[bsmIndex] = gxAttr[row.OID].BSM; string xzqdm = row.Value[xzqdmIndex].ToTrim(); string mssm = row.Value[mssmIndex].ToTrim(); string hdmc = ""; if (IsZLMCBG) { hdmc = row.Value[xzqmcIdx].ToTrim(); } string key = xzqdm + "_" + mssm + "_" + hdmc; if (dcmjList.ContainsKey(key)) row.Value[dcmjIndex] = dcmjList[key].ToDouble(2); cursor.UpdateRow(row); } else { delFilter.WhereClause = string.Format("OBJECTID = {0}", row.OID); (o2 as ITable).DeleteSearchedRows(delFilter); } } cursor.Flush(); } catch (Exception ex) { LogAPI.Debug("生成更新过程数据失败:"); LogAPI.Debug(ex); } } #endregion #region TableToTable public static bool TableToTable(IFeatureWorkspace pInWork, IWorkspace pOutWork, string tableName, IQueryFilter queryFilter = null) { try { if (pInWork == null || pOutWork == null || string.IsNullOrEmpty(tableName)) return false; IWorkspace2 workspace2 = pInWork as IWorkspace2; if (workspace2 != null) { if (!workspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, tableName)) { return false; } } ITable pInTable = pInWork.OpenTable(tableName); if (pInTable == null) return false; IDataset pIndataset = (IDataset)pInTable; IDatasetName pInDatasetName = (IDatasetName)pIndataset.FullName; IEnumDataset enumDataset = pOutWork.get_Datasets(esriDatasetType.esriDTTable); IDataset dataset; enumDataset.Reset(); while ((dataset = enumDataset.Next()) != null) { string[] names = dataset.Name.Split('.'); if (string.Equals(names[names.Length - 1], tableName, StringComparison.CurrentCultureIgnoreCase)) { dataset.Delete(); break; } } IDataset pOutDataset = (IDataset)pOutWork; IDatasetName pOutDatasetName = new TableNameClass(); pOutDatasetName.WorkspaceName = (IWorkspaceName)pOutDataset.FullName; pOutDatasetName.Name = tableName; IFieldChecker fieldChecker = new FieldCheckerClass(); IFields targetFeatureClassFields = pInTable.Fields; IFields sourceFeatureClassFields = pInTable.Fields; IEnumFieldError enumFieldError; fieldChecker.InputWorkspace = pInWork as IWorkspace; fieldChecker.ValidateWorkspace = pOutWork; fieldChecker.Validate(sourceFeatureClassFields, out enumFieldError, out targetFeatureClassFields); IFeatureDataConverter one2another = new FeatureDataConverterClass(); try { one2another.ConvertTable(pInDatasetName, queryFilter, pOutDatasetName, targetFeatureClassFields, "", 1000, 0); } finally { Marshal.ReleaseComObject(one2another); } return true; } catch (Exception ex) { LogAPI.Debug(ex); throw ex; } } #endregion #region 获取最新标识码 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 #region SetAttribue public void SetAttribue(IFeatureClass pGxgcFc, IFeatureClass pJCFc, IFeatureClass pGxFc, ref Dictionary bghAttr, ref Dictionary gxAttr) { try { //IMapService _MapService = MapsManager.Instance.MapService; IFeatureLayer gxLayer = new FeatureLayerClass() { FeatureClass = pGxFc }; IFeatureClass jcFc = pJCFc; IQueryFilter filter = new QueryFilterClass() { SubFields = $"OBJECTID,FID_{JCTBName},BSM_1,FID_CJDCQGX,ZLDWDM,XZQTZLX" }; IFeatureCursor cursor = pGxgcFc.Search(filter, true); IFeature fe = null; int jcOIDIndex = pGxgcFc.FindField($"FID_{JCTBName}"); int jcBSMIndex = pGxgcFc.FindField("BSM_1"); int XZQTZLXIndex = pGxgcFc.FindField("XZQTZLX"); int gxOIDIndex = pGxgcFc.FindField("FID_CJDCQGX"); int gxZLDWDMIndex = pGxgcFc.FindField("ZLDWDM"); List txbgOID = new List(); List list = new List(); while ((fe = cursor.NextFeature()) != null) { int jcOID = (int)fe.Value[jcOIDIndex]; OIDMapping oMaping = new OIDMapping(); int gxOID = (int)fe.Value[gxOIDIndex]; oMaping.gcOID = fe.OID; oMaping.bgqOID = jcOID; oMaping.bgqTBBSM = fe.Value[jcBSMIndex].ToTrim(); oMaping.bghTBBSM = oMaping.bgqTBBSM; oMaping.bghTBBH = oMaping.bgqTBBH; oMaping.bghOID = gxOID; oMaping.bghZLDWDM = fe.Value[gxZLDWDMIndex].ToTrim(); oMaping.XZQTZLX = fe.Value[XZQTZLXIndex].ToTrim(); list.Add(oMaping); } string MaxBSM = string.Empty; if (string.IsNullOrWhiteSpace(MaxBSM)) MaxBSM = GetNewBSM(new List() { jcFc }); if (!MaxBSM.StartsWith(IDGParm.PrjInfo.CODE)) { MaxBSM = IDGParm.PrjInfo.CODE + MaxBSM.Substring(6); } IEnumerable> groupbgq = list.GroupBy(g => g.bgqOID); foreach (var item in groupbgq) { List tempList = item.ToList(); if (tempList.Count > 1) { double kzmj = tempList[0].BGMJ; tempList.ForEach(o => { string bgqBSM = string.Empty; string bghBSM = string.Empty; 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; o.IsTXBG = true; o.bghTBBSM = MaxBSM; o.IsSplit = true; IFeature gcF = pGxgcFc.GetFeature(o.gcOID); o.BGMJ = (gcF.ShapeCopy as IPolygon).GetEllipseArea(); Marshal.ReleaseComObject(gcF); }); } else { if (!tempList[0].bgqTBBSM.StartsWith(IDGParm.PrjInfo.CODE)) { string bsmPrefix = IDGParm.PrjInfo.CODE + MaxBSM.Substring(6, 4); int MaxNum = Convert.ToInt32(MaxBSM.Substring(10)); string bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); MaxBSM = bghBSM; tempList[0].bghTBBSM = MaxBSM; } } } groupbgq = list.GroupBy(g => g.bghOID); foreach (var item in groupbgq) { List tempList = item.ToList(); if (tempList.Count > 1) { string bgqBSM = string.Empty; string bghBSM = string.Empty; if (string.IsNullOrWhiteSpace(MaxBSM)) MaxBSM = GetNewBSM(new List() { jcFc }); 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; string bgqTBBH = string.Empty; string bghTBBH = string.Empty; string strZLDW = item.ToList()[0].bghZLDWDM; tempList.ForEach(o => { o.IsTXBG = true; o.bghTBBSM = MaxBSM; o.bghTBBH = bghTBBH; }); } else { if (!tempList[0].bgqTBBSM.StartsWith(IDGParm.PrjInfo.CODE)) { string bsmPrefix = IDGParm.PrjInfo.CODE + MaxBSM.Substring(6, 4); int MaxNum = Convert.ToInt32(MaxBSM.Substring(10)); string bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); MaxBSM = bghBSM; tempList[0].bghTBBSM = MaxBSM; } } } int idxBGQBSM = pGxgcFc.FindField("BSM_1"); int idxBGHZLDW = pGxgcFc.FindField("ZLDWDM"); List fcList = new List() { jcFc }; foreach (var item in list) { string tempBGXW = item.IsTXBG ? "2" : "1"; if (item.bgqOID == -1) { tempBGXW = "3"; } else if (item.bghOID == -1) { tempBGXW = "0"; item.bghTBBH = ""; item.bghTBBSM = ""; } if (!bghAttr.ContainsKey(item.gcOID)) { bghAttr.Add(item.gcOID, new BGHAttributeModel() { BGHOID = item.bghOID, BGHTBBH = item.bghTBBH, BGHBSM = item.bghTBBSM, BGMJ = item.BGMJ, BGXW = tempBGXW, XZQTZLX = item.XZQTZLX }); } else { bghAttr[item.gcOID] = new BGHAttributeModel() { BGHOID = item.bghOID, BGHTBBH = item.bghTBBH, BGHBSM = item.bghTBBSM, BGMJ = item.BGMJ, BGXW = tempBGXW, XZQTZLX = item.XZQTZLX }; } if (!gxAttr.ContainsKey(item.bghOID)) { gxAttr.Add(item.bghOID, new GXAttributeModel() { TBBH = item.bghTBBH, BSM = item.bghTBBSM, TBMJ = item.BGMJ }); } else { gxAttr[item.bghOID].TBMJ += item.BGMJ; } } } catch (Exception ex) { LogAPI.Debug("属性赋值失败:"); LogAPI.Debug(ex); } } #endregion #region ReturnMessages private static string ReturnMessages(Geoprocessor gp) { string ms = ""; if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { ms += "$" + gp.GetMessage(Count) + "\n\n"; } } return ms; } #endregion #region GetOutPutFeatureClass private static IFeatureClass GetOutPutFeatureClass(IGeoProcessorResult tGeoResult) { IGPUtilities pGPUtilities = new GPUtilitiesClass(); IFeatureClass pFeatureClass = null; IQueryFilter pQueryFilter = null; try { pGPUtilities.DecodeFeatureLayer(tGeoResult.GetOutput(0), out pFeatureClass, out pQueryFilter); return pFeatureClass; } catch (Exception ex) { throw new Exception("获取生成图层异常:" + ex.Message); } finally { if (pQueryFilter != null) { Marshal.ReleaseComObject(pQueryFilter); } } } #endregion public class CJDCQ_Param { public IFeatureLayer JCLayer { get; set; } public IFeatureLayer JCJXLayer { get; set; } public IFeatureLayer GXLayer { get; set; } public IFeatureLayer GXGCLayer { get; set; } public IFeatureLayer GXJXLayer { get; set; } public IFeatureLayer NMTBLayer { get; set; } public IFeatureLayer GXGCTBLayer { get; set; } public IFeatureLayer JCTBLayer { get; set; } } } }