You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1925 lines
92 KiB
1925 lines
92 KiB
//using ESRI.ArcGIS.AnalysisTools; |
|
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.DataSourcesGDB; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using ESRI.ArcGIS.Geoprocessing; |
|
using ESRI.ArcGIS.Geoprocessor; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.AE.Enum; |
|
//using KGIS.Framework.AE.GPHelper; |
|
using KGIS.Framework.AE.ExtensionMethod; |
|
using KGIS.Framework.DBOperator; |
|
//using KGIS.Framework.Maps; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.PluginServiceInterface; |
|
//using KUI.Windows; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Data; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Runtime.InteropServices; |
|
using Kingo.PluginServiceInterface.Model; |
|
using ESRI.ArcGIS.AnalysisTools; |
|
using KGIS.Framework.ThreadManager; |
|
using KGIS.Framework.AE.GPHelper; |
|
//using IDEParameter; |
|
|
|
namespace IDGForNDBG |
|
{ |
|
public class XZQ_IDGHelper2 : BaseIDG |
|
{ |
|
public string IDataChangeName { get => "XZQ_IDGHelper"; } |
|
private string TempGDBPath = string.Empty; |
|
private string TempDBPath = string.Empty; |
|
private string TempDir = string.Empty; |
|
|
|
IDGParameter IDGParm = null; |
|
|
|
|
|
public void Execute(IDGParameter pParm) |
|
{ |
|
ThreadManager.Instance.QueueUserWorkItem(new System.Threading.WaitCallback(ExeXZQ), pParm); |
|
//ExeXZQ(pParm); |
|
} |
|
|
|
|
|
public void ExeXZQ(object obj) |
|
{ |
|
IDGParameter Parm = obj as IDGParameter; |
|
IDGParm = Parm; |
|
Console.WriteLine("Log:正在进行行政区数据提取,请稍候..."); |
|
IFeatureLayer TempGXLayer = null; |
|
try |
|
{ |
|
GPParamClass paramClass = new GPParamClass(); |
|
TempDir = CreateTempDB("XZQ"); |
|
TempGDBPath = System.IO.Path.Combine(TempDir, "TempGDB.gdb"); |
|
TempDBPath = TempDir + @"\Temp" + ".sqlite"; |
|
|
|
|
|
//XZQ_Param bgParm = new XZQ_Param(); |
|
OpenDB(Parm); |
|
|
|
//string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\NMK"; |
|
//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); |
|
|
|
|
|
IRDBHelper rdbHelper = null; |
|
List<DataDicTionary> qsDic = null; |
|
try |
|
{ |
|
|
|
//FileInfo fileInfo = new FileInfo(Parm.PrjInfo.BGDatabase); |
|
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<DataDicTionary>(dicDt);// Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM); |
|
|
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine("Err:获取权属字典失败!" + ex.Message); |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
rdbHelper.DisConnect(); |
|
} |
|
List<string> columns = new List<string>() { "XZQDM", "MSSM" };//, "XZQTZLX", "HDMC" |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = NmTbLayer; |
|
gPParamClass.OutFeatureClassPath = TempGDBPath + "\\" + "TempXZQGX"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.ListDissolveFiledName = columns; |
|
gPParamClass.GPType = EnumGPType.Dissolve; |
|
//GeoprocessorHelper gpHelper = new GeoprocessorHelper(); |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref TempGXLayer); |
|
|
|
IFeatureLayer jcLayer = null; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = JcXzqLayer; |
|
gPParamClass.OutFeatureClassPath = TempGDBPath; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.FcName = "JC_XZQ"; |
|
gPParamClass.GPType = EnumGPType.FcToFc; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref jcLayer); |
|
JcXzqLayer = jcLayer; |
|
//if (drqXZQFc != null) |
|
//{ |
|
//fcAPI = new FeatureClassAPI(drqXZQFc); |
|
//fcAPI.FcToFc(jcxzqLayer.FeatureClass, null, false); |
|
//} |
|
|
|
IFeatureCursor cursor = null;// cjdcqgxFeatureLayer.FeatureClass.Search(null, true); |
|
IFeature f = null; |
|
int xzqdmIdx = TempGXLayer.FeatureClass.FindField("XZQDM"); |
|
//int zldwmcIdx = cjdcqgxFeatureLayer.FeatureClass.FindField("ZLDWMC"); |
|
int mssmIdx = TempGXLayer.FeatureClass.FindField("MSSM"); |
|
int hdmcIdx = TempGXLayer.FeatureClass.FindField("HDMC"); |
|
int areaIdx = TempGXLayer.FeatureClass.FindField("SHAPE_AREA"); |
|
int lengthIdx = TempGXLayer.FeatureClass.FindField("SHAPE_LENGTH"); |
|
|
|
int jc_xzqdmIdx = JcXzqLayer.FeatureClass.FindField("XZQDM"); |
|
//int jc_zldwmcIdx = jccjdcqLayer.FeatureClass.FindField("ZLDWMC"); |
|
int jc_mssmIdx = JcXzqLayer.FeatureClass.FindField("MSSM"); |
|
int jc_hdmcIdx = JcXzqLayer.FeatureClass.FindField("HDMC"); |
|
int jc_areaIdx = JcXzqLayer.FeatureClass.FindField("SHAPE_AREA"); |
|
int jc_lengthIdx = JcXzqLayer.FeatureClass.FindField("SHAPE_LENGTH"); |
|
int xzqtzlxIndex = TempGXLayer.FeatureClass.FindField("XZQTZLX"); |
|
|
|
string zldwdm = string.Empty; |
|
string zldwmc = string.Empty; |
|
string mssm = string.Empty; |
|
string hdmc = string.Empty; |
|
List<string> ChangesList = new List<string>(); |
|
int xzqtzlx = 0; |
|
ITable xzqgxTb = GxXzqLayer.FeatureClass as ITable; |
|
xzqgxTb.DeleteSearchedRows(null);//删除行政区更新所有数据 |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(TempGXLayer.FeatureClass); |
|
fcAPI.AddField("BSM", esriFieldType.esriFieldTypeString, "标识码"); |
|
fcAPI.AddField("GXSJ", esriFieldType.esriFieldTypeDate, "更新时间"); |
|
fcAPI.AddField("XZQMC", esriFieldType.esriFieldTypeString, "行政区名称"); |
|
fcAPI.AddField("HDMC", esriFieldType.esriFieldTypeString, "海岛名称"); |
|
fcAPI.AddField("DCMJ", esriFieldType.esriFieldTypeDouble, "调查面积"); |
|
cursor = TempGXLayer.FeatureClass.Update(null, true); |
|
int xzqmcIdx = TempGXLayer.FeatureClass.FindField("XZQMC"); |
|
//int xzqdmIdx = cjdcqgxFeatureLayer.FeatureClass.FindField("XZQMC"); |
|
while ((f = cursor.NextFeature()) != null) |
|
{ |
|
string xzqdm = f.Value[xzqdmIdx].ToTrim(); |
|
if (qsDic != null) |
|
{ |
|
DataDicTionary dic = qsDic.FirstOrDefault(d => d.CODE == xzqdm); |
|
if (dic != null) |
|
{ |
|
f.Value[xzqmcIdx] = dic.NAME; |
|
} |
|
} |
|
cursor.UpdateFeature(f); |
|
} |
|
cursor.Flush(); |
|
fcAPI.FcToFc(GxXzqLayer.FeatureClass, null, false); |
|
GenerateGxgcDataForXZQ(Parm); |
|
int gcNum = GxgcXzqLayer.FeatureClass.FeatureCount(null); |
|
if (gcNum == 0) |
|
{ |
|
(GxXzqLayer.FeatureClass as ITable).DeleteSearchedRows(null); |
|
} |
|
else |
|
{ |
|
//fcAPI.FcToFc(XZQGXLayer.FeatureClass, null, false); |
|
XZQExtractExe(Parm); |
|
} |
|
Console.WriteLine("Log:行政区数据提取完成。"); |
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine("Log:行政区数据提取失败"); |
|
//LogAPI.Debug("Err:提取行政区错误:" + ex.Message.ToString()); |
|
//LogAPI.Debug(ex); |
|
throw ex; |
|
} |
|
} |
|
|
|
public void OpenDB(IDGParameter parm) |
|
{ |
|
try |
|
{ |
|
LayerCfg layerInfo = null; |
|
if (parm.PrjInfo != null && !string.IsNullOrWhiteSpace(parm.PrjInfo.TempData)) |
|
{ |
|
byte[] contentArray = Convert.FromBase64String(parm.PrjInfo.TempData); |
|
string LayerCfg = System.Text.Encoding.Default.GetString(contentArray); |
|
layerInfo = KGIS.Framework.Utils.SerializeAPI.DeserializeToObject<LayerCfg>(LayerCfg); |
|
} |
|
if (layerInfo == null) |
|
{ |
|
throw new Exception("Err:获取图层信息失败!"); |
|
} |
|
//FileInfo fileInfo = new FileInfo(parm.PrjInfo.BGDatabase); |
|
string PathBgDB = parm.PrjInfo.BGDatabase;// Path.Combine(, "BGDB" + ".gdb"); |
|
string PathZLDB = parm.PrjInfo.ZLDatabase; |
|
string PathNMDB = parm.PrjInfo.NMDatabase;// System.IO.Path.Combine(fileInfo.DirectoryName, "NMDB" + ".gdb"); |
|
BgWsAPI = new WorkspaceAPI(PathBgDB, WorkspaceTypeEnum.GDBFile); |
|
if (BgWsAPI.CurrentWorkspace == null) |
|
{ |
|
Console.WriteLine("打开变更数据库失败!"); |
|
return; |
|
} |
|
ZlWsAPI = new WorkspaceAPI(PathZLDB, WorkspaceTypeEnum.GDBFile); |
|
if (ZlWsAPI.CurrentWorkspace == null) |
|
{ |
|
Console.WriteLine("打开增量数据库失败!"); |
|
return; |
|
} |
|
NmWsAPI = new WorkspaceAPI(PathNMDB, WorkspaceTypeEnum.GDBFile); |
|
|
|
|
|
LayerCfg JCLayerInfo = layerInfo.Layers.FirstOrDefault(f => f.LayerName == "年初数据"); |
|
if (JCLayerInfo == null) |
|
{ |
|
throw new Exception("Err:获取年初数据库失败!"); |
|
} |
|
List<LayerCfg> NcList = JCLayerInfo.GetAllItem(); |
|
if (parm.ExeDLTB) |
|
{ |
|
LayerCfg _JcTBLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "地类图斑"); |
|
|
|
_jcTbLayer = OpenLayer(_JcTBLayerInfo); |
|
if (_jcTbLayer == null) |
|
{ |
|
throw new Exception("Err:获取年初地类图斑数据失败!"); |
|
} |
|
|
|
} |
|
|
|
{ |
|
LayerCfg _JcXzqLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "行政区"); |
|
_jcXzqLayer = OpenLayer(_JcXzqLayerInfo); |
|
if (_JcXzqLayerInfo == null) |
|
throw new Exception("Err:获取年初行政区数据失败!"); |
|
LayerCfg _JcXzqJxLayerInfo = NcList.FirstOrDefault(f => f.LayerName == "行政区界线"); |
|
_jcXzqJxLayer = OpenLayer(_JcXzqJxLayerInfo); |
|
if (_JcXzqJxLayerInfo == null) |
|
throw new Exception("Err:获取年初行政区界线数据失败!"); |
|
_gxXzqLayer = OpenLayer(ZlWsAPI, "XZQGX"); |
|
_gxgcXzqLayer = OpenLayer(ZlWsAPI, "XZQGXGC"); |
|
_gxXzqJxLayer = OpenLayer(ZlWsAPI, "XZQJXGX"); |
|
_gxgcTBLayer = OpenLayer(ZlWsAPI, "DLTBGXGC"); |
|
if (_nmTbLayer == null) |
|
_nmTbLayer = OpenLayer(NmWsAPI, "DLTB_NMK"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
#region 提取行政区界线 |
|
public void XZQExtractExe(IDGParameter pParm) |
|
{ |
|
bool cb_XZQDMChange = false; |
|
IFeatureClass XZQGXFeatureClass = null; |
|
IFeatureClass XZQGXGCFeatureClass = null; |
|
IFeatureLayer JCXZQFeatureLayer = null; |
|
IFeatureLayer JCXZQJXFeatureLayer = null; |
|
IFeatureClassAPI xzqgxgcfcAPI = null; |
|
|
|
IFeatureLayer gx_xzqLayer = null; |
|
IFeatureLayer gxgc_xzqLayer = null; |
|
IFeatureLayer gx_xzqjxLayer = null; |
|
try |
|
{ |
|
//if (_MapService == null) |
|
// _MapService = MapsManager.Instance.MapService; |
|
|
|
gx_xzqLayer = GxXzqLayer; |
|
gxgc_xzqLayer = GxgcXzqLayer; |
|
gx_xzqjxLayer = GxXzqJxLayer; |
|
XZQGXFeatureClass = gx_xzqLayer.FeatureClass;// _MapService.GetFeatureClassByName("XZQGX");//行政区更新层 |
|
XZQGXGCFeatureClass = gxgc_xzqLayer.FeatureClass;// _MapService.GetFeatureClassByName("XZQGXGC");//行政区更新过程层 |
|
JCXZQFeatureLayer = JcXzqLayer;// _MapService.GetFeatureLayerByLayerName("行政区");//基础行政区 |
|
JCXZQJXFeatureLayer = JcXzqJxLayer;// _MapService.GetFeatureLayerByLayerName("行政区界线");//基础行政区界线 |
|
if (XZQGXGCFeatureClass.FeatureCount(null) == 0) return; |
|
xzqgxgcfcAPI = new FeatureClassAPI(XZQGXGCFeatureClass); |
|
List<IFeature> xzqgxgcList = xzqgxgcfcAPI.QueryFeatures(null); |
|
IFeature xzqGXGC = FeatureAPI.MergeFeature(xzqgxgcList); |
|
if (xzqGXGC == null) |
|
{ |
|
LogAPI.Debug("行政区更新过程层数据为空!"); |
|
return; |
|
} |
|
List<IFeature> features = FeatureAPI.Identify(xzqGXGC.ShapeCopy, JCXZQFeatureLayer); |
|
|
|
//string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\XZQJXGX"; |
|
//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(TempGDBPath, WorkspaceTypeEnum.GDBFile); |
|
|
|
IFeatureClassAPI tempxzqgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("XZQGX_TEMP", (XZQGXFeatureClass as IGeoDataset).SpatialReference, XZQGXFeatureClass.Fields); |
|
tempxzqgxFeatureclassAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); |
|
JCXZQInsertGX(features, tempxzqgxFeatureclassAPI.FeatureClass, null);//将基础村级调查区数据插入到更新过程层,变更前变更后的属性数据一致 |
|
|
|
IFeatureClassAPI xzqgxFeatureclassAPI = psTempWorkspaceAPI.CreateFeatureClass("XZQGX", (XZQGXFeatureClass as IGeoDataset).SpatialReference, XZQGXFeatureClass.Fields); |
|
xzqgxFeatureclassAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); |
|
|
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(XZQGXFeatureClass); |
|
fcAPI.FcToFc(xzqgxFeatureclassAPI.FeatureClass, null, false); |
|
|
|
IQueryFilter filter = new QueryFilterClass(); |
|
filter.WhereClause = string.Format(" BGHXZQDM is null or BGHXZQDM =''"); |
|
XZQGXMSInsertGX(XZQGXGCFeatureClass, xzqgxFeatureclassAPI.FeatureClass, filter); |
|
|
|
IFeatureLayer xzqgxJCLayer = null; |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = tempxzqgxFeatureclassAPI.FeatureClass }; |
|
gPParamClass.SecondFeatureLayer = new FeatureLayerClass() { FeatureClass = xzqgxFeatureclassAPI.FeatureClass }; |
|
gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "XZQGX_JC"); |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.Erase; |
|
//GeoprocessorHelper gpHelper = new GeoprocessorHelper(); |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref xzqgxJCLayer); |
|
fcAPI = new FeatureClassAPI(xzqgxJCLayer.FeatureClass); |
|
fcAPI.AddField("IsJCTB", esriFieldType.esriFieldTypeString, "基础图斑"); |
|
|
|
fcAPI = new FeatureClassAPI(xzqgxJCLayer.FeatureClass); |
|
fcAPI.FcToFc(xzqgxFeatureclassAPI.FeatureClass, null, false); |
|
|
|
filter = new QueryFilterClass(); |
|
filter.WhereClause = string.Format("SHAPE_AREA<0.1"); |
|
(xzqgxFeatureclassAPI.FeatureClass as ITable).DeleteSearchedRows(filter); |
|
|
|
// 村级调查区更新过程要素转线 |
|
IFeatureLayer xzqgxjxLayer = null; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = new FeatureLayerClass() { FeatureClass = xzqgxFeatureclassAPI.FeatureClass }; |
|
gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "XZQGX_JX"); |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.PolygonToLine; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref xzqgxjxLayer); |
|
|
|
// 村级调查区更新过程界线取消线分割 |
|
IFeatureLayer gxjxUnsplitLayer = null; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = xzqgxjxLayer; |
|
gPParamClass.OutFeatureClassPath = System.IO.Path.Combine(TempGDBPath, "XZQGXJX_Unsplit"); |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.ListDissolveFiledName = new List<string>() { "LEFT_FID", "RIGHT_FID" }; |
|
gPParamClass.GPType = EnumGPType.UnsplitLine; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref gxjxUnsplitLayer); |
|
|
|
Dictionary<int, string> xzqdmDic = new Dictionary<int, string>(); |
|
Dictionary<int, string> isjctbDic = new Dictionary<int, string>(); |
|
int objectidIndex = xzqgxFeatureclassAPI.FeatureClass.Fields.FindField("OBJECTID"); |
|
int bghzldwdmIndex = xzqgxFeatureclassAPI.FeatureClass.Fields.FindField("XZQDM"); |
|
int gxgcIndex = xzqgxFeatureclassAPI.FeatureClass.Fields.FindField("IsJCTB"); |
|
IFeatureCursor gxgcjxCursor = xzqgxFeatureclassAPI.FeatureClass.Search(null, true); |
|
IFeature gxgcFeature = null; |
|
while ((gxgcFeature = gxgcjxCursor.NextFeature()) != null) |
|
{ |
|
if (objectidIndex == -1) |
|
continue; |
|
int objectid = int.Parse(gxgcFeature.Value[objectidIndex].ToString()); |
|
if (bghzldwdmIndex != -1) |
|
{ |
|
string zldwdm = gxgcFeature.Value[bghzldwdmIndex].ToString(); |
|
if (objectid != 0) |
|
xzqdmDic.Add(objectid, zldwdm); |
|
} |
|
if (gxgcIndex != -1) |
|
{ |
|
string jctb = gxgcFeature.Value[gxgcIndex].ToString(); |
|
|
|
if (objectid != 0) |
|
isjctbDic.Add(objectid, jctb); |
|
} |
|
|
|
Marshal.ReleaseComObject(gxgcFeature); |
|
} |
|
IFeatureClass XZQJXGXFeatureClass = gx_xzqjxLayer.FeatureClass;// _MapService.GetFeatureClassByName("XZQJXGX"); |
|
ITable table = XZQJXGXFeatureClass as ITable; |
|
table.DeleteSearchedRows(null); |
|
|
|
int leftidIndex = gxjxUnsplitLayer.FeatureClass.Fields.FindField("LEFT_FID"); |
|
int rightIndex = gxjxUnsplitLayer.FeatureClass.Fields.FindField("RIGHT_FID"); |
|
int shapeLengthIndex = gxjxUnsplitLayer.FeatureClass.Fields.FindField("SHAPE_LENGTH"); |
|
IFeatureCursor gxgcjxUnsplitCursor = gxjxUnsplitLayer.Search(null, true); |
|
IFeature f = null; |
|
List<int> JC_OID = new List<int>(); |
|
List<int> MS_OID = new List<int>(); |
|
IFeatureCursor xzqgxCur = XZQGXFeatureClass.Search(null, true); |
|
IFeature xzqgx = null; |
|
while ((xzqgx = xzqgxCur.NextFeature()) != null) |
|
{ |
|
List<IFeature> jcjx_features = FeatureAPI.Identify2(xzqgx.ShapeCopy, JCXZQJXFeatureLayer); |
|
foreach (var item in jcjx_features) |
|
{ |
|
if (!MS_OID.Contains(item.OID)) |
|
MS_OID.Add(item.OID); |
|
} |
|
} |
|
while ((f = gxgcjxUnsplitCursor.NextFeature()) != null) |
|
{ |
|
IPolyline line = f.ShapeCopy as IPolyline; |
|
IPoint p = line.FromPoint; |
|
List<IFeature> lines = FeatureAPI.Identify2(p, gxjxUnsplitLayer); |
|
if (lines.Count < 3) |
|
{ |
|
foreach (var item in lines) |
|
{ |
|
if (item.OID == f.OID) |
|
continue; |
|
try |
|
{ |
|
IFeatureEdit edit = item as IFeatureEdit; |
|
edit.Split(p); |
|
} |
|
catch (Exception ex) |
|
{ |
|
} |
|
} |
|
} |
|
} |
|
|
|
if (cb_XZQDMChange == true) |
|
{ |
|
gxgcjxUnsplitCursor = JCXZQJXFeatureLayer.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, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
if (MS_OID.Contains(f.OID)) |
|
MS_OID.Remove(f.OID); |
|
} |
|
} |
|
|
|
gxgcjxUnsplitCursor = gxjxUnsplitLayer.Search(null, true); |
|
while ((f = gxgcjxUnsplitCursor.NextFeature()) != null) |
|
{ |
|
if (leftidIndex == -1 || rightIndex == -1) |
|
{ |
|
continue; |
|
} |
|
|
|
List<IFeature> jcjx_features = FeatureAPI.Identify2(f.ShapeCopy, JCXZQJXFeatureLayer); |
|
|
|
int leftID = int.Parse(f.Value[leftidIndex].ToString()); |
|
int rightID = int.Parse(f.Value[rightIndex].ToString()); |
|
double gxshapeLength = f.Value[shapeLengthIndex].ToDouble(2); |
|
string leftxzqdm = leftID == -1 ? "" : xzqdmDic[leftID]; |
|
string rightxzqdm = rightID == -1 ? "" : xzqdmDic[rightID]; |
|
string leftIsjctb = leftID == -1 ? "0" : isjctbDic[leftID]; |
|
string rightIsjctb = rightID == -1 ? "0" : isjctbDic[rightID]; |
|
|
|
string bghJXLX = string.Empty; |
|
if (!string.IsNullOrWhiteSpace(leftIsjctb) && !string.IsNullOrWhiteSpace(rightIsjctb) && jcjx_features.Count > 1) |
|
{ |
|
foreach (var item in jcjx_features) |
|
{ |
|
if (MS_OID.Contains(item.OID)) |
|
MS_OID.Remove(item.OID); |
|
} |
|
continue; |
|
} |
|
if (leftxzqdm.Length == rightxzqdm.Length) |
|
{ |
|
if (leftxzqdm.Length == 0) |
|
{ |
|
bghJXLX = ""; |
|
|
|
} |
|
else if (leftxzqdm.Substring(0, 6) != rightxzqdm.Substring(0, 6)) |
|
{ |
|
//县界 |
|
bghJXLX = "650200"; |
|
} |
|
else if (leftxzqdm.Substring(0, 9) == rightxzqdm.Substring(0, 9)) |
|
{ |
|
//乡镇界 |
|
bghJXLX = ""; |
|
} |
|
else |
|
{ |
|
//乡镇界 |
|
bghJXLX = "660200"; |
|
} |
|
} |
|
else |
|
{ |
|
//县界 |
|
bghJXLX = "650200"; |
|
} |
|
if (cb_XZQDMChange == true) |
|
{ |
|
InsertXZQGXFeature(f, 3, bghJXLX, "600001", JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
continue; |
|
} |
|
|
|
if (jcjx_features.Count > 1) |
|
{ |
|
//相关基础界线标记删除,新生成的界线标记新增 |
|
foreach (var item in jcjx_features) |
|
{ |
|
if (JC_OID.Contains(item.OID)) |
|
continue; |
|
JC_OID.Add(item.OID); |
|
string jcjxlx2 = item.Value[item.Fields.FindField("JXLX")].ToString(); |
|
string jcjxxz2 = item.Value[item.Fields.FindField("JXXZ")].ToString(); |
|
InsertXZQGXFeature(item, 0, jcjxlx2, jcjxxz2, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
if (MS_OID.Contains(item.OID)) |
|
MS_OID.Remove(item.OID); |
|
} |
|
if (!string.IsNullOrWhiteSpace(bghJXLX)) |
|
InsertXZQGXFeature(f, 3, bghJXLX, "600001", JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
continue; |
|
} |
|
if (jcjx_features.Count == 0) |
|
{ |
|
//新生成的界线标记新增 |
|
InsertXZQGXFeature(f, 3, bghJXLX, "600001", JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
continue; |
|
} |
|
IFeature jcfeature = jcjx_features[0]; |
|
string jcjxlx = jcfeature.Value[jcfeature.Fields.FindField("JXLX")].ToString(); |
|
string jcjxxz = jcfeature.Value[jcfeature.Fields.FindField("JXXZ")].ToString(); |
|
double jcshapeLength = jcfeature.Value[jcfeature.Fields.FindField("SHAPE_LENGTH")].ToDouble(2); |
|
if (string.IsNullOrWhiteSpace(bghJXLX)) |
|
{ |
|
if (!JC_OID.Contains(jcfeature.OID)) |
|
{ |
|
JC_OID.Add(jcfeature.OID); |
|
InsertXZQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
if (MS_OID.Contains(jcfeature.OID)) |
|
MS_OID.Remove(jcfeature.OID); |
|
} |
|
continue; |
|
} |
|
if (gxshapeLength == jcshapeLength) |
|
{ |
|
if (!string.IsNullOrWhiteSpace(leftIsjctb) && !string.IsNullOrWhiteSpace(rightIsjctb)) |
|
{ |
|
continue; |
|
} |
|
//长度一样,表示界线图形为变化 |
|
if (bghJXLX == jcjxlx) |
|
{ |
|
InsertXZQGXFeature(jcfeature, 4, jcjxlx, jcjxxz, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
if (MS_OID.Contains(jcfeature.OID)) |
|
MS_OID.Remove(jcfeature.OID); |
|
continue; |
|
} |
|
else |
|
{ |
|
if (!JC_OID.Contains(jcfeature.OID)) |
|
{ |
|
JC_OID.Add(jcfeature.OID); |
|
InsertXZQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
if (MS_OID.Contains(jcfeature.OID)) |
|
MS_OID.Remove(jcfeature.OID); |
|
} |
|
//相关基础界线标记删除,新生成的界线标记新增 |
|
InsertXZQGXFeature(f, 3, bghJXLX, jcjxxz, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
} |
|
} |
|
else |
|
{ |
|
if (!JC_OID.Contains(jcfeature.OID)) |
|
{ |
|
JC_OID.Add(jcfeature.OID); |
|
InsertXZQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
if (MS_OID.Contains(jcfeature.OID)) |
|
MS_OID.Remove(jcfeature.OID); |
|
} |
|
//相关基础界线标记删除,新生成的界线标记新增 |
|
InsertXZQGXFeature(f, 3, bghJXLX, jcjxxz, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
} |
|
|
|
} |
|
foreach (var item in MS_OID) |
|
{ |
|
IFeature jcfeature = JCXZQJXFeatureLayer.FeatureClass.GetFeature(item); |
|
string jcjxlx = jcfeature.Value[jcfeature.Fields.FindField("JXLX")].ToString(); |
|
string jcjxxz = jcfeature.Value[jcfeature.Fields.FindField("JXXZ")].ToString(); |
|
InsertXZQGXFeature(jcfeature, 0, jcjxlx, jcjxxz, JCXZQJXFeatureLayer.FeatureClass, XZQJXGXFeatureClass); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("行政区数据提取发生异常!异常信息如下:"); |
|
LogAPI.Debug(ex); |
|
LogAPI.Debug("异常信息结束"); |
|
} |
|
} |
|
|
|
private void JCXZQInsertGX(List<IFeature> jcfeatures, IFeatureClass gxfeatureClass, IQueryFilter pFilter) |
|
{ |
|
IFeatureCursor T_Cursor = null; |
|
try |
|
{ |
|
Dictionary<int, int> fieldsDic = new Dictionary<int, int>(); |
|
for (int i = 0; i < gxfeatureClass.Fields.FieldCount; i++) |
|
{ |
|
IField field = gxfeatureClass.Fields.Field[i]; |
|
if (field.Name == gxfeatureClass.ShapeFieldName || field.Name.Contains(gxfeatureClass.ShapeFieldName) || field.Name == gxfeatureClass.OIDFieldName || !field.Editable) continue; |
|
|
|
int index = -1; |
|
index = jcfeatures[0].Fields.FindField(field.Name); |
|
if (index == -1) |
|
index = jcfeatures[0].Fields.FindField(field.AliasName); |
|
if (index == -1) |
|
continue; |
|
|
|
fieldsDic.Add(i, index); |
|
} |
|
if (fieldsDic.Count != 0) |
|
{ |
|
IFeatureBuffer buffer = gxfeatureClass.CreateFeatureBuffer(); |
|
T_Cursor = gxfeatureClass.Insert(true); |
|
int gxgcIndex = gxfeatureClass.FindField("IsJCTB"); |
|
for (int i = 0; i < jcfeatures.Count; i++) |
|
{ |
|
IFeature f = jcfeatures[i]; |
|
buffer.Shape = f.ShapeCopy; |
|
|
|
foreach (int item in fieldsDic.Keys) |
|
{ |
|
if (string.IsNullOrWhiteSpace(f.Value[fieldsDic[item]].ToTrim())) |
|
buffer.Value[item] = DBNull.Value; |
|
buffer.Value[item] = f.Value[fieldsDic[item]]; |
|
} |
|
if (gxgcIndex != -1) |
|
{ |
|
buffer.Value[gxgcIndex] = "1"; |
|
} |
|
T_Cursor.InsertFeature(buffer); |
|
} |
|
T_Cursor.Flush(); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("基础村级调查区向临时库村级调查区更新层插入数据失败:" + ex.Message); |
|
} |
|
} |
|
|
|
private void XZQGXMSInsertGX(IFeatureClass gxgcfeatureClass, IFeatureClass gxfeatureClass, IQueryFilter pFilter) |
|
{ |
|
IFeatureCursor T_Cursor = null; |
|
IFeatureCursor S_Cursor = null; |
|
|
|
try |
|
{ |
|
Dictionary<int, int> fieldsDic = new Dictionary<int, int>(); |
|
for (int i = 0; i < gxfeatureClass.Fields.FieldCount; i++) |
|
{ |
|
IField field = gxfeatureClass.Fields.Field[i]; |
|
if (field.Name == gxfeatureClass.ShapeFieldName || field.Name.Contains(gxfeatureClass.ShapeFieldName) || field.Name == gxfeatureClass.OIDFieldName || !field.Editable) continue; |
|
|
|
int index = -1; |
|
string gxgcfield = "BGH" + field.Name; |
|
index = gxgcfeatureClass.Fields.FindField(gxgcfield); |
|
if (index == -1) |
|
continue; |
|
|
|
fieldsDic.Add(i, index); |
|
} |
|
|
|
if (fieldsDic.Count != 0) |
|
{ |
|
IFeatureBuffer buffer = gxfeatureClass.CreateFeatureBuffer(); |
|
T_Cursor = gxfeatureClass.Insert(true); |
|
int gxgcIndex = gxfeatureClass.FindField("IsJCTB"); |
|
|
|
IFeature gxgcfeature = null; |
|
S_Cursor = gxgcfeatureClass.Search(pFilter, true); |
|
while ((gxgcfeature = S_Cursor.NextFeature()) != null) |
|
{ |
|
buffer.Shape = gxgcfeature.ShapeCopy; |
|
foreach (int item in fieldsDic.Keys) |
|
{ |
|
if (string.IsNullOrWhiteSpace(gxgcfeature.Value[fieldsDic[item]].ToTrim())) |
|
buffer.Value[item] = DBNull.Value; |
|
buffer.Value[item] = gxgcfeature.Value[fieldsDic[item]]; |
|
} |
|
T_Cursor.InsertFeature(buffer); |
|
Marshal.ReleaseComObject(gxgcfeature); |
|
} |
|
T_Cursor.Flush(); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("基础行政区向临时库行政区更新层插入数据失败:" + ex.Message); |
|
} |
|
} |
|
public void InsertXZQGXFeature(IFeature pGXJX, int BGXW, string JXLX, string JXXZ, IFeatureClass JC_XZQJX, IFeatureClass XZQJXGX) |
|
{ |
|
IFeatureCursor gx_cursor = null; |
|
IFeatureBuffer gx_buffer = null; |
|
try |
|
{ |
|
bool IsInsert = true; |
|
var Identify = FeatureAPI.Identify2(pGXJX.Shape, new FeatureLayer() { FeatureClass = XZQJXGX }); |
|
if (Identify.Count > 0) |
|
{ |
|
foreach (var item in Identify) |
|
{ |
|
if (FeatureAPI.GetEqual(item.ShapeCopy, pGXJX.Shape) && FeatureAPI.GetEqual(pGXJX.Shape, item.ShapeCopy) && BGXW != 3) |
|
{ |
|
IsInsert = false; |
|
break; |
|
} |
|
} |
|
} |
|
if (IsInsert) |
|
{ |
|
if (string.IsNullOrWhiteSpace(strXZQJXMaxBSM)) |
|
{ |
|
strXZQJXMaxBSM = SetMaxBSM(JC_XZQJX, XZQJXGX); |
|
if (!strXZQJXMaxBSM.StartsWith(IDGParm.PrjInfo.CODE)) |
|
strXZQJXMaxBSM = IDGParm.PrjInfo.CODE + "1220" + "1".PadLeft(8, '0'); |
|
} |
|
else |
|
{ |
|
string bsmPrefix = IDGParm.PrjInfo.CODE + strXZQJXMaxBSM.Substring(6, 4); |
|
int MaxNum = Convert.ToInt32(strXZQJXMaxBSM.Substring(9)); |
|
strXZQJXMaxBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); |
|
} |
|
gx_cursor = XZQJXGX.Insert(true); |
|
gx_buffer = XZQJXGX.CreateFeatureBuffer(); |
|
gx_buffer.Shape = pGXJX.Shape; |
|
gx_buffer.set_Value(gx_buffer.Fields.FindField("BSM"), BGXW == 3 ? strXZQJXMaxBSM : pGXJX.Value[pGXJX.Fields.FindField("BSM")]); |
|
gx_buffer.set_Value(gx_buffer.Fields.FindField("JXLX"), JXLX); |
|
gx_buffer.set_Value(gx_buffer.Fields.FindField("JXXZ"), JXXZ); |
|
gx_buffer.set_Value(gx_buffer.Fields.FindField("JXSM"), BGXW == 3 ? string.Empty : pGXJX.Value[pGXJX.Fields.FindField("JXSM")]); |
|
gx_buffer.set_Value(gx_buffer.Fields.FindField("BZ"), BGXW == 3 ? string.Empty : pGXJX.Value[pGXJX.Fields.FindField("BZ")]); |
|
gx_buffer.set_Value(gx_buffer.Fields.FindField("BGXW"), BGXW); |
|
gx_buffer.set_Value(gx_buffer.Fields.FindField("GXSJ"), DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : new DateTime(DateTime.Now.Year - 1, 12, 31)); |
|
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<IFeatureClass>() { 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<IFeatureClass> fcList) |
|
{ |
|
int xh = 0; |
|
string MaxBSM = ""; |
|
string leftStr = string.Empty; |
|
foreach (var fc in fcList) |
|
{ |
|
string BSM = string.Empty; |
|
int BSMIndex = fc.FindField("BSM"); |
|
if (BSMIndex == -1) return BSM; |
|
|
|
ITable table = (ITable)fc; |
|
// 创建一个ITableSort接口对象 |
|
ITableSort tableSort = new TableSortClass(); |
|
tableSort.Table = table; |
|
tableSort.Fields = "BSM"; |
|
tableSort.set_Ascending("BSM", false); |
|
tableSort.Sort(null); |
|
ICursor cursor = tableSort.Rows; |
|
IRow row = cursor.NextRow(); |
|
if (row != null) |
|
{ |
|
int maxBSM = 0; |
|
int currBSM = 0; |
|
string BSMStr = row.Value[BSMIndex].ToString(); |
|
if (BSMStr.Length != 18) return BSM; |
|
string subBSMStr = BSMStr.Substring(9); |
|
try |
|
{ |
|
currBSM = Convert.ToInt32(subBSMStr); |
|
} |
|
catch (Exception) |
|
{ |
|
return BSM; |
|
} |
|
if (currBSM > maxBSM) maxBSM = currBSM; |
|
|
|
if (BSMStr.Length != 18) return BSM; |
|
string maxStr = maxBSM.ToString(); |
|
int zeroNum = 9 - maxStr.Length; |
|
for (int i = 0; i < zeroNum; i++) |
|
{ |
|
maxStr = 0 + maxStr; |
|
} |
|
BSM = BSMStr.Substring(0, 9) + maxStr; |
|
} |
|
if (BSM.Length != 18) |
|
continue; |
|
int xh2 = Convert.ToInt32(BSM.Substring(10)); |
|
leftStr = BSM.Substring(0, 10); |
|
if (xh < xh2) |
|
{ |
|
xh = xh2; |
|
MaxBSM = BSM; |
|
} |
|
} |
|
return MaxBSM; |
|
} |
|
|
|
#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 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 GenerateGxgcDataForXZQ |
|
public void GenerateGxgcDataForXZQ(IDGParameter pParm) |
|
{ |
|
Geoprocessor gp = null; |
|
IWorkspaceFactory pFtWsFct = null; |
|
IWorkspaceName workspaceName = null; |
|
try |
|
{ |
|
//IMapService _MapService = MapsManager.Instance.MapService; |
|
gp = new Geoprocessor() |
|
{ |
|
OverwriteOutput = true |
|
}; |
|
IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();//对两个要素类进行相交运算 |
|
gpValueTableObject.SetColumns(2); |
|
object o1 = JcXzqLayer; |
|
object o2 = GxXzqLayer; |
|
gpValueTableObject.AddRow(ref o2); |
|
gpValueTableObject.AddRow(ref o1); |
|
|
|
//string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\GXGC"; |
|
//if (!System.IO.Directory.Exists(gdbFolder)) |
|
//{ |
|
// System.IO.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 = GxXzqLayer as IFeatureLayer; |
|
gPParamClass.SecondFeatureLayer = JcXzqLayer as IFeatureLayer; |
|
gPParamClass.OutFeatureClassPath = TempGDBPath + "\\" + "TempGXGC"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.Union; |
|
//GeoprocessorHelper gpHelper = new GeoprocessorHelper(); |
|
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); |
|
//string dbPath = IDGParm.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"); |
|
System.Data.DataTable ChangeDT = rdbHelper.ExecuteDatatable("change", "select XZQDM,XZQDM_1,XZQMC,XZQMC_1,MSSM,HDMC from TempGXGC_MToS where xzqdm<>xzqdm_1 or xzqmc<>xzqmc_1 or objectid not in (select objectid from (select * from TempGXGC_MToS group by FID_JC_XZQ HAVING count(0)=1) where FID_XZQGX>-1 and FID_JC_XZQ>-1)", true); |
|
List<string> listZL = new List<string>(); |
|
List<string> listMS = new List<string>(); |
|
if (ChangeDT != null) |
|
{ |
|
if (ChangeDT.Rows.Count == 0) return; |
|
foreach (System.Data.DataRow dr in ChangeDT.Rows) |
|
{ |
|
string zl = dr["XZQDM"].ToTrim(); |
|
string mssm = dr["MSSM"].ToTrim(); |
|
string xzqmc = dr["XZQMC"].ToTrim(); |
|
string key = zl + "_" + mssm + "_" + xzqmc; |
|
if (string.IsNullOrWhiteSpace(zl)) |
|
{ |
|
if (!listMS.Contains(dr["XZQDM_1"].ToTrim())) |
|
listMS.Add(dr["XZQDM_1"].ToTrim()); |
|
continue; |
|
} |
|
if (listZL.Contains(key)) continue; |
|
listZL.Add(key); |
|
} |
|
} |
|
System.Data.DataTable delDt = rdbHelper.ExecuteDatatable("del", "select objectid,XZQDM_1,XZQMC_1,MSSM_1,HDMC_1 from (select * from TempGXGC_MToS group by FID_JC_XZQ HAVING count(0)=1) where FID_XZQGX>-1 and FID_JC_XZQ>-1 and xzqdm=xzqdm_1", 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["XZQDM_1"].ToTrim(); |
|
string mssm = dr["MSSM_1"].ToTrim(); |
|
string xzqmc = dr["XZQMC_1"].ToTrim(); |
|
string key = zl + "_" + mssm + "_" + xzqmc; |
|
DataRow[] rows = allDT.Select(string.Format("XZQDM='{0}' and MSSM='{1}'", zl, mssm)); |
|
if (rows.Length > 1) continue; |
|
if (listZL.Contains(zl)) continue; |
|
if (listMS.Contains(zl)) continue; |
|
pjbntFeatureLayer.FeatureClass.GetFeature(oid).Delete(); |
|
} |
|
} |
|
outFc = pjbntFeatureLayer.FeatureClass; |
|
IFeatureClassAPI gcFcAPI = new FeatureClassAPI(outFc); |
|
gcFcAPI.AddField("XZQTZLX", esriFieldType.esriFieldTypeString, ""); |
|
Dictionary<int, BGHAttributeModel> bghAttr = new Dictionary<int, BGHAttributeModel>(); |
|
Dictionary<int, GXAttributeModel> gxAttr = new Dictionary<int, GXAttributeModel>(); |
|
SetAttribueForXZQ(outFc, (JcXzqLayer as IFeatureLayer).FeatureClass, (GxXzqLayer as IFeatureLayer).FeatureClass, ref bghAttr, ref gxAttr); |
|
IFeatureClass gxgcFc = (GxgcXzqLayer as IFeatureLayer).FeatureClass; //_MapService.GetFeatureClassByName("XZQGXGC"); |
|
ITable cjdcqgxgcTb = gxgcFc as ITable; |
|
cjdcqgxgcTb.DeleteSearchedRows(null);//删除村级调查区更新过程所有数据 |
|
Dictionary<int, int> target_SourMaping = new Dictionary<int, int>(); |
|
Dictionary<string, object> fieldValues = new Dictionary<string, object>(); |
|
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); |
|
//gpValueTableObject = new GpValueTableObjectClass();//对两个要素类进行相交运算 |
|
//gpValueTableObject.SetColumns(2); |
|
//object o3 = outFc; |
|
//object o4 = pBgParm.NMTBLayer; |
|
//gpValueTableObject.AddRow(ref o3); |
|
//gpValueTableObject.AddRow(ref o4); |
|
//Intersect process2 = new Intersect(); |
|
//process2.in_features = gpValueTableObject; |
|
//process2.out_feature_class = TempGDBPath + "\\" + "TempGXGC_DLTB"; |
|
//process2.join_attributes = "ALL"; |
|
//IGeoProcessorResult tGeoResult2 = (IGeoProcessorResult)gp.Execute(process2, null); |
|
|
|
IFeatureLayer _tempLayer = null; |
|
pjbntFeatureLayer.FeatureClass = outFc; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = pjbntFeatureLayer; |
|
gPParamClass.SecondFeatureLayer = NmTbLayer; |
|
gPParamClass.OutFeatureClassPath = TempGDBPath + "\\" + "TempGXGC_DLTB"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
gPParamClass.GPType = EnumGPType.Intersect; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref _tempLayer); |
|
|
|
//if (tGeoResult2 == null || tGeoResult2.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) |
|
//{ |
|
// string msg = ReturnMessages(gp); |
|
// throw new Exception(msg); |
|
//} |
|
IFeatureClass outFc2 = _tempLayer.FeatureClass; |
|
Console.WriteLine("xzq"); |
|
ITable table = outFc2 as ITable; |
|
ICursor cursor = table.Search(new QueryFilterClass() { SubFields = "OBJECTID,SHAPE,FID_TempGXGC_MToS,FID_DLTB_NMK,BSM_12,XZQDM,MSSM,HDMC,TBMJ,XZQTZLX_1" }, true); |
|
IRow row = null; |
|
List<int> DicNMKOids = new List<int>(); |
|
int nmkoidIdx = table.FindField("FID_DLTB_NMK"); |
|
int oidIdx = table.FindField("FID_TempGXGC_MToS"); |
|
int mjIdx = table.FindField("TBMJ"); |
|
int xzqdmIdx = table.FindField("XZQDM"); |
|
int xzqmcIdx = table.FindField("XZQMC"); |
|
int mssmIdx = table.FindField("MSSM"); |
|
int hdmcIdx = table.FindField("HDMC"); |
|
int nmkBSMIdx = table.FindField("BSM_12"); |
|
int xzqtzlxIdx = table.FindField("XZQTZLX_1"); |
|
int ShapeIdx = table.FindField("SHAPE"); |
|
Dictionary<int, List<PCModel>> dicPcList = new Dictionary<int, List<PCModel>>(); |
|
Dictionary<int, string> dicXZQTZLX = new Dictionary<int, string>(); |
|
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(); |
|
if (oid == 39108) |
|
{ |
|
} |
|
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<PCModel>() { 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<PCModel> pcList = new List<PCModel>(); |
|
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<IFeature> gcFList = FeatureAPI.Identify2(f.ShapeCopy, tempLayer); |
|
double bgmj = 0; |
|
int gcBgmjIdx = tempLayer.FeatureClass.FindField("TBBGMJ"); |
|
if (gcFList.Count == 0) |
|
{ |
|
gcFList = FeatureAPI.Identify2(f.ShapeCopy, jcDLTBLayer); |
|
gcBgmjIdx = jcDLTBLayer.FeatureClass.FindField("TBMJ"); |
|
} |
|
if (gcBgmjIdx != -1) |
|
{ |
|
foreach (var gc in gcFList) |
|
{ |
|
bgmj += gc.Value[gcBgmjIdx].ToDouble(2); |
|
} |
|
if (Math.Abs(pc.JSMJ - bgmj) < 500) |
|
pc.JSMJ = bgmj; |
|
} |
|
else |
|
{ |
|
pc.JSMJ = (f.ShapeCopy as IPolygon).GetEllipseArea().ToDouble(2); |
|
} |
|
//pcList.Add(pc); |
|
} |
|
double jsmj = item.Value.Sum(p => p.JSMJ); |
|
double tbmj = item.Value[0].TBMJ; |
|
if (jsmj != tbmj) |
|
{ |
|
List<PCModel> 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<int, double> bgmjList = new Dictionary<int, double>(); |
|
Dictionary<string, double> dcmjList = new Dictionary<string, double>(); |
|
cursor = table.Search(new QueryFilterClass() { SubFields = "OBJECTID,FID_TempGXGC_MToS,FID_DLTB_NMK,XZQDM,XZQMC,MSSM,HDMC,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(); |
|
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 bghDCMJIndex = gxgcFc.FindField("BGHDCMJ"); |
|
int bgqDCMJIndex = gxgcFc.FindField("BGQDCMJ"); |
|
int bghZLDWDMIndex = gxgcFc.FindField("BGHXZQDM"); |
|
int bgqZLDWDMIndex = gxgcFc.FindField("BGQXZQDM"); |
|
|
|
int bghMSSMIndex = gxgcFc.FindField("BGHMSSM"); |
|
int bgqMSSMIndex = gxgcFc.FindField("BGQMSSM"); |
|
int bgqHDMCIndex = gxgcFc.FindField("BGQHDMC"); |
|
int bghHDMCIndex = gxgcFc.FindField("BGHHDMC"); |
|
|
|
int bghZLDWMCIndex = gxgcFc.FindField("BGHXZQMC"); |
|
int bgqZLDWMCIndex = gxgcFc.FindField("BGQXZQMC"); |
|
|
|
int xzqtzlxIndex = outFc.FindField("XZQTZLX"); |
|
int bgqOIDIndex = outFc.FindField("FID_XZQGX"); |
|
IFeatureLayer cjdcqLayer = GxgcXzqLayer as IFeatureLayer;// _MapService.GetFeatureLayerByName("CJDCQGXGC"); |
|
int cjdcqHDMC = cjdcqLayer.FeatureClass.FindField("BGHHDMC"); |
|
IQueryFilter delFilter = new QueryFilterClass() { WhereClause = "1=2" }; |
|
List<DataDicTionary> dicQS = null;// Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM); |
|
if (dicQS == null) |
|
dicQS = new List<DataDicTionary>(); |
|
Dictionary<string, string> dicHDMC = new Dictionary<string, string>(); |
|
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] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : 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 = buf.Value[bghZLDWMCIndex].ToTrim(); |
|
string key = xzqdm + "_" + mssm + "_" + xzqmc; |
|
if (dcmjList.ContainsKey(key)) |
|
buf.Value[bghDCMJIndex] = dcmjList[key].ToDouble(2); |
|
DataDicTionary dic = dicQS.FirstOrDefault(d => d.CODE == xzqdm); |
|
if (dic != null) |
|
{ |
|
buf.Value[bghZLDWMCIndex] = dic.NAME; |
|
} |
|
} |
|
if (bghAttr.ContainsKey(s.OID)) |
|
{ |
|
if (bghAttr[s.OID].BGXW == "3") |
|
{ |
|
List<IFeature> cjdcqList = FeatureAPI.Identify2(s.ShapeCopy, cjdcqLayer); |
|
if (cjdcqList.Count > 0 && cjdcqHDMC != -1) |
|
{ |
|
buf.Value[bghHDMCIndex] = cjdcqList[0].Value[cjdcqHDMC]; |
|
} |
|
} |
|
else |
|
{ |
|
buf.Value[bghHDMCIndex] = buf.Value[bgqHDMCIndex]; |
|
} |
|
if (!dicHDMC.ContainsKey(bghAttr[s.OID].BGHBSM)) |
|
{ |
|
dicHDMC.Add(bghAttr[s.OID].BGHBSM, buf.Value[bghHDMCIndex].ToTrim()); |
|
} |
|
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<IFeature> 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<IFeature> 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<IFeature> 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 hdmc = ""; |
|
string key = xzqdm + "_" + mssm + "_" + hdmc; |
|
if (dcmjList.ContainsKey(key)) |
|
{ |
|
dcmjList[key] = dcmjList[key] - bgmj; |
|
buf.Value[bghDCMJIndex] = dcmjList[key].ToDouble(2); |
|
} |
|
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; |
|
} |
|
} |
|
} |
|
string dm = buf.Value[bgqZLDWDMIndex].ToTrim(); |
|
if (buf.Value[bgmjIndex].ToDouble() == 0 || (buf.Value[bgqDCMJIndex].ToTrim() == buf.Value[bghDCMJIndex].ToTrim() && 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 jsmjIndex = (o2 as ITable).FindField("JSMJ"); |
|
int xzqdmIndex = (o2 as ITable).FindField("XZQDM"); |
|
int mssmIndex = (o2 as ITable).FindField("MSSM"); |
|
int hdmcIndex = (o2 as ITable).FindField("HDMC"); |
|
int xzqmcIndex = (o2 as ITable).FindField("XZQMC"); |
|
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] = DateTime.Now.Month >= 10 ? new DateTime(DateTime.Now.Year, 12, 31) : 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; |
|
if (dicHDMC.ContainsKey(gxAttr[row.OID].BSM)) |
|
{ |
|
row.Value[hdmcIndex] = dicHDMC[gxAttr[row.OID].BSM]; |
|
} |
|
string xzqdm = row.Value[xzqdmIndex].ToTrim(); |
|
string mssm = row.Value[mssmIndex].ToTrim(); |
|
string hdmc = row.Value[xzqmcIndex].ToTrim(); |
|
string key = xzqdm + "_" + mssm + "_" + hdmc; |
|
if (dcmjList.ContainsKey(key)) |
|
row.Value[dcmjIndex] = dcmjList[key].ToDouble(2); |
|
DataDicTionary dic = dicQS.FirstOrDefault(d => d.CODE == xzqdm); |
|
if (dic != null) |
|
{ |
|
row.Value[xzqmcIndex] = dic.NAME; |
|
} |
|
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 SetAttribueForXZQ |
|
public void SetAttribueForXZQ(IFeatureClass pGxgcFc, IFeatureClass pJCFc, IFeatureClass pGxFc, ref Dictionary<int, BGHAttributeModel> bghAttr, ref Dictionary<int, GXAttributeModel> gxAttr) |
|
{ |
|
try |
|
{ |
|
//IMapService _MapService = MapsManager.Instance.MapService; |
|
IFeatureLayer gxLayer = new FeatureLayerClass() { FeatureClass = pGxFc }; |
|
IFeatureClass jcFc = pJCFc; |
|
IQueryFilter filter = new QueryFilterClass() { SubFields = "OBJECTID,FID_JC_XZQ,BSM_1,FID_XZQGX,XZQDM,XZQTZLX" }; |
|
IFeatureCursor cursor = pGxgcFc.Search(filter, true); |
|
IFeature fe = null; |
|
int jcOIDIndex = pGxgcFc.FindField("FID_JC_XZQ"); |
|
int jcBSMIndex = pGxgcFc.FindField("BSM_1"); |
|
int XZQTZLXIndex = pGxgcFc.FindField("XZQTZLX"); |
|
int gxOIDIndex = pGxgcFc.FindField("FID_XZQGX"); |
|
int gxZLDWDMIndex = pGxgcFc.FindField("XZQDM"); |
|
List<OIDMapping> txbgOID = new List<OIDMapping>(); |
|
List<OIDMapping> list = new List<OIDMapping>(); |
|
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<IFeatureClass>() { jcFc }); |
|
if (!MaxBSM.StartsWith(IDGParm.PrjInfo.CODE)) |
|
{ |
|
MaxBSM = IDGParm.PrjInfo.CODE + MaxBSM.Substring(6); |
|
} |
|
IEnumerable<IGrouping<int, OIDMapping>> groupbgq = list.GroupBy(g => g.bgqOID); |
|
foreach (var item in groupbgq) |
|
{ |
|
List<OIDMapping> 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<OIDMapping> tempList = item.ToList(); |
|
if (tempList.Count > 1) |
|
{ |
|
string bgqBSM = string.Empty; |
|
string bghBSM = string.Empty; |
|
if (string.IsNullOrWhiteSpace(MaxBSM)) |
|
MaxBSM = GetNewBSM(new List<IFeatureClass>() { 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("XZQDM"); |
|
List<IFeatureClass> fcList = new List<IFeatureClass>() { 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"; |
|
} |
|
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 获取最新标识码 |
|
public string GetNewBSM(List<IFeatureClass> 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 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 |
|
|
|
public class XZQ_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; } |
|
|
|
} |
|
} |
|
public class PCModel |
|
{ |
|
public int OID { get; set; } |
|
public int NMKOID { get; set; } |
|
public string NMKBSM { get; set; } |
|
public double TBMJ { get; set; } |
|
public double JSMJ { get; set; } |
|
} |
|
public class BGHAttributeModel |
|
{ |
|
public int BGHOID { get; set; } |
|
public string BGHBSM { get; set; } |
|
public string BGHTBBH { get; set; } |
|
public double BGMJ { get; set; } |
|
public string BGXW { get; set; } |
|
public string XZQTZLX { get; set; } |
|
} |
|
public class GXAttributeModel |
|
{ |
|
public string BSM { get; set; } |
|
public string TBBH { get; set; } |
|
public double TBMJ { get; set; } |
|
} |
|
public class OIDMapping |
|
{ |
|
/// <summary> |
|
/// 过程层OID |
|
/// </summary> |
|
public int gcOID { get; set; } |
|
/// <summary> |
|
/// 变更前OID |
|
/// </summary> |
|
public int bgqOID { get; set; } |
|
/// <summary> |
|
/// 变更前图斑标识码 |
|
/// </summary> |
|
public string bgqTBBSM { get; set; } |
|
/// <summary> |
|
/// 变更前图斑编号 |
|
/// </summary> |
|
public string bgqTBBH { get; set; } |
|
/// <summary> |
|
/// 变更后OID |
|
/// </summary> |
|
public int bghOID { get; set; } |
|
/// <summary> |
|
/// 变更后图斑标识码 |
|
/// </summary> |
|
public string bghTBBSM { get; set; } |
|
/// <summary> |
|
/// 变更后坐落单位代码 |
|
/// </summary> |
|
public string bghZLDWDM { get; set; } |
|
/// <summary> |
|
/// 变更后图斑编号 |
|
/// </summary> |
|
public string bghTBBH { get; set; } |
|
/// <summary> |
|
/// 是否图形变更 |
|
/// </summary> |
|
public bool IsTXBG { get; set; } |
|
/// <summary> |
|
/// 变更面积 |
|
/// </summary> |
|
public double BGMJ { get; set; } |
|
public string XZQTZLX { get; set; } |
|
public bool IsSplit { get; set; } |
|
} |
|
}
|
|
|