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 IDEParameter; using KGIS.Framework.AE; using KGIS.Framework.AE.Enum; using KGIS.Framework.AE.GaussCalculate; using KGIS.Framework.AE.GPHelper; using KGIS.Framework.DBOperator; using KGIS.Framework.ThreadManager; using KGIS.Framework.Utils; using Kingo.PluginServiceInterface; using Kingo.PluginServiceInterface.Model; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Runtime.InteropServices; namespace IDGForNDBG { public class DLTB_IDGForThreadHelper : BaseIDG { private IFeatureClass BGFeatureClass = null; private IFeatureLayer JCFeatureLayer = null; //private IFeatureLayer BgTbLayer = null; //private IFeatureLayer GxgcTBLayer = null; //private IFeatureLayer GXPDTLayer = null; //private IFeatureLayer JCPDTLayer = null; private string TempDbPath = string.Empty; IWorkspace pOutWork = null; private IDGParameter Parm = null; private List DataPaths = new List(); public void ExecuteForThread(IDGParameter pIdgParm) { Parm = pIdgParm; IFeature f = null; IFeatureCursor pCursor = null; IFeatureClassAPI fcAPI = null; GPParamClass paramClass = new GPParamClass(); List _threadList = new List(); try { DateTime StartTime = DateTime.Now; Console.WriteLine($"Log:开始生成地类图斑更新数据..."); DLTB_IDGForThreadHelper2 helper = new DLTB_IDGForThreadHelper2(pIdgParm); DBLayerSourceHelper LaySourceHelper = helper.OpenDB(pIdgParm.PrjInfo); ITable dltbgxTb = LaySourceHelper.GxTbLayer.FeatureClass as ITable; IQueryFilter delFilter = new QueryFilterClass(); delFilter.WhereClause = "1=1"; dltbgxTb.DeleteSearchedRows(delFilter); ITable dltbgxgcTb = LaySourceHelper.GxgcTBLayer.FeatureClass as ITable; dltbgxgcTb.DeleteSearchedRows(delFilter); string TempDir = CreateTempDB("DLTB"); string _TempDbPath = System.IO.Path.Combine(TempDir, "TempGDB.gdb"); #region 判断是否存在坐落变更 提取相关数据 if (Parm.PrjInfo.ListZLXXInfo.Count > 0) { if (!string.IsNullOrWhiteSpace(Parm.PrjInfo.ListZLXXInfo[0].BGQDM) && !string.IsNullOrWhiteSpace(Parm.PrjInfo.ListZLXXInfo[0].BGHDM)) { Console.WriteLine("Msg:正在处理坐落变更数据..."); IWorkspaceAPI wsAPI = new WorkspaceAPI(_TempDbPath, WorkspaceTypeEnum.GDBFile); IFeatureClassAPI DLTBBG_ZLBGAPI = wsAPI.CreateFeatureClass("TempDLTBBG", (LaySourceHelper.BgTbLayer.FeatureClass as IGeoDataset).SpatialReference, LaySourceHelper.BgTbLayer.FeatureClass.Fields); foreach (var item in Parm.PrjInfo.ListZLXXInfo) { if (string.IsNullOrWhiteSpace(item.BGQDM.ToTrim()) || string.IsNullOrWhiteSpace(item.BGHDM.ToTrim())) continue; fcAPI = new FeatureClassAPI(LaySourceHelper.JcTbLayer.FeatureClass); IQueryFilter Tempfilter = new QueryFilterClass() { WhereClause = $"ZLDWDM like '{item.BGQDM }%'" }; fcAPI.FcToFc(DLTBBG_ZLBGAPI.FeatureClass, Tempfilter, false); ITable tempBGTb = DLTBBG_ZLBGAPI.FeatureClass as ITable; ICursor _cursor = tempBGTb.Update(Tempfilter, true); IRow _row = null; int _idx = DLTBBG_ZLBGAPI.FeatureClass.FindField("ZLDWDM"); int _idxQS = DLTBBG_ZLBGAPI.FeatureClass.FindField("QSDWDM"); while ((_row = _cursor.NextRow()) != null && _idx != -1) { _row.Value[_idx] = _row.Value[_idx].ToTrim().Replace(item.BGQDM, item.BGHDM); _row.Value[_idxQS] = _row.Value[_idxQS].ToTrim().Replace(item.BGQDM, item.BGHDM); _cursor.UpdateRow(_row); } _cursor.Flush(); } IFeatureLayer EraseAnalysisLayer = null; #region 变更图斑擦除坐落变更的图斑 paramClass = new GPParamClass(); paramClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = DLTBBG_ZLBGAPI.FeatureClass }; paramClass.SecondFeatureLayer = LaySourceHelper.BgTbLayer; paramClass.OutFeatureClassPath = $"{_TempDbPath}\\BGTB_Erase"; paramClass.IsGetOutPutFeature = true; paramClass.GPType = EnumGPType.Erase; GPHelper.Instance.ExeGPForProces(paramClass, ref EraseAnalysisLayer); #endregion ITable tempdltb = DLTBBG_ZLBGAPI.FeatureClass as ITable; tempdltb.DeleteSearchedRows(null); fcAPI = new FeatureClassAPI(EraseAnalysisLayer.FeatureClass); fcAPI.FcToFc(DLTBBG_ZLBGAPI.FeatureClass, null, false); fcAPI = new FeatureClassAPI(LaySourceHelper.BgTbLayer.FeatureClass); fcAPI.FcToFc(DLTBBG_ZLBGAPI.FeatureClass, null, false); LaySourceHelper.BgTbLayer.FeatureClass = DLTBBG_ZLBGAPI.FeatureClass; } } #endregion IQueryFilter filter = new QueryFilterClass(); filter.SubFields = "ZLDWDM"; pCursor = LaySourceHelper.BgTbLayer.FeatureClass.Search(filter, true); int idxZLDW = LaySourceHelper.BgTbLayer.FeatureClass.FindField("ZLDWDM"); List XzqList = new List(); while ((f = pCursor.NextFeature()) != null) { string zl = f.Value[idxZLDW].ToTrim(); if (zl.Length != 19) continue; string xzqdm = zl.Substring(0, 9); if (!XzqList.Contains(xzqdm)) { XzqList.Add(xzqdm); } } LayerCfg layerInfo = null; if (pIdgParm.PrjInfo != null && !string.IsNullOrWhiteSpace(pIdgParm.PrjInfo.TempData)) { byte[] contentArray = Convert.FromBase64String(pIdgParm.PrjInfo.TempData); string LayerCfg = System.Text.Encoding.Default.GetString(contentArray); layerInfo = KGIS.Framework.Utils.SerializeAPI.DeserializeToObject(LayerCfg); } ThreadParam para = new ThreadParam(); para.Layers = layerInfo.GetAllItem(); //para.Layers = new List(); para.StrJcTbLayer = GeoDBAPI.SerialzedPersist(LaySourceHelper.JcTbLayer); para.StrBgTbLayer = GeoDBAPI.SerialzedPersist(LaySourceHelper.BgTbLayer); int ProNum = Environment.ProcessorCount - 3; if (ProNum < 1) ProNum = 1; //ProNum = XzqList.Count; ProNum = 1; int ThreadNum = XzqList.Count / ProNum; if (XzqList.Count < ProNum) ThreadNum = 1; for (int i = 0; i < ProNum; i++) { List tempBsmList = new List(); if (i < ProNum - 1) { tempBsmList = XzqList.GetRange(i * ThreadNum, ThreadNum); } else { tempBsmList = XzqList.GetRange(i * ThreadNum, XzqList.Count - i * ThreadNum); } string _ThreadName = string.Empty; List _Codes = new List(); foreach (var xzq in tempBsmList) { _ThreadName += xzq.Replace(Parm.PrjInfo.CODE, ""); _Codes.Add(xzq); } if (ProNum == 1) { _Codes.Clear(); _ThreadName = "ALL"; } _threadList.Add(new ThreadParam() { ThreadName = _ThreadName, Codes = _Codes, ProjInfo = pIdgParm.PrjInfo, StrJcTbLayer = para.StrJcTbLayer, StrBgTbLayer = para.StrBgTbLayer, Layers = para.Layers }); } foreach (var itemThread in _threadList) { DLTB_IDGForThreadHelper2 helper2 = new DLTB_IDGForThreadHelper2(pIdgParm); ThreadManager.Instance.QueueUserWorkItem(new System.Threading.WaitCallback(helper2.Execute), itemThread); //break; } while (ThreadManager.Instance.ActiveCount > 0) { } //合库 foreach (var itemThread in _threadList) { //Directory.GetCurrentDirectory() + "\\Temp\\DLTB\\" string gdbPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Temp", "DLTB", itemThread.ThreadName, "ZLDB" + ".gdb"); if (!Directory.Exists(gdbPath)) continue; IWorkspaceAPI wsAPI = null; IFeatureClassAPI GxFcAPI = null; IFeatureClassAPI GxgcFcAPI = null; try { string strFilter = string.Empty; if (itemThread.Codes.Count > 0) { foreach (var xzq in itemThread.Codes) { strFilter += string.Format(" ZLDWDM like '{0}%' or", xzq); } strFilter = strFilter.TrimEnd('r').TrimEnd('o'); } IQueryFilter _Filter = new QueryFilterClass(); _Filter.WhereClause = strFilter; wsAPI = new WorkspaceAPI(gdbPath, WorkspaceTypeEnum.GDBFile); GxFcAPI = wsAPI.OpenFeatureClass("DLTBGX"); if (GxFcAPI.FeatureClass == null) continue; GxFcAPI.FcToFc(LaySourceHelper.GxTbLayer.FeatureClass, _Filter, false); GxgcFcAPI = wsAPI.OpenFeatureClass("DLTBGXGC"); if (GxgcFcAPI.FeatureClass == null) continue; _Filter.WhereClause = _Filter.WhereClause.Replace("ZLDWDM", "BGHZLDWDM"); GxgcFcAPI.FcToFc(LaySourceHelper.GxgcTBLayer.FeatureClass, _Filter, false); } catch (Exception ex) { Console.WriteLine("Err:合并数据库异常:" + ex.Message); Console.WriteLine("Err:合并数据库异常:" + ex.StackTrace); break; } finally { if (GxFcAPI != null) GxFcAPI.CloseFeatureClass(); if (GxgcFcAPI != null) GxgcFcAPI.CloseFeatureClass(); if (wsAPI != null) wsAPI.CloseWorkspace(); } } Console.WriteLine("Msg:正在进行属性赋值..."); #region 更新层/更新过程层 标识码,图斑编号等赋值 string TempDbPath = System.IO.Path.Combine(TempDir, "Temp" + ".sqlite"); IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + TempDbPath, DatabaseType.SQLite); IFeatureLayer Temp_DLTBGXGC = null; paramClass = new GPParamClass() { FirstFeatureLayer = LaySourceHelper.GxTbLayer, SecondFeatureLayer = LaySourceHelper.GxgcTBLayer, OutFeatureClassPath = $"{_TempDbPath}\\GX_GXGCUnion", IsGetOutPutFeature = true, PreserveAttributes = "ALL", GPType = EnumGPType.Union }; GPHelper.Instance.ExeGPForProces(paramClass, ref Temp_DLTBGXGC); IWorkspace ws = (Temp_DLTBGXGC.FeatureClass as FeatureClass).Workspace; rdbHelper.ExecuteSQL(" drop table GX_GXGCUnion "); IWorkspace pOutWork = CreateDBWorkspace(TempDbPath); TableToTable(ws as IFeatureWorkspace, pOutWork, "GX_GXGCUnion"); DataTable GX_GXGCUnion = rdbHelper.ExecuteDatatable("tab", "select FID_DLTBGX,FID_DLTBGXGC,TBBGMJ,ZLDWDM,BGXW,BGHTBBH,BGHTBBSM,BGQZLDWDM,BGHZLDWDM from GX_GXGCUnion", true); Dictionary bsmDic = new Dictionary(); Dictionary OIDdic = new Dictionary(); var strBSM = GetNewBSM(new List() { LaySourceHelper.JcTbLayer.FeatureClass }); Dictionary dicTBBH = new Dictionary(); GetMaxTBBH(LaySourceHelper.JcTbLayer.FeatureClass, ref dicTBBH); List DelGxOIDs = new List(); foreach (DataRow item in GX_GXGCUnion.Rows) { int gxID = item["FID_DLTBGX"].ToInt(); string zldwdm = item["ZLDWDM"].ToString(); string bgxw = item["BGXW"].ToString(); string TBBH = string.Empty; if (!bsmDic.ContainsKey(gxID)) { if (bgxw == "2" || (bgxw == "1" && item["BGQZLDWDM"].ToTrim() != item["BGHZLDWDM"].ToTrim())) { if (bgxw == "2") { var strbsm = strBSM.Substring(0, 10); var Maxbsm = strBSM.Substring(10).ToInt() + 1; strBSM = strbsm + Maxbsm.ToString().PadLeft(8, '0');//最新标识码 } if (dicTBBH.ContainsKey(zldwdm)) { dicTBBH[zldwdm] = dicTBBH[zldwdm] + 1;//最大图斑编号-去最新值 TBBH = dicTBBH[zldwdm].ToTrim(); } else { dicTBBH.Add(zldwdm, 1); TBBH = dicTBBH[zldwdm].ToTrim(); } if (bgxw == "2") { bsmDic.Add(gxID, new string[] { strBSM, TBBH }); } else { bsmDic.Add(gxID, new string[] { item["BGHTBBSM"].ToString(), TBBH }); } } else { bsmDic.Add(gxID, new string[] { item["BGHTBBSM"].ToString(), item["BGHTBBH"].ToString() }); } } int gxgcID = item["FID_DLTBGXGC"].ToInt(); if (gxgcID == -1) { DelGxOIDs.Add(gxID); } if (!OIDdic.ContainsKey(gxgcID)) { OIDdic.Add(gxgcID, gxID); } } pCursor = LaySourceHelper.GxTbLayer.FeatureClass.Update(null, true); var _index_BSM = LaySourceHelper.GxTbLayer.FeatureClass.FindField("BSM"); var _index_YSDM = LaySourceHelper.GxTbLayer.FeatureClass.FindField("YSDM");//2001010100 var _index_TBBH = LaySourceHelper.GxTbLayer.FeatureClass.FindField("TBBH"); var _index_TBMJ = LaySourceHelper.GxTbLayer.FeatureClass.FindField("TBMJ"); var _index_KCXS = LaySourceHelper.GxTbLayer.FeatureClass.FindField("KCXS"); var _index_KCMJ = LaySourceHelper.GxTbLayer.FeatureClass.FindField("KCMJ"); var _index_TBDLMJ = LaySourceHelper.GxTbLayer.FeatureClass.FindField("TBDLMJ"); var igx_gxsj = LaySourceHelper.GxTbLayer.FeatureClass.FindField("GXSJ"); var igx_xzqtzlx = LaySourceHelper.GxTbLayer.FeatureClass.FindField("XZQTZLX"); IFeature feature = null; while ((feature = pCursor.NextFeature()) != null) { int oid = feature.OID; if (DelGxOIDs.Contains(oid)) { feature.Value[_index_BSM] = "Del"; pCursor.UpdateFeature(feature); continue; } if (bsmDic.ContainsKey(oid)) { string[] arr = bsmDic[oid]; feature.Value[_index_BSM] = arr[0]; feature.Value[_index_TBBH] = arr[1]; } var kcxs = feature.Value[_index_KCXS].ToDouble();//扣除系数 feature.Value[_index_YSDM] = "2001010100";//要素代码 DataRow[] row = GX_GXGCUnion.Select($"FID_DLTBGX={feature.OID}"); double mj = 0.00; if (row.Length > 0) { string gxgcid = string.Join(" or ", row.Select(r => $"OBJECTID = {r["FID_DLTBGXGC"].ToString()}")).ToString(); mj = row.Select(r => r["TBBGMJ"].ToDouble()).Sum().ToDouble(2); } feature.Value[_index_TBMJ] = mj; feature.Value[_index_KCMJ] = Math.Round(mj * kcxs, 2); feature.Value[_index_TBDLMJ] = Math.Round(mj - mj * kcxs, 2); feature.Value[igx_gxsj] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31); feature.Value[igx_xzqtzlx] = 0; pCursor.UpdateFeature(feature); } pCursor.Flush(); (LaySourceHelper.GxTbLayer.FeatureClass as ITable).DeleteSearchedRows(new QueryFilterClass() { WhereClause = "BSM = 'Del'" }); pCursor = LaySourceHelper.GxgcTBLayer.FeatureClass.Update(null, true); int iBGHTBBSM = LaySourceHelper.GxgcTBLayer.FeatureClass.FindField("BGHTBBSM"); int iBGHTBBH = LaySourceHelper.GxgcTBLayer.FeatureClass.FindField("BGHTBBH"); var igxgc_xzqtzlx = LaySourceHelper.GxgcTBLayer.FeatureClass.FindField("XZQTZLX"); while ((feature = pCursor.NextFeature()) != null) { var xzqtzlx = feature.Value[igxgc_xzqtzlx].ToTrim(); if (xzqtzlx == "2" || xzqtzlx == "4") { if (string.IsNullOrWhiteSpace(xzqtzlx)) feature.Value[igxgc_xzqtzlx] = 0; else feature.Value[igxgc_xzqtzlx] = xzqtzlx; } else { int oid = feature.OID; if (OIDdic.ContainsKey(oid)) { int gxOID = OIDdic[oid]; if (bsmDic.ContainsKey(gxOID)) { string[] arr = bsmDic[gxOID]; feature.Value[iBGHTBBSM] = arr[0]; feature.Value[iBGHTBBH] = arr[1]; } } } pCursor.UpdateFeature(feature); } pCursor.Flush(); #endregion GDPDExcute2(LaySourceHelper, _TempDbPath); rdbHelper.ExecuteSQL(" drop table DLTBGXGC "); TableToTable((LaySourceHelper.GxgcTBLayer.FeatureClass as FeatureClass).Workspace as IFeatureWorkspace, pOutWork, "DLTBGXGC"); DataTable DtDLTBGXGC = rdbHelper.ExecuteDatatable("tab", @"select BGHTBBSM from DLTBGXGC WHERE BGXW = 1 and (BGQZLDWDM != BGHZLDWDM or BGQZLDWMC!=BGHZLDWMC or BGQQSDWDM!=BGHQSDWDM or BGQQSDWMC!=BGHQSDWMC) and TRIM(IfNull(BGQDLBM,'')) = TRIM(IfNull(BGHDLBM,'')) and TRIM(IfNull(BGQDLMC,'')) = TRIM(IfNull(BGHDLMC,'')) and TRIM(IfNull(BGQQSXZ,'')) = TRIM(IfNull(BGHQSXZ,'')) and TRIM(IfNull(BGQKCDLBM,'')) = TRIM(IfNull(BGHKCDLBM,'')) and TRIM(IfNull(BGQKCXS,'')) = TRIM(IfNull(BGHKCXS,'')) and TRIM(IfNull(BGQGDLX,'')) = TRIM(IfNull(BGHGDLX,'')) and TRIM(IfNull(BGQGDPDJB,'')) = TRIM(IfNull(BGHGDPDJB,'')) and TRIM(IfNull(BGQXZDWKD,'')) = TRIM(IfNull(BGHXZDWKD,'')) and TRIM(IfNull(BGQTBXHDM,'')) = TRIM(IfNull(BGHTBXHDM,'')) and TRIM(IfNull(BGQTBXHMC,'')) = TRIM(IfNull(BGHTBXHMC,'')) and TRIM(IfNull(BGQZZSXDM,'')) = TRIM(IfNull(BGHZZSXDM,'')) and TRIM(IfNull(BGQZZSXMC,'')) = TRIM(IfNull(BGHZZSXMC,'')) and TRIM(IfNull(BGQGDDB,'')) = TRIM(IfNull(BGHGDDB,'')) and TRIM(IfNull(BGQFRDBS,'')) = TRIM(IfNull(BGHFRDBS,'')) and TRIM(IfNull(BGQCZCSXM,'')) = TRIM(IfNull(BGHCZCSXM,''))", true); if (DtDLTBGXGC != null && DtDLTBGXGC.Rows.Count > 0) { List bghbsm = DtDLTBGXGC.Rows.OfType().Select(r => $"{r["BGHTBBSM"].ToString()}").ToList(); int ibghtbbsm = LaySourceHelper.GxgcTBLayer.FeatureClass.FindField("BGHTBBSM"); int ijczt = LaySourceHelper.GxgcTBLayer.FeatureClass.FindField("ONLYZLBG"); pCursor = LaySourceHelper.GxgcTBLayer.FeatureClass.Update(null, true); while ((feature = pCursor.NextFeature()) != null) { string bghtbbsm = feature.Value[ibghtbbsm].ToString(); if (bghbsm.Contains(bghtbbsm)) { feature.Value[ijczt] = "1"; pCursor.UpdateFeature(feature); } } pCursor.Flush(); pCursor = LaySourceHelper.GxTbLayer.FeatureClass.Update(null, true); ijczt = LaySourceHelper.GxTbLayer.FeatureClass.FindField("ONLYZLBG"); int ibsm = LaySourceHelper.GxTbLayer.FeatureClass.FindField("BSM"); while ((feature = pCursor.NextFeature()) != null) { string bsm = feature.Value[ibsm].ToString(); if (bghbsm.Contains(bsm)) { feature.Value[ijczt] = "1"; pCursor.UpdateFeature(feature); } } pCursor.Flush(); } Console.WriteLine("Msg:正在生成年末数据..."); base.CreateNMK(LaySourceHelper); Console.WriteLine($"Log:地类图斑数据提取完成。耗时:{GetTime(StartTime)}"); } catch (Exception ex) { Console.WriteLine($"Err:错误信息---" + ex.Message); Console.WriteLine($"Err:错误信息---" + ex.StackTrace); throw ex; } finally { if (pCursor != null) Marshal.ReleaseComObject(pCursor); } } /// /// 耕地坡度级别赋值 /// public void GDPDExcute2(DBLayerSourceHelper pLaySourceHelper, string pTempGDbPath) { IFeatureClassAPI GXAPI = null; IFeatureClassAPI GXGCAPI = null; IFeatureClassAPI pdtFcAPI = null; IFeatureLayer PDTLayer = null; IFeature feature = null; IFeature gxgcfeature = null; IFeatureCursor cursor = null; IWorkspaceFactory pFtWsFct = null; IWorkspaceName workspaceName = null; IFeatureLayer unionLayer = null; IFeatureClassAPI unionFcAPI = null; List unFcList = null; //IRDBHelper rdbHelper = null; try { //ProgressHelper.ShowProcessBar("正在进行耕地坡度级别赋值,请稍后……"); //string dbPath = System.IO.Path.GetDirectoryName(Platform.Instance.MapsService.GetProjectInfo().GetProjDBPath()) + @"\BGTJ.sqlite"; //rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, Framework.DBOperator.DatabaseType.SQLite); List sqllist = new List(); //string MDBPath = Platform.Instance.MapsService.GetProjectInfo().GetProjDBPath(); #region 变更图斑层(GDB) // 获取变更图斑 GXAPI = new FeatureClassAPI(pLaySourceHelper.GxTbLayer.FeatureClass); if (GXAPI == null || GXAPI.FeatureClass == null) { //MessageHelper.ShowError("未获取到更新层图斑"); return; } GXGCAPI = new FeatureClassAPI(pLaySourceHelper.GxgcTBLayer.FeatureClass); if (GXGCAPI == null || GXGCAPI.FeatureClass == null) { //MessageHelper.ShowError("未获取到更新过程层图斑"); return; } #endregion #region 坡度图层(MDB) // 获取坡度图 pdtFcAPI = new FeatureClassAPI(pLaySourceHelper.GxPdtLayer.FeatureClass); if (pdtFcAPI == null || pdtFcAPI.FeatureClass == null) { //MessageHelper.ShowError("未获取到坡度图更新层图斑"); return; } PDTLayer = pLaySourceHelper.GxPdtLayer; if (pdtFcAPI.FeatureClass.FeatureCount(null) <= 0) { pdtFcAPI = new FeatureClassAPI(pLaySourceHelper.JcPdtLayer.FeatureClass); PDTLayer = pLaySourceHelper.JcPdtLayer; } if (pdtFcAPI.FeatureClass.FeatureCount(null) <= 0) { //MessageHelper.ShowError("当前工程中未导入坡度数据!"); return; } #endregion //ProgressHelper.ShowProcessBar("正在处理数据……"); //准备临时文件 string Temp = Directory.GetCurrentDirectory() + "\\Temp\\TempBGFile"; if (!System.IO.Directory.Exists(Temp)) { System.IO.Directory.CreateDirectory(Temp); } string mdbFileName = Guid.NewGuid().ToString(); string path = System.IO.Path.Combine(Temp, mdbFileName);//合并一个路径 pFtWsFct = new FileGDBWorkspaceFactory(); workspaceName = pFtWsFct.Create(path, "TempGDB", null, 0); string TempmdbPath = System.IO.Path.Combine(path, "TempGDB.gdb"); IWorkspaceAPI psTempWorkspaceAPI = new WorkspaceAPI(TempmdbPath, WorkspaceTypeEnum.GDBFile); IFeatureClassAPI tempdltbgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("TempDLTBGX", (GXAPI.FeatureClass as IGeoDataset).SpatialReference, GXAPI.FeatureClass.Fields); tempdltbgxFeatureclassAPI.AddField("OLDOBJECTID", esriFieldType.esriFieldTypeInteger, "老OBJECTID"); IFeatureClass tempdltbgxFC = tempdltbgxFeatureclassAPI.FeatureClass; Dictionary fieldsDic = new Dictionary(); for (int i = 0; i < tempdltbgxFC.Fields.FieldCount; i++) { IField field = tempdltbgxFC.Fields.Field[i]; if (field.Name == tempdltbgxFC.ShapeFieldName || field.Name.Contains(tempdltbgxFC.ShapeFieldName) || field.Name == tempdltbgxFC.OIDFieldName || !field.Editable) continue; int index = -1; index = GXAPI.FeatureClass.Fields.FindField(field.Name); if (index == -1) index = GXAPI.FeatureClass.Fields.FindFieldByAliasName(field.AliasName); if (index == -1) continue; fieldsDic.Add(i, index); } if (fieldsDic.Count == 0) return; IFeatureBuffer buffer = tempdltbgxFC.CreateFeatureBuffer(); IFeatureCursor tempgxCursor = tempdltbgxFC.Insert(true); int oldOIDIndex = tempdltbgxFC.FindField("OLDOBJECTID"); if (oldOIDIndex == -1) return; IQueryFilter queryfilter = new QueryFilterClass(); queryfilter.WhereClause = string.Format("DLBM like '01%' "); int gdCount = GXAPI.FeatureClass.FeatureCount(queryfilter); if (gdCount == 0) return; IFeature gxtbFeature = null; IFeatureCursor dltbgxCursor = GXAPI.FeatureClass.Search(queryfilter, true); int OIDIndex = GXAPI.FeatureClass.FindField("OBJECTID"); int num = 0; while ((gxtbFeature = dltbgxCursor.NextFeature()) != null) { num++; buffer.Shape = gxtbFeature.ShapeCopy; foreach (int item in fieldsDic.Keys) { if (string.IsNullOrWhiteSpace(gxtbFeature.Value[fieldsDic[item]].ToTrim())) buffer.Value[item] = DBNull.Value; buffer.Value[item] = gxtbFeature.Value[fieldsDic[item]]; } buffer.Value[oldOIDIndex] = gxtbFeature.Value[OIDIndex]; tempgxCursor.InsertFeature(buffer); if (num % 1000 == 0) { tempgxCursor.Flush(); } Marshal.ReleaseComObject(gxtbFeature); } tempgxCursor.Flush(); //DLTBGX与PDTGX 相交 GPParamClass gPParamClass = new GPParamClass(); gPParamClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = tempdltbgxFC };// pLaySourceHelper.BgTbLayer; gPParamClass.SecondFeatureLayer = PDTLayer; gPParamClass.OutFeatureClassPath = pTempGDbPath + "\\TB_PD"; gPParamClass.IsGetOutPutFeature = true; gPParamClass.GPType = EnumGPType.Identify; GPHelper.Instance.ExeGPForProces(gPParamClass, ref unionLayer); unionFcAPI = new FeatureClassAPI(unionLayer.FeatureClass); cursor = unionFcAPI.FeatureClass.Search(null, true); feature = null; Dictionary DicPDJB = new Dictionary(); Dictionary DicMJ = new Dictionary(); Dictionary> DicPDJB_MJ = new Dictionary>(); int idxOID = unionFcAPI.FeatureClass.FindField("OLDOBJECTID"); if (idxOID == -1) { return; } int idxArea = unionFcAPI.FeatureClass.FindField("SHAPE_AREA"); int idxPDJB = unionFcAPI.FeatureClass.FindField("PDJB"); while ((feature = cursor.NextFeature()) != null) { int oid = Convert.ToInt32(feature.Value[idxOID].ToTrim()); if (oid == 456) { } double area = feature.Value[idxArea].ToDouble(2); string pdjb = feature.Value[idxPDJB].ToTrim(); if (!DicPDJB_MJ.ContainsKey(oid)) { DicPDJB_MJ.Add(oid, new List() { new PDJBModel() { PDJB = pdjb, MJ = area } }); } else { List list = DicPDJB_MJ[oid]; PDJBModel pdjbMod = list.FirstOrDefault(f => f.PDJB == pdjb); if (pdjbMod == null) { list.Add(new PDJBModel() { PDJB = pdjb, MJ = area }); } else { pdjbMod.MJ += area; } DicPDJB_MJ[oid] = list; } if (!DicMJ.ContainsKey(oid)) { DicMJ.Add(oid, area); DicPDJB.Add(oid, pdjb); } else if (DicMJ[oid] < area) { DicMJ[oid] = area; DicPDJB[oid] = pdjb; } } cursor = GXAPI.FeatureClass.Update(new QueryFilter() { WhereClause = "DLBM like '01%' " }, false); int Objectid_GX = GXAPI.FeatureClass.FindField("objectid"); int BSM_GX = GXAPI.FeatureClass.FindField("BSM"); int GDPDJB_GX = GXAPI.FeatureClass.FindField("GDPDJB"); int GDLX_GX = GXAPI.FeatureClass.FindField("GDLX"); int DLBM_GX = GXAPI.FeatureClass.FindField("DLBM"); int GDPDJB_GXGC = GXGCAPI.FeatureClass.FindField("BGHGDPDJB"); int GDLX_GXGC = GXGCAPI.FeatureClass.FindField("BGHGDLX"); int DLBM_GXGC = GXGCAPI.FeatureClass.FindField("BGHDLBM"); int GDPDJBIndex = pdtFcAPI.FeatureClass.FindField("PDJB"); var count = GXAPI.FeatureClass.FeatureCount(new QueryFilter() { WhereClause = "DLBM like '01%' " }); var featurecount = 0; while ((feature = cursor.NextFeature()) != null) { featurecount++; //ProgressHelper.ShowProcessBar($"正在进行耕地坡度赋值...【{featurecount}/{count}】"); //查询union图层 //unFcList = unionFcAPI.QueryFeatures(GeoDBAPI.CreateQueryFilter("FID_DLTBGX =" + feature.Value[Objectid_GX])); //unFcList = unionFcAPI.QueryFeatures(GeoDBAPI.CreateQueryFilter("OLDOBJECTID =" + feature.Value[Objectid_GX])); //if (unFcList.Count == 0) //{ // continue; //} if (feature.OID == 529) { } string pdjb = string.Empty; if (!DicPDJB_MJ.ContainsKey(feature.OID)) { continue; } List list = DicPDJB_MJ[feature.OID]; list = list.OrderByDescending(o => o.MJ).ToList(); pdjb = list[0].PDJB;//[feature.OID]; //if (unFcList != null && unFcList.Count == 1) //{ // pdjb = unFcList[0].Value[unFcList[0].Fields.FindField("PDJB")].ToString(); //} //else if (unFcList != null && unFcList.Count > 1) //{ // switch (SumType) // { // case PDJSumType.PDMax: // pdjb = GetPDMaxValue(unFcList, null); // break; // case PDJSumType.PDMin: // pdjb = GetPDMinValue(unFcList, null); // break; // case PDJSumType.MJMax: // pdjb = GetMJMaxValue2(unFcList); // break; // case PDJSumType.PDAvg: // pdjb = GetPDAvgValue(unFcList, null); // break; // case PDJSumType.Weight: // pdjb = GetWeightValue(unFcList); // break; // default: // break; // } //} feature.Value[GDPDJB_GX] = pdjb; string dlbm = feature.Value[DLBM_GX].ToString(); string bghbsm = feature.Value[BSM_GX].ToString(); string UpdateGCSql = string.Empty; string strGDLX = feature.Value[GDLX_GX].ToTrim(); if (pdjb == "1") { strGDLX = ""; } //if (!string.IsNullOrWhiteSpace(dlbm) && "2,3,4,5".Contains(pdjb)) //{ // if (dlbm == "0101") // { // strGDLX = "TT"; // //feature.Value[GDLX_GX] = "TT"; // } // else if ("0102,0103".Contains(dlbm)) // { // //UpdateGCSql = string.Format("update DLTBGXGC set BGHGDPDJB='{0}', BGHGDLX='{1}' where BGHTBBSM='{2}'", pdjb, "PD", bghbsm); // strGDLX = "PD"; // } //} feature.Value[GDLX_GX] = strGDLX; UpdateGCSql = string.Format("update DLTBGXGC set BGHGDPDJB='{0}', BGHGDLX='{1}' where BGHTBBSM='{2}'", pdjb, strGDLX, bghbsm); //UpdateGCSql = string.Format("update DLTBGXGC set BGHGDPDJB='{0}' where BGHTBBSM='{1}'", pdjb, bghbsm); if (!string.IsNullOrWhiteSpace(UpdateGCSql)) (GXGCAPI.FeatureClass as FeatureClass).Workspace.ExecuteSQL(UpdateGCSql); cursor.UpdateFeature(feature); //IFeatureCursor gxCursor = GXGCAPI.FeatureClass.Update(new QueryFilter() { WhereClause = string.Format("BGHTBBSM ='{0}'", bghbsm) }, false); //IFeature gxFeature = null; //while ((gxFeature = gxCursor.NextFeature()) != null) //{ // gxFeature.Value[GDPDJB_GXGC] = pdjb; // string bghdlbm = gxFeature.Value[DLBM_GXGC].ToString(); // if (!string.IsNullOrWhiteSpace(bghdlbm) && "2,3,4,5".Contains(pdjb)) // { // if (bghdlbm == "0101") // gxFeature.Value[GDLX_GXGC] = "TT"; // else if ("0102,0103".Contains(bghdlbm)) // gxFeature.Value[GDLX_GXGC] = "PD"; // } // gxCursor.UpdateFeature(gxFeature); // Marshal.ReleaseComObject(gxFeature); //} //if (!string.IsNullOrWhiteSpace(dlbm) && "2,3,4,5".Contains(pdjb)) //{ // if (dlbm == "0101") // sqllist.Add(string.Format("update BHXXB set BGHGDPDJB='{0}', BGHGDLX='{1}' where BGHTBBSM='{2}'", pdjb, "TT", bghbsm)); // else if ("0102,0103".Contains(dlbm)) // sqllist.Add(string.Format("update BHXXB set BGHGDPDJB='{0}', BGHGDLX='{1}' where BGHTBBSM='{2}'", pdjb, "PD", bghbsm)); //} //else //{ sqllist.Add(string.Format("update BHXXB set BGHGDPDJB='{0}', BGHGDLX='{1}' where BGHTBBSM='{2}'", pdjb, strGDLX, bghbsm)); //} Marshal.ReleaseComObject(feature); } //rdbHelper.BeginTransaction(); //try //{ // foreach (string item in sqllist) // { // rdbHelper.ExecuteNonQuery(item, CommandType.Text); // } //} //catch (Exception ex) //{ // rdbHelper.Rollback(); //} //rdbHelper.Commit(); //ProgressHelper.CloseProcessBar(); //MessageHelper.ShowTips("耕地坡度赋值完成!"); } catch (Exception ex) { //ProgressHelper.CloseProcessBar(); LogAPI.Debug("Err:耕地坡度级别赋值异常" + ex.Message); LogAPI.Debug("Err:耕地坡度级别赋值异常" + ex.StackTrace); //MessageHelper.ShowError("耕地坡度级别赋值异常:" + ex.Message); } finally { //ProgressHelper.CloseProcessBar(); if (feature != null) Marshal.ReleaseComObject(feature); if (gxgcfeature != null) Marshal.ReleaseComObject(gxgcfeature); if (cursor != null) Marshal.ReleaseComObject(cursor); if (pFtWsFct != null) Marshal.ReleaseComObject(pFtWsFct); if (workspaceName != null) Marshal.ReleaseComObject(workspaceName); if (unionLayer != null) Marshal.ReleaseComObject(unionLayer); //if (rdbHelper != null) //{ // rdbHelper.DisConnect(); //} } } private IWorkspace CreateDBWorkspace(string pDbPath) { try { if (!File.Exists(pDbPath)) { Console.WriteLine(string.Format("指定的文件路径{0}不存在!", pDbPath)); return null; } IWorkspaceFactory pOutWorkFactory = null; pOutWorkFactory = new SqlWorkspaceFactoryClass(); IWorkspace pOutWork = pOutWorkFactory.OpenFromFile(pDbPath, 0); return pOutWork; } catch (Exception ex) { //Console.WriteLine($"Log:CreateDBWorkspace错误:{ex.Message}"); throw; } } #region TableToTable public bool TableToTable(IFeatureWorkspace pInWork, IWorkspace pOutWork, string tableName, IQueryFilter queryFilter = null) { try { if (pInWork == null || pOutWork == null || string.IsNullOrEmpty(tableName)) return false; IWorkspace2 workspace2 = pInWork as IWorkspace2; if (workspace2 != null) { if (!workspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, tableName)) { return false; } } ITable pInTable = pInWork.OpenTable(tableName); if (pInTable == null) return false; IDataset pIndataset = (IDataset)pInTable; IDatasetName pInDatasetName = (IDatasetName)pIndataset.FullName; IEnumDataset enumDataset = pOutWork.get_Datasets(esriDatasetType.esriDTTable); IDataset dataset; enumDataset.Reset(); while ((dataset = enumDataset.Next()) != null) { string[] names = dataset.Name.Split('.'); if (string.Equals(names[names.Length - 1], tableName, StringComparison.CurrentCultureIgnoreCase)) { dataset.Delete(); break; } } IDataset pOutDataset = (IDataset)pOutWork; IDatasetName pOutDatasetName = new TableNameClass(); pOutDatasetName.WorkspaceName = (IWorkspaceName)pOutDataset.FullName; pOutDatasetName.Name = tableName; IFieldChecker fieldChecker = new FieldCheckerClass(); IFields targetFeatureClassFields = pInTable.Fields; IFields sourceFeatureClassFields = pInTable.Fields; IEnumFieldError enumFieldError; fieldChecker.InputWorkspace = pInWork as IWorkspace; fieldChecker.ValidateWorkspace = pOutWork; fieldChecker.Validate(sourceFeatureClassFields, out enumFieldError, out targetFeatureClassFields); IFeatureDataConverter one2another = new FeatureDataConverterClass(); try { one2another.ConvertTable(pInDatasetName, queryFilter, pOutDatasetName, targetFeatureClassFields, "", 1000, 0); } finally { Marshal.ReleaseComObject(one2another); } return true; } catch (Exception ex) { LogAPI.Debug("Err:TableToTable异常" + ex.Message); LogAPI.Debug("Err:TableToTable异常" + ex.StackTrace); throw ex; } } #endregion #region 获取最新图斑编号 private void GetMaxTBBH(IFeatureClass fc, ref Dictionary result) { ICursor cursor = (fc as ITable).Search(new QueryFilterClass() { SubFields = "ZLDWDM,TBBH" }, true); IRow row = null; int zlIndex = -1; int bhIndex = -1; while ((row = cursor.NextRow()) != null) { if (zlIndex == -1) zlIndex = row.Fields.FindField("ZLDWDM"); if (bhIndex == -1) bhIndex = row.Fields.FindField("TBBH"); if (zlIndex != -1 && bhIndex != -1) { string zl = row.Value[zlIndex].ToTrim(); zl = zl.Replace(zl.Substring(0, 6), Parm.PrjInfo.CODE); int tbbh = 0; int.TryParse(row.Value[bhIndex].ToString(), out tbbh); if (result.ContainsKey(zl)) { if (result[zl] < tbbh) result[zl] = tbbh; } else { result.Add(zl, tbbh); } } } } #endregion #region 获取最新标识码 public string GetNewBSM(List fcList) { string result = string.Empty; int xh = 0; string leftStr = string.Empty; foreach (var item in fcList) { string MaxBSM = GetMaxBSM(item); if (MaxBSM.Length != 18) continue; int xh2 = Convert.ToInt32(MaxBSM.Substring(10)); leftStr = MaxBSM.Substring(0, 10); if (xh < xh2) xh = xh2; } xh++; if (string.IsNullOrWhiteSpace(leftStr)) leftStr = Parm.PrjInfo.CODE + "1210"; result = leftStr + xh.ToString().PadLeft(8, '0'); return result; } private static string GetMaxBSM(IFeatureClass fc) { string BSM = string.Empty; int BSMIndex = fc.FindField("BSM"); if (BSMIndex == -1) return BSM; ITable table = (ITable)fc; // 创建一个ITableSort接口对象 ITableSort tableSort = new TableSortClass(); tableSort.Table = table; 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 } public class DLTB_IDGForThreadHelper2 : BaseIDG { private string Lock = ""; private IDGParameter Parm = null; private string TempDbPath = string.Empty; public DLTB_IDGForThreadHelper2(IDGParameter pParm) { Parm = pParm; } public void Execute(object pThreadParm) { IFeatureLayer _JcTbLayer = null; IFeatureLayer _BgTbLayer = null; IWorkspaceAPI _WsAPI = null; IFeatureClassAPI _JcFcAPI = null; IFeatureClassAPI _BgFcAPI = null; IFeatureCursor pCursor = null; IFeature feature = null; ThreadParam _Parm = null; try { _Parm = pThreadParm as ThreadParam; string TempPath = CreateTempFile(_Parm.ThreadName); string TempDbPath = System.IO.Path.Combine(TempPath, _Parm.ThreadName + ".sqlite"); string TempGDbPath = System.IO.Path.Combine(TempPath, _Parm.ThreadName + ".gdb"); string TempGDbPath2 = System.IO.Path.Combine(TempPath, "ZLDB" + ".gdb"); DirectoryCopy(_Parm.ProjInfo.ZLDatabase, TempPath); FileInfo fInfo = new FileInfo(_Parm.ProjInfo.ZLDatabase); _Parm.ProjInfo.ZLDatabase = System.IO.Path.Combine(TempPath, fInfo.Name); DBLayerSourceHelper LaySourceHelper = OpenDB(_Parm.ProjInfo); ProcessBGTB(LaySourceHelper, TempGDbPath2); LaySourceHelper.JcTbLayer = GeoDBAPI.DeSerialzedPersist(_Parm.StrJcTbLayer) as IFeatureLayer; LaySourceHelper.BgTbLayer = GeoDBAPI.DeSerialzedPersist(_Parm.StrBgTbLayer) as IFeatureLayer; GPParamClass paramClass = new GPParamClass(); string strFilter = string.Empty; if (_Parm.Codes.Count > 0) { foreach (var xzq in _Parm.Codes) { strFilter += string.Format(" ZLDWDM like '{0}%' or", xzq); } strFilter = strFilter.TrimEnd('r').TrimEnd('o'); } if (string.IsNullOrWhiteSpace(strFilter)) strFilter = "1=1"; paramClass.FirstFeatureLayer = LaySourceHelper.JcTbLayer;// GeoDBAPI.DeSerialzedPersist(_Parm.StrJcTbLayer) as IFeatureLayer; paramClass.SecondFeatureLayer = LaySourceHelper.BgTbLayer;// GeoDBAPI.DeSerialzedPersist(_Parm.StrBgTbLayer) as IFeatureLayer; paramClass.Where_clause = strFilter; paramClass.TempGDBPath = TempPath; paramClass.IsGetOutPutFeature = true; paramClass.GPType = EnumGPType.BGTBYCL; paramClass.XZQDM = _Parm.ProjInfo.CODE; IFeatureLayer Temp_DLTBGXGC = null; GPHelper helper = new GPHelper(); helper.ExeGPForProces(paramClass, ref Temp_DLTBGXGC); IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + TempDbPath, DatabaseType.SQLite); Console.WriteLine("Msg:正在进行变更行为赋值..."); #region BGXW=2 //变更图斑与基础库图斑一对多 rdbHelper.ExecuteSQL(" UPDATE GXGC_Multipart set BGXW='2' where FID_DLTBBG in (select FID_DLTBBG from GXGC_Multipart where FID_DLTBBG <> -1 GROUP BY FID_DLTBBG HAVING COUNT(FID_DLTBBG) > 1) "); rdbHelper.ExecuteSQL(@" UPDATE GXGC_Multipart set BGXW='2' where BGXW ISNULL and FID_DLTB in (select FID_DLTB from GXGC_Multipart GROUP BY FID_DLTB HAVING COUNT(FID_DLTB) > 1 ) "); #endregion #region BGXW=1 rdbHelper.ExecuteSQL(@"UPDATE GXGC_Multipart set BGXW='1' where BGXW ISNULL and OBJECTID in (select OBJECTID from ( select FID_DLTBBG,OBJECTID,BGXW,XZQTZLX_1, case when DLBM ISNULL OR DLBM=' ' THEN '' ELSE DLBM END DLBM, case when DLBM_1 ISNULL OR DLBM_1=' ' THEN '' ELSE DLBM_1 END DLBM_1, case when DLMC ISNULL OR DLMC=' ' THEN '' ELSE DLMC END DLMC, case when DLMC_1 ISNULL OR DLMC_1=' ' THEN '' ELSE DLMC_1 END DLMC_1, case when QSXZ ISNULL OR QSXZ=' ' THEN '' ELSE QSXZ END QSXZ, case when QSXZ_1 ISNULL OR QSXZ_1=' ' THEN '' ELSE QSXZ_1 END QSXZ_1, case when QSDWDM ISNULL OR QSDWDM=' ' THEN '' ELSE QSDWDM END QSDWDM, case when QSDWDM_1 ISNULL OR QSDWDM_1=' ' THEN '' ELSE QSDWDM_1 END QSDWDM_1, case when QSDWMC ISNULL OR QSDWMC=' ' THEN '' ELSE QSDWMC END QSDWMC, case when QSDWMC_1 ISNULL OR QSDWMC_1=' ' THEN '' ELSE QSDWMC_1 END QSDWMC_1, case when ZLDWDM ISNULL OR ZLDWDM=' ' THEN '' ELSE ZLDWDM END ZLDWDM, case when ZLDWDM_1 ISNULL OR ZLDWDM_1=' ' THEN '' ELSE ZLDWDM_1 END ZLDWDM_1, case when ZLDWMC ISNULL OR ZLDWMC=' ' THEN '' ELSE ZLDWMC END ZLDWMC, case when ZLDWMC_1 ISNULL OR ZLDWMC_1=' ' THEN '' ELSE ZLDWMC_1 END ZLDWMC_1, case when KCDLBM ISNULL or KCDLBM=' ' THEN '' ELSE KCDLBM END KCDLBM, case when KCDLBM_1 ISNULL or KCDLBM_1=' ' THEN '' ELSE KCDLBM_1 END KCDLBM_1, case when KCXS ISNULL or KCXS=' ' THEN '' ELSE KCXS END KCXS, case when KCXS_1 ISNULL or KCXS_1=' ' THEN '' ELSE KCXS_1 END KCXS_1, case when GDLX ISNULL or GDLX=' ' THEN '' ELSE GDLX END GDLX, case when GDLX_1 ISNULL or GDLX_1=' ' THEN '' ELSE GDLX_1 END GDLX_1, case when GDPDJB ISNULL or GDPDJB=' ' THEN '' ELSE GDPDJB END GDPDJB, case when GDPDJB_1 ISNULL or GDPDJB_1=' ' THEN '' ELSE GDPDJB_1 END GDPDJB_1, case when XZDWKD ISNULL or XZDWKD=' ' or XZDWKD=0.0 THEN 0 ELSE XZDWKD END XZDWKD, case when XZDWKD_1 ISNULL or XZDWKD_1=' ' or XZDWKD_1=0.0 THEN 0 ELSE XZDWKD_1 END XZDWKD_1, case when TBXHDM ISNULL or TBXHDM=' ' THEN '' ELSE TBXHDM END TBXHDM, case when TBXHDM_1 ISNULL or TBXHDM_1=' ' THEN '' ELSE TBXHDM_1 END TBXHDM_1, case when TBXHMC ISNULL or TBXHMC=' ' THEN '' ELSE TBXHMC END TBXHMC, case when TBXHMC_1 ISNULL or TBXHMC_1=' ' THEN '' ELSE TBXHMC_1 END TBXHMC_1, case when ZZSXDM ISNULL or ZZSXDM=' ' THEN '' ELSE ZZSXDM END ZZSXDM, case when ZZSXDM_1 ISNULL or ZZSXDM_1=' ' THEN '' ELSE ZZSXDM_1 END ZZSXDM_1, case when ZZSXMC ISNULL or ZZSXMC=' ' THEN '' ELSE ZZSXMC END ZZSXMC, case when ZZSXMC_1 ISNULL or ZZSXMC_1=' ' THEN '' ELSE ZZSXMC_1 END ZZSXMC_1, case when GDDB ISNULL or GDDB=' ' or GDDB=0 THEN '' ELSE GDDB END GDDB, case when GDDB_1 ISNULL or GDDB_1=' ' or GDDB_1=0 THEN '' ELSE GDDB_1 END GDDB_1, case when FRDBS ISNULL or FRDBS=' ' THEN '' ELSE FRDBS END FRDBS, case when FRDBS_1 ISNULL or FRDBS_1=' ' THEN '' ELSE FRDBS_1 END FRDBS_1, case when CZCSXM ISNULL or CZCSXM=' ' THEN '' ELSE CZCSXM END CZCSXM, case when CZCSXM_1 ISNULL or CZCSXM_1=' ' THEN '' ELSE CZCSXM_1 END CZCSXM_1, case when MSSM ISNULL or MSSM=' ' THEN '' ELSE MSSM END MSSM, case when MSSM_1 ISNULL or MSSM_1=' ' THEN '' ELSE MSSM_1 END MSSM_1, case when HDMC ISNULL or HDMC=' ' THEN '' ELSE HDMC END HDMC, case when HDMC_1 ISNULL or HDMC_1=' ' THEN '' ELSE HDMC_1 END HDMC_1 from GXGC_Multipart WHERE BGXW ISNULL and FID_DLTBBG<>-1 and FID_DLTB in (select FID_DLTB from GXGC_Multipart GROUP BY FID_DLTB HAVING COUNT(FID_DLTB) = 1) and FID_DLTBBG in (select FID_DLTBBG from GXGC_Multipart GROUP BY FID_DLTBBG HAVING COUNT(FID_DLTBBG) = 1) ) WHERE (XZQTZLX_1='2' or XZQTZLX_1='4' or DLBM != DLBM_1 or DLMC != DLMC_1 or QSXZ != QSXZ_1 or QSDWDM != QSDWDM_1 or QSDWMC != QSDWMC_1 or ZLDWDM != ZLDWDM_1 or ZLDWMC != ZLDWMC_1 or KCDLBM != KCDLBM_1 or KCXS != KCXS_1 or GDLX != GDLX_1 or GDPDJB != GDPDJB_1 or XZDWKD != XZDWKD_1 or TBXHDM != TBXHDM_1 or TBXHMC != TBXHMC_1 or ZZSXDM != ZZSXDM_1 or ZZSXMC != ZZSXMC_1 or GDDB != GDDB_1 or FRDBS != FRDBS_1 or CZCSXM != CZCSXM_1 or MSSM != MSSM_1 or HDMC != HDMC_1) )"); #endregion Console.WriteLine("Msg:正在进行面积平差..."); lock (Lock) { #region 面积平差 DataTable data_BSM = rdbHelper.ExecuteDatatable("tab", "select BSM,TBMJ_1 from GXGC_Multipart GROUP BY BSM HAVING count(BSM)>1", true); List pcBSMList = new List(); if (data_BSM != null && data_BSM.Rows.Count > 0) { foreach (DataRow row in data_BSM.Rows) { var jc_bsm = row["BSM"].ToTrim(); if (!pcBSMList.Contains(jc_bsm)) pcBSMList.Add(jc_bsm); } } pCursor = Temp_DLTBGXGC.FeatureClass.Search(new QueryFilterClass() { SubFields = "OBJECTID,BSM,TBMJ,SHAPE" }, true); var _itbmj = Temp_DLTBGXGC.FeatureClass.FindField("TBMJ"); var bsmIdx = Temp_DLTBGXGC.FeatureClass.FindField("BSM"); feature = null; Dictionary AreaList = new Dictionary(); //int _i = 0; while ((feature = pCursor.NextFeature()) != null) { string bsm = feature.Value[bsmIdx].ToTrim(); if (!pcBSMList.Contains(bsm)) continue; //_i++; double area = GetEllipseArea(feature.ShapeCopy); //lock (AreaList) //{ AreaList.Add(feature.OID, area.ToDouble()); //} //if (_i == 100) //{ // _i = 0; // Console.Clear(); // Console.Write(feature.OID); //} } //} DataTable data = rdbHelper.ExecuteDatatable("tab", "select OBJECTID,BSM,TBMJ,TBMJ_1 from GXGC_Multipart ", true); Dictionary _GXGCvaluePairs = new Dictionary();//记录平差结果 if (data_BSM != null && data_BSM.Rows.Count > 0) { foreach (DataRow row in data_BSM.Rows) { var jc_TBMJ = row["TBMJ_1"].ToDouble(); List shpList = new List(); var rows = data.Select($"BSM ='{row["BSM"]}'"); foreach (var item in rows) { Adjustment adj = new Adjustment(); adj.ID = item["OBJECTID"].ToInt(); if (AreaList.ContainsKey(adj.ID)) adj.bgmj = AreaList[adj.ID]; shpList.Add(adj); } if (shpList.Count > 0) { AreaAdjustment(shpList, jc_TBMJ);//面积平差 foreach (var item in shpList) { if (!_GXGCvaluePairs.ContainsKey(item.ID)) { _GXGCvaluePairs.Add(item.ID, item.bgmj); } } } } } #endregion Console.WriteLine("Msg:正在写入过程数据..."); #region 生成更新过程层 //IFeatureClassAPI DLTBGXGC = wsAPI1.CreateFeatureClass("DLTBGXGC", (LaySourceHelper.GxgcTBLayer.FeatureClass as IGeoDataset).SpatialReference, LaySourceHelper.GxgcTBLayer.FeatureClass.Fields); //Console.WriteLine(Temp_DLTBGXGC.FeatureClass.FeatureCount(null)); DataTable data_BGXW = rdbHelper.ExecuteDatatable("tab", @"select FID_DLTBBG,FID_DLTB,BGXW,OBJECTID,TBMJ_1,XZQTZLX_1 from GXGC_Multipart WHERE BGXW NOT NULL ", true); GXGCFcToFc(Temp_DLTBGXGC.FeatureClass, LaySourceHelper.GxgcTBLayer.FeatureClass, null, false, data_BGXW, _GXGCvaluePairs); //Console.WriteLine("更新过程写入:" + LaySourceHelper.GxgcTBLayer.FeatureClass.FeatureCount(null)); #endregion } Console.WriteLine("Msg:正在写入更新数据..."); #region 生成更新层 IWorkspaceAPI wsAPI1 = new WorkspaceAPI(TempGDbPath, WorkspaceTypeEnum.GDBFile); IFeatureClassAPI DLTBGX = wsAPI1.CreateFeatureClass("DLTBGX", (LaySourceHelper.GxTbLayer.FeatureClass as IGeoDataset).SpatialReference, LaySourceHelper.GxTbLayer.FeatureClass.Fields); GXFcToFc(LaySourceHelper.GxgcTBLayer.FeatureClass, DLTBGX.FeatureClass, new QueryFilterClass() { WhereClause = "BGHDLBM <>'1001' and BGHDLBM <>'1002' and BGHDLBM <>'1003' and BGHDLBM<>'1004' and BGHDLBM <>'1006' and BGHDLBM<>'1009' and BGHDLBM<>'1101' and BGHDLBM<>'1107' and BGHDLBM<>'1107A' and XZQTZLX<>'2' and XZQTZLX<>'4' " }); IFeatureLayer DissolveAnalysisFeatureLayer = null; #region 上海数据不合并 if (_Parm.ProjInfo.CODE.StartsWith("31")) { IFeatureClassAPI fcAPI = new FeatureClassAPI(DLTBGX.FeatureClass); fcAPI.FcToFc(LaySourceHelper.GxTbLayer.FeatureClass, null, false); } else { paramClass = new GPParamClass(); paramClass.FirstFeatureLayer = new FeatureLayer() { FeatureClass = DLTBGX.FeatureClass }; paramClass.OutFeatureClassPath = $"{TempGDbPath}\\GX_Dissolve"; paramClass.IsGetOutPutFeature = true; paramClass.ListDissolveFiledName = new List() { "DLBM", "DLMC", "QSXZ", "QSDWDM", "QSDWMC", "ZLDWDM", "ZLDWMC", "KCDLBM", "KCXS", "GDLX", "GDPDJB", "TBXHDM", "TBXHMC", "ZZSXDM", "ZZSXMC", "GDDB", "FRDBS", "CZCSXM", "MSSM", "HDMC" }; paramClass.GPType = EnumGPType.Dissolve; GPHelper.Instance.ExeGPForProces(paramClass, ref DissolveAnalysisFeatureLayer); //(LaySourceHelper.GxTbLayer.FeatureClass as ITable).DeleteSearchedRows(null); IFeatureClassAPI fcAPI = new FeatureClassAPI(DissolveAnalysisFeatureLayer.FeatureClass); fcAPI.FcToFc(LaySourceHelper.GxTbLayer.FeatureClass, null, false); } #endregion IFeatureLayer tempGcLayer = null; paramClass = new GPParamClass(); paramClass.FirstFeatureLayer = LaySourceHelper.GxgcTBLayer; paramClass.GPType = EnumGPType.SelectLayerByAttribute; paramClass.IsGetOutPutFeature = true; paramClass.Where_clause = "BGXW = '2' and (BGHDLBM ='1001' or BGHDLBM ='1002' or BGHDLBM ='1003' or BGHDLBM='1004' or BGHDLBM ='1006' or BGHDLBM='1009' or BGHDLBM='1101' or BGHDLBM='1107' or BGHDLBM='1107A')"; paramClass.FcName = "TempGC"; paramClass.TempGDBPath = TempGDbPath; GPHelper.Instance.ExeGPForProces(paramClass, ref tempGcLayer); IFeatureClassAPI BgTbFcAPI = wsAPI1.OpenFeatureClass("DLTBBG"); IFeatureLayer tempGcEraseLayer = null; paramClass.FirstFeatureLayer = tempGcLayer; paramClass.SecondFeatureLayer = new FeatureLayerClass() { FeatureClass = BgTbFcAPI.FeatureClass }; paramClass.OutFeatureClassPath = $"{TempGDbPath}\\TempGcErase"; paramClass.IsGetOutPutFeature = true; paramClass.GPType = EnumGPType.Erase; GPHelper.Instance.ExeGPForProces(paramClass, ref tempGcEraseLayer); GXFcToFc(BgTbFcAPI.FeatureClass, LaySourceHelper.GxTbLayer.FeatureClass, new QueryFilterClass() { WhereClause = "(DLBM ='1001' or DLBM ='1002' or DLBM ='1003' or DLBM='1004' or DLBM ='1006' or DLBM='1009' or DLBM='1101' or DLBM='1107' or DLBM='1107A') and (XZQTZLX<>'2' or XZQTZLX<>'4') " }); GXFcToFc(tempGcEraseLayer.FeatureClass, LaySourceHelper.GxTbLayer.FeatureClass, new QueryFilterClass() { WhereClause = "BGHDLBM ='1001' or BGHDLBM ='1002' or BGHDLBM ='1003' or BGHDLBM='1004' or BGHDLBM ='1006' or BGHDLBM='1009' or BGHDLBM='1101' or BGHDLBM='1107' or BGHDLBM='1107A'" }); #endregion } catch (Exception ex) { Console.WriteLine($"Err:异常---{ex.Message}"); Console.WriteLine($"Err:异常---{ex.StackTrace}"); throw ex; } } private IFeatureLayer ProcessBGTB(DBLayerSourceHelper pLaySourceHelper, string pTempGDbPath) { IFeatureLayer result = null; try { #region 空属性值 赋值 #region 变更图斑 string BgtbName = (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).BrowseName; (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set KCDLBM =Null where KCDLBM is Null or KCDLBM=' ' or KCDLBM=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set KCXS=0 where KCXS is Null "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set GDLX =Null where GDLX is Null or GDLX=' ' or GDLX=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set GDPDJB =Null where GDPDJB is Null or GDPDJB=' ' or GDPDJB=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set XZDWKD=0 where XZDWKD is Null "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set TBXHDM =Null where TBXHDM is Null or TBXHDM=' ' or TBXHDM=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set TBXHMC =Null where TBXHMC is Null or TBXHMC=' ' or TBXHMC=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set ZZSXDM =Null where ZZSXDM is Null or ZZSXDM=' ' or ZZSXDM=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set ZZSXMC =Null where ZZSXMC is Null or ZZSXMC=' ' or ZZSXMC=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set GDDB =0 where GDDB is Null "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set FRDBS =Null where FRDBS is Null or FRDBS=' ' or FRDBS=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set CZCSXM =Null where CZCSXM is Null or CZCSXM=' ' or CZCSXM=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set MSSM =Null where MSSM is Null or MSSM=' ' or MSSM=' ' "); (pLaySourceHelper.BgTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {BgtbName} set HDMC =Null where HDMC is Null or HDMC=' ' or HDMC=' ' "); #endregion #region 基础地类图斑 string JC_DLTBName = (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).BrowseName; (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set KCDLBM =Null where KCDLBM is Null or KCDLBM=' ' or KCDLBM=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set KCXS =0 where KCXS is Null"); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDLX =Null where GDLX is Null or GDLX=' ' or GDLX=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDPDJB =Null where GDPDJB is Null or GDPDJB=' ' or GDPDJB=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set XZDWKD =0 where XZDWKD is Null"); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set TBXHDM =Null where TBXHDM is Null or TBXHDM=' ' or TBXHDM=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set TBXHMC =Null where TBXHMC is Null or TBXHMC=' ' or TBXHMC=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set ZZSXDM =Null where ZZSXDM is Null or ZZSXDM=' ' or ZZSXDM=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set ZZSXMC =Null where ZZSXMC is Null or ZZSXMC=' ' or ZZSXMC=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set GDDB =0 where GDDB is Null"); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set FRDBS =Null where FRDBS is Null or FRDBS=' ' or FRDBS=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set CZCSXM =Null where CZCSXM is Null or CZCSXM=' ' or CZCSXM=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set MSSM =Null where MSSM is Null or MSSM=' ' or MSSM=' ' "); (pLaySourceHelper.JcTbLayer.FeatureClass as FeatureClass).Workspace.ExecuteSQL($"Update {JC_DLTBName} set HDMC =Null where HDMC is Null or HDMC=' ' or HDMC=' ' "); #endregion #endregion GDPDExcute(pLaySourceHelper, pTempGDbPath); } catch (Exception ex) { Console.WriteLine($"Err:变更前执行变更图斑数据处理失败:{ex.Message}"); Console.WriteLine($"Err:变更前执行变更图斑数据处理失败:{ex.StackTrace}"); if (ex.Message.Contains("0x8004022D"))//变更层数据被占用,无法获取锁 { Console.WriteLine($"Err:问题原因可能是【变更图斑图层被占用,无法获取锁。】"); } throw ex; } return result; } public virtual string CreateTempFile(string pType) { string result = string.Empty; try { string dbPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Temp" + ".db"); string TempFolder = Directory.GetCurrentDirectory() + "\\Temp\\DLTB\\" + pType; if (!Directory.Exists(TempFolder)) Directory.CreateDirectory(TempFolder); try { DelectDirect(TempFolder); } catch { //删除临时数据异常 不做处理 } if (!Directory.Exists(TempFolder)) { Directory.CreateDirectory(TempFolder); } if (File.Exists(dbPath)) { File.Copy(dbPath, System.IO.Path.Combine(TempFolder, pType + ".sqlite")); } else { Console.WriteLine(string.Format("文件{0}不存在!", dbPath)); } result = TempFolder; } catch (Exception ex) { Console.WriteLine("创建临时数据库失败!" + ex.Message); throw ex; } return result; } private void CreateTempGDBForGP(IFeatureLayer pJCDLTBLayer, IFeatureLayer pDLTBBGLayer, string pXZQDM, string pLocation) { object sev = null; //1-定义GeoProcessor对象 IGeoProcessor gp = new GeoProcessorClass(); try { string StrFilter = string.Format("ZLDWDM like '{0}%'", pXZQDM.ToTrim()); //2-设置参数 gp.OverwriteOutput = true; string strPath = AppDomain.CurrentDomain.BaseDirectory; if (!strPath.EndsWith(@"\")) { strPath += @"\"; } string toolPath = System.IO.Path.Combine(strPath, @"Resource\ZLDatabaseTool" + ".tbx"); if (!System.IO.File.Exists(toolPath)) { throw new Exception("未找到预变更工具!"); } //3-设置工具箱所在的路径 gp.AddToolbox(toolPath); //4-设置输入参数 IVariantArray parameters = new VarArrayClass(); parameters.Add(pJCDLTBLayer); parameters.Add(pDLTBBGLayer); parameters.Add(StrFilter); parameters.Add(pLocation); parameters.Add(pXZQDM); //5-执行工具 IGeoProcessorResult result = gp.Execute("CreateTempGDB", parameters, null); if (result != null && result.Status != esriJobStatus.esriJobSucceeded) { string ms = ""; if (gp.MessageCount > 0) { for (int Count = 0; Count <= gp.MessageCount - 1; Count++) { ms += "$" + gp.GetMessage(Count) + "\n\n"; } } } } catch (Exception ex) { throw ex; } finally { if (gp.MessageCount > 0) gp.GetMessages(ref sev).ToString(); } } public void CalculateArea(object pParm) { //try //{ // CalcAreaParm CalParm = pParm as CalcAreaParm; // IFeatureLayer _Layer = GeoDBAPI.DeSerialzedPersist(CalParm.StrLayer) as IFeatureLayer; // IFeatureCursor pCursor = _Layer.FeatureClass.Search(new QueryFilterClass() { SubFields = "OBJECTID,BSM,TBMJ,SHAPE" }, true); // var _itbmj = _Layer.FeatureClass.FindField("TBMJ"); // var bsmIdx = _Layer.FeatureClass.FindField("BSM"); // IFeature feature = null; // while ((feature = pCursor.NextFeature()) != null) // { // string bsm = feature.Value[bsmIdx].ToTrim(); // if (!CalParm.BsmList.Contains(bsm)) // continue; // double area = GetEllipseArea(feature.ShapeCopy); // lock (AreaList) // { // AreaList.Add(feature.OID, area.ToDouble()); // } // } //} //catch (Exception ex) //{ // //Console.WriteLine(ex.Message); //} } public class CalcAreaParm { public string StrLayer { get; set; } public int StartIndex { get; set; } public List BsmList { get; set; } } public DBLayerSourceHelper OpenDB(ProjectInfo pPrjarm) { DBLayerSourceHelper result = new DBLayerSourceHelper(); try { LayerCfg layerInfo = null; if (pPrjarm != null && !string.IsNullOrWhiteSpace(pPrjarm.TempData)) { byte[] contentArray = Convert.FromBase64String(pPrjarm.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 = pPrjarm.BGDatabase;// Path.Combine(, "BGDB" + ".gdb"); string PathZLDB = pPrjarm.ZLDatabase; string PathNMDB = pPrjarm.NMDatabase; 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 == "地类图斑"); result.JcTbLayer = result.OpenLayer(_JcTBLayerInfo); if (result.JcTbLayer == null) { throw new Exception("Err:获取年初地类图斑数据失败!"); } LayerCfg _JcPdtLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "坡度图"); result.JcPdtLayer = result.OpenLayer(_JcPdtLayerInfo); if (result.JcPdtLayer == null) { //throw new Exception("Err:获取年初坡度图数据失败!"); } result.BgTbLayer = result.OpenLayer(result.BgWsAPI, "DLTBBG"); result.GxTbLayer = result.OpenLayer(result.ZlWsAPI, "DLTBGX"); result.GxgcTBLayer = result.OpenLayer(result.ZlWsAPI, "DLTBGXGC"); result.GxPdtLayer = result.OpenLayer(result.ZlWsAPI, "PDTGX"); result.NmTbLayer = result.OpenLayer(result.NmWsAPI, "DLTB_NMK"); return result; } catch (Exception ex) { throw ex; } } private IWorkspace CreateDBWorkspace(string pDbPath) { try { if (!File.Exists(pDbPath)) { Console.WriteLine(string.Format("指定的文件路径{0}不存在!", pDbPath)); return null; } IWorkspaceFactory pOutWorkFactory = null; pOutWorkFactory = new SqlWorkspaceFactoryClass(); IWorkspace pOutWork = pOutWorkFactory.OpenFromFile(pDbPath, 0); return pOutWork; } catch (Exception ex) { Console.WriteLine($"Log:CreateDBWorkspace错误:{ex.Message}"); throw; } } public double GetEllipseArea(IGeometry polygon) { try { // 1、获得投影 String SphName = polygon.SpatialReference.Name.ToString().ToUpper(); // 2、获得椭球 ICoordinate coordinate = CoordinateFactory.CreateCoordinate(); if (SphName.Contains("XIAN_1980") || SphName.Contains("XIAN1980")) { coordinate = CoordinateFactory.CreateCoordinate(KGIS.Framework.AE.GaussCalculate.Spheroid.SphXian80); } else if (SphName.Contains("BEIJING_1954") || SphName.Contains("BEIJING1954")) { coordinate = CoordinateFactory.CreateCoordinate(KGIS.Framework.AE.GaussCalculate.Spheroid.SphBeijing54); } else if (SphName.Contains("WGS_1984") || SphName.Contains("WGS1984")) { coordinate = CoordinateFactory.CreateCoordinate(KGIS.Framework.AE.GaussCalculate.Spheroid.SphWGS84); } else if (SphName.Contains("CGCS_2000") || SphName.Contains("CGCS2000")) { coordinate = CoordinateFactory.CreateCoordinate(KGIS.Framework.AE.GaussCalculate.Spheroid.SphCGCS2000); } else { return -1; } // 3、计算面积 IGeometry pGeometry = polygon as IGeometry; double PolygonArea = 0.0; // 4、保留两位小数 PolygonArea = Math.Round(coordinate.CalculateTerranArea(pGeometry), 2, MidpointRounding.AwayFromZero); return PolygonArea; } catch (Exception ex) { throw ex; } } public void GDPDExcute(DBLayerSourceHelper pLaySourceHelper, string pTempGDbPath) { //IFeatureClassAPI GXAPI = null; //IFeatureClassAPI pdtFcAPI = null; IFeatureLayer PDTLayer = null; IFeature feature = null; IFeatureCursor cursor = null; IWorkspaceFactory pFtWsFct = null; IWorkspaceName workspaceName = null; IFeatureLayer unionLayer = null; IFeatureClassAPI unionFcAPI = null; try { Console.WriteLine("Msg:正在进行耕地坡度级别赋值,请稍后..."); #region 变更图斑层(GDB) //// 获取变更图斑 //GXAPI = new FeatureClassAPI(BgTbLayer.FeatureClass); //if (GXAPI == null || GXAPI.FeatureClass == null) //{ // Console.WriteLine("Err:未获取到更新层图斑"); // return; //} #endregion #region 坡度图层(MDB) PDTLayer = pLaySourceHelper.GxPdtLayer; if (pLaySourceHelper.GxPdtLayer == null && pLaySourceHelper.JcPdtLayer == null) { Console.WriteLine("Warning:当前工程不存在坡度图图层!"); return; } if (PDTLayer.FeatureClass.FeatureCount(null) <= 0) { PDTLayer = pLaySourceHelper.JcPdtLayer; } if (PDTLayer.FeatureClass.FeatureCount(null) <= 0) { Console.WriteLine("Warning:当前工程中未导入坡度数据!"); return; } #endregion IWorkspaceAPI psTempWorkspaceAPI = new WorkspaceAPI(pTempGDbPath, WorkspaceTypeEnum.GDBFile); IFeatureClassAPI tempdltbgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("TempDLTBGX", (pLaySourceHelper.BgTbLayer.FeatureClass as IGeoDataset).SpatialReference, pLaySourceHelper.BgTbLayer.FeatureClass.Fields); tempdltbgxFeatureclassAPI.AddField("OLDOBJECTID", esriFieldType.esriFieldTypeInteger, "老OBJECTID"); IFeatureClass tempdltbgxFC = tempdltbgxFeatureclassAPI.FeatureClass; Dictionary fieldsDic = new Dictionary(); for (int i = 0; i < tempdltbgxFC.Fields.FieldCount; i++) { IField field = tempdltbgxFC.Fields.Field[i]; if (field.Name == tempdltbgxFC.ShapeFieldName || field.Name.Contains(tempdltbgxFC.ShapeFieldName) || field.Name == tempdltbgxFC.OIDFieldName || !field.Editable) continue; if (!"DLBM,GDLX,GDDB,GDPDJB,KCXS".Contains(field.Name)) continue; int index = -1; index = pLaySourceHelper.BgTbLayer.FeatureClass.Fields.FindField(field.Name); if (index == -1) index = pLaySourceHelper.BgTbLayer.FeatureClass.Fields.FindFieldByAliasName(field.AliasName); if (index == -1) continue; fieldsDic.Add(i, index); } if (fieldsDic.Count == 0) return; IFeatureBuffer buffer = tempdltbgxFC.CreateFeatureBuffer(); IFeatureCursor tempgxCursor = tempdltbgxFC.Insert(true); int oldOIDIndex = tempdltbgxFC.FindField("OLDOBJECTID"); if (oldOIDIndex == -1) return; IQueryFilter queryfilter = new QueryFilterClass(); queryfilter.WhereClause = string.Format("DLBM like '01%' "); int gdCount = pLaySourceHelper.BgTbLayer.FeatureClass.FeatureCount(queryfilter); if (gdCount == 0) return; IFeature gxtbFeature = null; IFeatureCursor dltbgxCursor = pLaySourceHelper.BgTbLayer.FeatureClass.Search(queryfilter, true); int OIDIndex = pLaySourceHelper.BgTbLayer.FeatureClass.FindField("OBJECTID"); int num = 0; while ((gxtbFeature = dltbgxCursor.NextFeature()) != null) { num++; if (gxtbFeature.ShapeCopy.IsEmpty) continue; buffer.Shape = gxtbFeature.ShapeCopy; foreach (int item in fieldsDic.Keys) { if (string.IsNullOrWhiteSpace(gxtbFeature.Value[fieldsDic[item]].ToTrim())) buffer.Value[item] = DBNull.Value; buffer.Value[item] = gxtbFeature.Value[fieldsDic[item]]; } buffer.Value[oldOIDIndex] = gxtbFeature.Value[OIDIndex]; tempgxCursor.InsertFeature(buffer); if (num % 1000 == 0) { tempgxCursor.Flush(); } Marshal.ReleaseComObject(gxtbFeature); } tempgxCursor.Flush(); //DLTBGX与PDTGX 相交 GPParamClass gPParamClass = new GPParamClass(); gPParamClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = tempdltbgxFC };// pLaySourceHelper.BgTbLayer; gPParamClass.SecondFeatureLayer = PDTLayer; gPParamClass.OutFeatureClassPath = pTempGDbPath + "\\TB_PD"; gPParamClass.IsGetOutPutFeature = true; gPParamClass.GPType = EnumGPType.Identify; GPHelper.Instance.ExeGPForProces(gPParamClass, ref unionLayer); unionFcAPI = new FeatureClassAPI(unionLayer.FeatureClass); cursor = unionFcAPI.FeatureClass.Search(null, true); feature = null; Dictionary DicPDJB = new Dictionary(); Dictionary DicMJ = new Dictionary(); Dictionary> DicPDJB_MJ = new Dictionary>(); int idxOID = unionFcAPI.FeatureClass.FindField("OLDOBJECTID"); if (idxOID == -1) { return; } int idxArea = unionFcAPI.FeatureClass.FindField("SHAPE_AREA"); int idxPDJB = unionFcAPI.FeatureClass.FindField("PDJB"); while ((feature = cursor.NextFeature()) != null) { int oid = Convert.ToInt32(feature.Value[idxOID].ToTrim()); double area = feature.Value[idxArea].ToDouble(2); string pdjb = feature.Value[idxPDJB].ToTrim(); if (!DicPDJB_MJ.ContainsKey(oid)) { DicPDJB_MJ.Add(oid, new List() { new PDJBModel() { PDJB = pdjb, MJ = area } }); } else { List list = DicPDJB_MJ[oid]; PDJBModel pdjbMod = list.FirstOrDefault(f => f.PDJB == pdjb); if (pdjbMod == null) { list.Add(new PDJBModel() { PDJB = pdjb, MJ = area }); } else { pdjbMod.MJ += area; } DicPDJB_MJ[oid] = list; } if (!DicMJ.ContainsKey(oid)) { DicMJ.Add(oid, area); DicPDJB.Add(oid, pdjb); } else if (DicMJ[oid] < area) { DicMJ[oid] = area; DicPDJB[oid] = pdjb; } } cursor = pLaySourceHelper.BgTbLayer.FeatureClass.Update(new QueryFilter() { WhereClause = "DLBM like '01%' " }, false); int Objectid_GX = pLaySourceHelper.BgTbLayer.FeatureClass.FindField("objectid"); int BSM_GX = pLaySourceHelper.BgTbLayer.FeatureClass.FindField("BSM"); int GDPDJB_GX = pLaySourceHelper.BgTbLayer.FeatureClass.FindField("GDPDJB"); int GDLX_GX = pLaySourceHelper.BgTbLayer.FeatureClass.FindField("GDLX"); int idxKCXS = pLaySourceHelper.BgTbLayer.FeatureClass.FindField("KCXS"); int DLBM_GX = pLaySourceHelper.BgTbLayer.FeatureClass.FindField("DLBM"); int GDPDJBIndex = PDTLayer.FeatureClass.FindField("PDJB"); var count = pLaySourceHelper.BgTbLayer.FeatureClass.FeatureCount(new QueryFilter() { WhereClause = "DLBM like '01%' " }); var featurecount = 0; while ((feature = cursor.NextFeature()) != null) { featurecount++; if (featurecount % 500 == 0) { Console.WriteLine($"Msg:正在进行耕地坡度赋值...【{featurecount}/{count}】"); } if (feature.OID == 529) { } string pdjb = string.Empty; if (!DicPDJB_MJ.ContainsKey(feature.OID)) { continue; } double tempmj = feature.Value[feature.Fields.FindField("SHAPE_AREA")].ToDouble(0); if (tempmj == 850.0) { } List list = DicPDJB_MJ[feature.OID]; list = list.OrderByDescending(o => o.MJ).ToList(); pdjb = list[0].PDJB;//[feature.OID]; feature.Value[GDPDJB_GX] = pdjb; string dlbm = feature.Value[DLBM_GX].ToString(); string bghbsm = feature.Value[BSM_GX].ToString(); string UpdateGCSql = string.Empty; string strGDLX = feature.Value[GDLX_GX].ToTrim(); if (pdjb == "1") { strGDLX = ""; } else if (!string.IsNullOrWhiteSpace(dlbm) && "2,3,4,5".Contains(pdjb) && string.IsNullOrWhiteSpace(strGDLX)) { string kcxsKey1 = string.Format("{0}-{1}", "TT", pdjb); double xs1 = 0; if (Parm.KCXSDic.ContainsKey(kcxsKey1)) { xs1 = Parm.KCXSDic[kcxsKey1].ToDouble(); } string kcxsKey2 = string.Format("{0}-{1}", "PD", pdjb); double xs2 = 0; if (Parm.KCXSDic.ContainsKey(kcxsKey2)) { xs2 = Parm.KCXSDic[kcxsKey2].ToDouble(); } if (xs1 == 0 && xs2 != 0) { strGDLX = "PD"; } else if (xs1 != 0 && xs2 == 0) { strGDLX = "TT"; } else { if (dlbm == "0101") { strGDLX = "TT"; } else if ("0102,0103".Contains(dlbm)) { strGDLX = "PD"; } } } string kcxsKey = string.Format("{0}-{1}", strGDLX, pdjb); if (Parm.KCXSDic.ContainsKey(kcxsKey)) { feature.Value[idxKCXS] = Parm.KCXSDic[kcxsKey].ToDouble(); } feature.Value[GDLX_GX] = strGDLX; cursor.UpdateFeature(feature); Marshal.ReleaseComObject(feature); } } catch (Exception ex) { Console.WriteLine("Warning:耕地坡度级别赋值异常:" + ex.Message); Console.WriteLine("Warning:耕地坡度级别赋值异常:" + ex); } finally { //ProgressHelper.CloseProcessBar(); if (feature != null) Marshal.ReleaseComObject(feature); if (cursor != null) Marshal.ReleaseComObject(cursor); if (pFtWsFct != null) Marshal.ReleaseComObject(pFtWsFct); if (workspaceName != null) Marshal.ReleaseComObject(workspaceName); if (unionLayer != null) Marshal.ReleaseComObject(unionLayer); } } #region 面积平差 /// /// 面积平差 /// /// 需要平差的对象集合 /// 控制面积 public void AreaAdjustment(List shpList, double pKZMJ) { try { if (shpList.Count == 1) { shpList[0].bgmj = pKZMJ; return; } shpList = shpList.OrderByDescending(o => o.bgmj).ToList(); double mjc = Math.Round(shpList.Sum(s => s.bgmj) - pKZMJ, 2); //平差 while (Math.Round(mjc, 2) != 0) { int tpsm = (int)(Math.Abs(Math.Round(mjc, 2)) / (double)0.01); int e = tpsm / shpList.Count; int f = tpsm % shpList.Count; if (f != 0) { double tpmj = (e + 1) * 0.01; for (int i = 0; i < f; i++) { if (mjc < 0) shpList[i].bgmj = shpList[i].bgmj + tpmj; else shpList[i].bgmj = shpList[i].bgmj - tpmj; } } if (e != 0) { double tpmj = e * 0.01; for (int i = f; i < shpList.Count; i++) { if (mjc < 0) shpList[i].bgmj = shpList[i].bgmj + tpmj; else shpList[i].bgmj = shpList[i].bgmj - tpmj; } } mjc = Math.Round(shpList.Sum(s => s.bgmj), 2) - pKZMJ; } } catch (Exception ex) { //LogAPI.Debug("面积平差错误:" + ex.Message); throw ex; } } #endregion #region GXGCFcToFc public bool GXGCFcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, IQueryFilter pFilter, bool pIsCut, DataTable data_BSM, Dictionary GXGCvaluePairs) { IFeatureCursor S_Cursor = null; IFeatureCursor T_Cursor = null; try { if (FeatureClass == null || pFc == null) return false; //获取对应关系 Dictionary dicField = new Dictionary(); Dictionary dicField1 = new Dictionary(); Dictionary dicFieldBGH = 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}_1"); if (index == -1) index = FeatureClass.Fields.FindField(fieldName); } else if (field.Name.Contains("BGH")) { dicFieldBGH.Add(field.Name, i); 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); } if (index == -1) continue; dicField.Add(i, index); string fName = field.Name.Replace("BGQTB", "").Replace("BGHTB", "").Replace("BGQ", "").Replace("BGH", ""); index = FeatureClass.Fields.FindField($"{fName}_1"); if ("BGQTBBH,BGQTBMJ,BGQTBXHDM,BGQTBXHMC,BGQTBDLMJ,BGHTBBH,BGHTBMJ,BGHTBXHDM,BGHTBXHMC,BGHTBDLMJ".Contains(field.Name)) fName = field.Name.Replace("BGH", "").Replace("BGQ", ""); index = FeatureClass.Fields.FindField($"{fName}_1"); if (index == -1) index = FeatureClass.Fields.FindField(fName); if (index == -1) continue; dicField1.Add(i, index); } (pFc as ITable).DeleteSearchedRows(null); string s = (pFc as FeatureClass).Workspace.PathName; IFeatureClassLoad pFclsLoad = pFc as IFeatureClassLoad; if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = true; //此处写编辑的代码 S_Cursor = FeatureClass.Search(pFilter, true); IFeature f = null; T_Cursor = pFc.Insert(true); IFeatureBuffer buffer = pFc.CreateFeatureBuffer(); var iFID_DLTBBG = FeatureClass.FindField("FID_DLTBBG"); var iFID_DLTB = FeatureClass.FindField("FID_DLTB"); var ibgxw = pFc.FindField("BGXW"); var itbbgmj = pFc.FindField("TBBGMJ"); var ibgqkcxs = pFc.FindField("BGQKCXS"); var ibgqkcmj = pFc.FindField("BGQKCMJ"); var ibgqtbdlmj = pFc.FindField("BGQTBDLMJ"); var ibghkcxs = pFc.FindField("BGHKCXS"); var ibghkcmj = pFc.FindField("BGHKCMJ"); var ibghtbdlmj = pFc.FindField("BGHTBDLMJ"); var ibsm = pFc.FindField("BSM"); var igxsj = pFc.FindField("GXSJ"); var idxBGHTBBH = pFc.FindField("BGHTBBH"); var idxJCTBBH = FeatureClass.FindField("TBBH_1"); if (idxJCTBBH == -1) idxJCTBBH = FeatureClass.FindField("TBBH"); var ixzqtzlx = pFc.FindField("XZQTZLX"); var tbbgmj = 0.00; int bsm = 1; while ((f = S_Cursor.NextFeature()) != null) { if (GXGCvaluePairs.ContainsKey(f.OID)) { tbbgmj = GXGCvaluePairs[f.OID]; //if (tbbgmj == 0) continue; } var FID_DLTBBG = f.Value[iFID_DLTBBG].ToString(); var FID_DLTB = f.Value[iFID_DLTB].ToString(); var row = data_BSM.Select($"FID_DLTBBG={FID_DLTBBG} and FID_DLTB={FID_DLTB} "); if (row == null || row.Length == 0) continue; buffer.Shape = f.ShapeCopy; var XZQTZLX = row[0]["XZQTZLX_1"].ToTrim(); if (pFilter is ISpatialFilter && pIsCut) { if (FeatureAPI.IsInterSect((pFilter as ISpatialFilter).Geometry, f.ShapeCopy)) { buffer.Shape = FeatureAPI.InterSect(f.ShapeCopy, (pFilter as SpatialFilterClass).Geometry); } else { continue; } } if (FID_DLTBBG == "-1") { foreach (int item in dicField1.Keys)//被动变更的图斑 变更前后属性相同 { try { if (f.Value[dicField1[item]].ToString().Contains(" ") || f.Value[dicField1[item]] is DBNull) { buffer.Value[item] = f.Value[dicField1[item]].ToTrim(); } else { buffer.Value[item] = f.Value[dicField1[item]]; } //buffer.Value[item] = f.Value[dicField1[item]].ToTrim(); } catch { buffer.Value[item] = f.Value[dicField1[item]]; } } } else { foreach (int item in dicField.Keys) { try { buffer.Value[item] = f.Value[dicField[item]]; } catch { buffer.Value[item] = f.Value[dicField[item]]; } } } if (idxJCTBBH != -1) buffer.Value[idxBGHTBBH] = f.Value[idxJCTBBH]; buffer.Value[ibgxw] = row[0]["BGXW"]; if (GXGCvaluePairs.ContainsKey(f.OID)) tbbgmj = GXGCvaluePairs[f.OID]; else tbbgmj = row[0]["TBMJ_1"].ToDouble(); buffer.Value[ixzqtzlx] = XZQTZLX; buffer.Value[itbbgmj] = Math.Round(tbbgmj, 2);//图斑变更面积 buffer.Value[ibgqkcmj] = Math.Round(buffer.Value[ibgqkcxs].ToDouble() * tbbgmj, 2);//变更前扣除面积 buffer.Value[ibgqtbdlmj] = tbbgmj - Math.Round(buffer.Value[ibgqkcxs].ToDouble() * tbbgmj, 2);//变更前图斑地类面积 buffer.Value[ibghkcmj] = Math.Round(buffer.Value[ibghkcxs].ToDouble() * tbbgmj, 2);//变更后扣除面积 buffer.Value[ibghtbdlmj] = tbbgmj - Math.Round(buffer.Value[ibghkcxs].ToDouble() * tbbgmj, 2);//变更后图斑地类面积 buffer.Value[ibsm] = $"{Parm.PrjInfo.CODE}2111{(bsm++).ToString().PadLeft(8, '0')}"; buffer.Value[igxsj] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31); if (XZQTZLX == "2" || XZQTZLX == "4") { foreach (var item in dicFieldBGH) { if (item.Key.StartsWith("BGH") && item.Value > 0) { try { buffer.Value[item.Value] = ""; } catch { buffer.Value[item.Value] = 0; } } } } T_Cursor.InsertFeature(buffer); } T_Cursor.Flush(); if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = false; return true; } catch (Exception ex) { throw ex; } } #endregion #region GXFcToFc public bool GXFcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, IQueryFilter pFilter) { 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 || field.Name.ToUpper() == "TBYBH") continue; index = FeatureClass.Fields.FindField($"BGH{field.Name}"); if (index == -1) index = FeatureClass.Fields.FindField($"BGHTB{field.Name}"); if (index == -1) index = FeatureClass.Fields.FindField(field.Name); if (index == -1) continue; dicField.Add(i, index); } IFeatureClassLoad pFclsLoad = pFc as IFeatureClassLoad; if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = true; //此处写编辑的代码 S_Cursor = FeatureClass.Search(pFilter, true); IFeature f = null; T_Cursor = pFc.Insert(true); IFeatureBuffer buffer = pFc.CreateFeatureBuffer(); while ((f = S_Cursor.NextFeature()) != null) { buffer.Shape = f.ShapeCopy; foreach (int item in dicField.Keys) { buffer.Value[item] = f.Value[dicField[item]]; } T_Cursor.InsertFeature(buffer); } T_Cursor.Flush(); if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = false; return true; } catch (Exception ex) { throw ex; } } #endregion #region FcToFc public bool FcToFc(IFeatureClass FeatureClass, IFeatureClass pFc, IQueryFilter pFilter) { IFeatureCursor S_Cursor = null; IFeatureCursor T_Cursor = null; try { if (FeatureClass == null || pFc == null) return false; Dictionary 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(pFilter, true); IFeature f = null; IFeatureBuffer buffer = pFc.CreateFeatureBuffer(); T_Cursor = pFc.Insert(true); while ((f = S_Cursor.NextFeature()) != null) { buffer.Shape = f.ShapeCopy; foreach (int item in dicField.Keys) { buffer.Value[item] = f.Value[dicField[item]]; } T_Cursor.InsertFeature(buffer); } T_Cursor.Flush(); if (pFclsLoad != null) pFclsLoad.LoadOnlyMode = false; return true; } catch (Exception) { throw; } } #endregion } //public class Adjustment //{ // public int ID { get; set; } // public double bgmj { get; set; } //} //public class PDJBModel //{ // public string PDJB { get; set; } // public double MJ { get; set; } //} public class ThreadParam { public string ThreadName { get; set; } public List Codes { get; set; } public ProjectInfo ProjInfo { get; set; } public string StrBgTbLayer { get; set; } public string StrJcTbLayer { get; set; } public List Layers { get; set; } } }