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.
709 lines
33 KiB
709 lines
33 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.esriSystem; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.AE.Enum; |
|
using KGIS.Framework.AE.GPHelper; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using Kingo.PluginServiceInterface; |
|
using Kingo.PluginServiceInterface.Model; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using System.Runtime.InteropServices; |
|
|
|
namespace KGIS_DLTB |
|
{ |
|
public class BaseIDG : IDisposable |
|
{ |
|
//private IFeatureLayer jCLayer; |
|
internal IFeatureLayer _jcTbLayer; |
|
internal IFeatureLayer _gxgcTBLayer; |
|
internal IFeatureLayer _gxTbLayer; |
|
internal IFeatureLayer _bgTbLayer; |
|
internal IFeatureLayer _cjqTbLayer; |
|
internal IFeatureLayer _jcCjdcqLayer; |
|
internal IFeatureLayer _jcCjdcqJxLayer; |
|
internal IFeatureLayer _gxCjdcqLayer; |
|
internal IFeatureLayer _gxgcCjdcqLayer; |
|
internal IFeatureLayer _gxCjdcqJxLayer; |
|
internal IFeatureLayer _jcXzqLayer; |
|
internal IFeatureLayer _jcXzqJxLayer; |
|
internal IFeatureLayer _gxXzqLayer; |
|
internal IFeatureLayer _gxgcXzqLayer; |
|
internal IFeatureLayer _gxXzqJxLayer; |
|
internal IFeatureLayer _jcCzcLayer; |
|
internal IFeatureLayer _gxCzcLayer; |
|
internal IFeatureLayer _gxgcCzcLayer; |
|
internal IFeatureLayer _jcGddbLayer; |
|
internal IFeatureLayer _gxGddbLayer; |
|
internal IFeatureLayer _jcPdtLayer; |
|
internal IFeatureLayer _gxPdtLayer; |
|
internal IFeatureLayer _nmTbLayer; |
|
|
|
public IWorkspaceAPI BgWsAPI { get; set; } |
|
public Dictionary<string, IWorkspaceAPI> DicWsAPI { get; set; } |
|
public IWorkspaceAPI ZlWsAPI { get; set; } |
|
public IWorkspaceAPI NmWsAPI { get; set; } |
|
public IWorkspaceAPI JCWsAPI { get; set; } |
|
//public IFeatureLayer JCLayer { get => jCLayer; set => jCLayer = value; } |
|
//public IFeatureLayer GXLayer { get => gXLayer; set => gXLayer = value; } |
|
public IFeatureLayer NmTbLayer { get => _nmTbLayer; set => _nmTbLayer = value; } |
|
#region 地类图斑 |
|
public IFeatureLayer JcTbLayer { get => _jcTbLayer; } |
|
public IFeatureLayer JcPdtLayer { get => _jcPdtLayer; } |
|
public IFeatureLayer GxgcTBLayer { get => _gxgcTBLayer; } |
|
public IFeatureLayer GxTbLayer { get => _gxTbLayer; } |
|
public IFeatureLayer GxPdtLayer { get => _gxPdtLayer; } |
|
|
|
public IFeatureLayer BgTbLayer { get => _bgTbLayer; } |
|
public IFeatureLayer CJQTbLayer { get => _cjqTbLayer; } |
|
#endregion |
|
|
|
#region 村级调查区 |
|
public IFeatureLayer JcCjdcqLayer { get => _jcCjdcqLayer; set => _jcCjdcqLayer = value; } |
|
public IFeatureLayer JcCjdcqJxLayer { get => _jcCjdcqJxLayer; } |
|
public IFeatureLayer GxCjdcqLayer { get => _gxCjdcqLayer; } |
|
public IFeatureLayer GxgcCjdcqLayer { get => _gxgcCjdcqLayer; } |
|
public IFeatureLayer GxCjdcqJxLayer { get => _gxCjdcqJxLayer; } |
|
#endregion |
|
|
|
#region 行政区 |
|
public IFeatureLayer JcXzqLayer { get => _jcXzqLayer; set => _jcXzqLayer = value; } |
|
public IFeatureLayer JcXzqJxLayer { get => _jcXzqJxLayer; } |
|
public IFeatureLayer GxXzqLayer { get => _gxXzqLayer; } |
|
public IFeatureLayer GxgcXzqLayer { get => _gxgcXzqLayer; } |
|
public IFeatureLayer GxXzqJxLayer { get => _gxXzqJxLayer; } |
|
#endregion |
|
|
|
#region 城镇村 |
|
public IFeatureLayer JcCzcLayer { get => _jcCzcLayer; } |
|
public IFeatureLayer GxCzcLayer { get => _gxCzcLayer; } |
|
public IFeatureLayer GxgcCzcLayer { get => _gxgcCzcLayer; } |
|
#endregion |
|
|
|
#region 耕地等别 |
|
public IFeatureLayer JcGddbLayer { get => _jcGddbLayer; } |
|
public IFeatureLayer GxGddbLayer { get => _gxGddbLayer; } |
|
#endregion |
|
public virtual void CreateNMK2(IDGParameter parm) |
|
{ |
|
try |
|
{ |
|
IFeatureLayer TempNMKLayer = null; |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = JcTbLayer;//基础地类图斑要素类 |
|
gPParamClass.SecondFeatureLayer = GxTbLayer;//地类图斑更新要素类 |
|
gPParamClass.OutFeatureClassPath = parm.PrjInfo.NMDatabase + "\\" + "DLTB_NMK";//要添加的要素类图层 |
|
gPParamClass.IsGetOutPutFeature = true;//是否获取GP工具生成后的图层 |
|
gPParamClass.GPType = EnumGPType.Erase; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref TempNMKLayer);//擦除/相减分析 |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(TempNMKLayer.FeatureClass); |
|
fcAPI.AddField("XZQDM", esriFieldType.esriFieldTypeString, "行政区代码"); |
|
fcAPI.AddField("XZQTZLX", esriFieldType.esriFieldTypeInteger, "行政区调整类型"); |
|
//fcAPI.FcToFc(NMKLayer.FeatureClass, null, false); |
|
fcAPI = new FeatureClassAPI(GxTbLayer.FeatureClass); |
|
fcAPI.FcToFc(TempNMKLayer.FeatureClass, null, false); |
|
|
|
ITable nmkTable = TempNMKLayer.FeatureClass as ITable; |
|
//更新后年末库 |
|
ICursor nmkCur = nmkTable.Update(null, true); |
|
IRow nmkRow = null; |
|
int bsmIdx = nmkTable.FindField("BSM"); |
|
int zldwIdx = nmkTable.FindField("ZLDWDM"); |
|
int xzqdmIdx = nmkTable.FindField("XZQDM"); |
|
int XZQTZLXmIdx = nmkTable.FindField("XZQTZLX"); |
|
int HDMCIdx = nmkTable.FindField("HDMC"); |
|
while ((nmkRow = nmkCur.NextRow()) != null) |
|
{ |
|
//string bsm = nmkRow.Value[bsmIdx].ToTrim(); |
|
//if (hcbghbsm.Contains(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 2; |
|
//} |
|
//else if (msbghbsm.Contains(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 4; |
|
//} |
|
//else if (msbgqbsm.Contains(bsm) && !bghbsmDic.ContainsKey(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 4; |
|
//} |
|
//if (bhxxDic.ContainsKey(bsm)) |
|
//{ |
|
// for (int i = 0; i < nmkRow.Fields.FieldCount; i++) |
|
// { |
|
// IField field = nmkRow.Fields.Field[i]; |
|
// string bghField = "BGH" + field.Name; |
|
// DataRow dr = bhxxDic[bsm]; |
|
// if (!dr.Table.Columns.Contains(bghField)) |
|
// bghField = "BGHTB" + field.Name; |
|
// if (dr.Table.Columns.Contains(bghField)) |
|
// { |
|
// if (field.Type == esriFieldType.esriFieldTypeString) |
|
// { |
|
// nmkRow.Value[i] = msbghbsm.Contains(bsm) ? "" : dr[bghField]; |
|
// } |
|
// else if (field.Type == esriFieldType.esriFieldTypeDouble) |
|
// { |
|
// nmkRow.Value[i] = msbghbsm.Contains(bsm) ? 0 : dr[bghField].ToDouble(); |
|
// } |
|
// } |
|
// } |
|
//} |
|
if (zldwIdx != -1 && xzqdmIdx != -1) |
|
{ |
|
string zldwdm = nmkRow.Value[zldwIdx].ToTrim(); |
|
if (!string.IsNullOrWhiteSpace(zldwdm) && zldwdm.Length > 9) |
|
{ |
|
nmkRow.Value[xzqdmIdx] = zldwdm.Substring(0, 9); |
|
} |
|
} |
|
if (HDMCIdx != -1) |
|
nmkRow.Value[HDMCIdx] = nmkRow.Value[HDMCIdx].ToString().ToTrim() == "" ? "" : nmkRow.Value[HDMCIdx].ToString().ToTrim(); |
|
nmkCur.UpdateRow(nmkRow); |
|
} |
|
nmkCur.Flush(); |
|
nmkTable.DeleteSearchedRows(new QueryFilterClass() { WhereClause = "XZQTZLX=4 or XZQTZLX=2" }); |
|
_nmTbLayer = TempNMKLayer; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 生成年末库图层-GP创建年末库图层 |
|
/// </summary> |
|
/// <param name="parm"></param> |
|
public virtual void CreateNMK3(IDGParameter parm) |
|
{ |
|
IFeatureCursor _cursor = null; |
|
try |
|
{ |
|
IFeatureLayer TempNMKLayer = null; |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = JcTbLayer;//基础地类图斑要素类 |
|
//gPParamClass.SecondFeatureLayer = GxTbLayer;//地类图斑更新要素类 |
|
gPParamClass.OutFeatureClassPath = parm.PrjInfo.NMDatabase;// + "\\" + "DLTB_NMK";//要添加的要素类图层 |
|
gPParamClass.IsGetOutPutFeature = true;//是否获取GP工具生成后的图层 |
|
gPParamClass.GPType = EnumGPType.FcToFc; |
|
gPParamClass.FcName = "DLTB_NMK"; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref TempNMKLayer);//擦除/相减分析 |
|
|
|
_cursor = GxgcTBLayer.FeatureClass.Search(new QueryFilterClass() { SubFields = "BGQTBBSM" }, true); |
|
Dictionary<string, int> DicJcBSMs = new Dictionary<string, int>(); |
|
IFeature f = null; |
|
int idx = GxgcTBLayer.FeatureClass.FindField("BGQTBBSM"); |
|
if (idx == -1) return; |
|
while ((f = _cursor.NextFeature()) != null) |
|
{ |
|
string jcbsm = f.Value[idx].ToTrim(); |
|
if (!DicJcBSMs.ContainsKey(jcbsm)) |
|
DicJcBSMs.Add(jcbsm, 0); |
|
} |
|
_cursor = TempNMKLayer.FeatureClass.Update(null, true); |
|
idx = TempNMKLayer.FeatureClass.FindField("BSM"); |
|
if (idx == -1) return; |
|
while ((f = _cursor.NextFeature()) != null) |
|
{ |
|
string bsm = f.Value[idx].ToTrim(); |
|
if (DicJcBSMs.ContainsKey(bsm)) |
|
{ |
|
f.Value[idx] = "-1"; |
|
_cursor.UpdateFeature(f); |
|
} |
|
} |
|
_cursor.Flush(); |
|
(TempNMKLayer.FeatureClass as ITable).DeleteSearchedRows(new QueryFilterClass() { WhereClause = "BSM = '-1'" }); |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(GxTbLayer.FeatureClass); |
|
fcAPI.FcToFc(TempNMKLayer.FeatureClass, null, false); |
|
|
|
fcAPI = new FeatureClassAPI(TempNMKLayer.FeatureClass); |
|
fcAPI.AddField("XZQDM", esriFieldType.esriFieldTypeString, "行政区代码"); |
|
fcAPI.AddField("XZQTZLX", esriFieldType.esriFieldTypeInteger, "行政区调整类型"); |
|
////fcAPI.FcToFc(NMKLayer.FeatureClass, null, false); |
|
//fcAPI = new FeatureClassAPI(GxTbLayer.FeatureClass); |
|
//fcAPI.FcToFc(TempNMKLayer.FeatureClass, null, false); |
|
|
|
ITable nmkTable = TempNMKLayer.FeatureClass as ITable; |
|
//更新后年末库 |
|
ICursor nmkCur = nmkTable.Update(null, true); |
|
IRow nmkRow = null; |
|
int bsmIdx = nmkTable.FindField("BSM"); |
|
int zldwIdx = nmkTable.FindField("ZLDWDM"); |
|
int xzqdmIdx = nmkTable.FindField("XZQDM"); |
|
int XZQTZLXmIdx = nmkTable.FindField("XZQTZLX"); |
|
int HDMCIdx = nmkTable.FindField("HDMC"); |
|
while ((nmkRow = nmkCur.NextRow()) != null) |
|
{ |
|
//string bsm = nmkRow.Value[bsmIdx].ToTrim(); |
|
//if (hcbghbsm.Contains(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 2; |
|
//} |
|
//else if (msbghbsm.Contains(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 4; |
|
//} |
|
//else if (msbgqbsm.Contains(bsm) && !bghbsmDic.ContainsKey(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 4; |
|
//} |
|
//if (bhxxDic.ContainsKey(bsm)) |
|
//{ |
|
// for (int i = 0; i < nmkRow.Fields.FieldCount; i++) |
|
// { |
|
// IField field = nmkRow.Fields.Field[i]; |
|
// string bghField = "BGH" + field.Name; |
|
// DataRow dr = bhxxDic[bsm]; |
|
// if (!dr.Table.Columns.Contains(bghField)) |
|
// bghField = "BGHTB" + field.Name; |
|
// if (dr.Table.Columns.Contains(bghField)) |
|
// { |
|
// if (field.Type == esriFieldType.esriFieldTypeString) |
|
// { |
|
// nmkRow.Value[i] = msbghbsm.Contains(bsm) ? "" : dr[bghField]; |
|
// } |
|
// else if (field.Type == esriFieldType.esriFieldTypeDouble) |
|
// { |
|
// nmkRow.Value[i] = msbghbsm.Contains(bsm) ? 0 : dr[bghField].ToDouble(); |
|
// } |
|
// } |
|
// } |
|
//} |
|
if (zldwIdx != -1 && xzqdmIdx != -1) |
|
{ |
|
string zldwdm = nmkRow.Value[zldwIdx].ToTrim(); |
|
if (!string.IsNullOrWhiteSpace(zldwdm) && zldwdm.Length > 9) |
|
{ |
|
nmkRow.Value[xzqdmIdx] = zldwdm.Substring(0, 9); |
|
} |
|
} |
|
if (HDMCIdx != -1) |
|
nmkRow.Value[HDMCIdx] = nmkRow.Value[HDMCIdx].ToString().ToTrim() == "" ? "" : nmkRow.Value[HDMCIdx].ToString().ToTrim(); |
|
nmkCur.UpdateRow(nmkRow); |
|
} |
|
nmkCur.Flush(); |
|
//nmkTable.DeleteSearchedRows(new QueryFilterClass() { WhereClause = "XZQTZLX=4 or XZQTZLX=2" }); |
|
_nmTbLayer = TempNMKLayer; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 生成年末库数据(BUG:新增 年末库 图层) |
|
/// </summary> |
|
/// <param name="parm"></param> |
|
public virtual void CreateNMK(IDGParameter parm) |
|
{ |
|
IFeatureCursor _cursor = null; |
|
try |
|
{ |
|
//if (NmWsAPI.OpenFeatureClass("DLTB_NMK").FeatureClass is IFeatureClass ClassFC) |
|
// NmTbLayer = new FeatureLayer() { Name = ClassFC.AliasName, FeatureClass = ClassFC }; |
|
if (NmTbLayer == null) return; |
|
(NmTbLayer.FeatureClass as ITable).DeleteSearchedRows(null); |
|
IFeatureClassAPI featureClassAPI = new FeatureClassAPI(JcTbLayer.FeatureClass); |
|
featureClassAPI.FcToFc(NmTbLayer.FeatureClass, new QueryFilterClass() { WhereClause = " (XZQTZLX <> '2' and XZQTZLX <> '4') or XZQTZLX Is NULL " }, false); |
|
_cursor = GxgcTBLayer.FeatureClass.Search(new QueryFilterClass() { SubFields = "BGQTBBSM" }, true); |
|
Dictionary<string, int> DicJcBSMs = new Dictionary<string, int>(); |
|
IFeature f = null; |
|
int idx = GxgcTBLayer.FeatureClass.FindField("BGQTBBSM"); |
|
if (idx == -1) return; |
|
while ((f = _cursor.NextFeature()) != null) |
|
{ |
|
string jcbsm = f.Value[idx].ToTrim(); |
|
if (!DicJcBSMs.ContainsKey(jcbsm)) |
|
DicJcBSMs.Add(jcbsm, 0); |
|
} |
|
_cursor = NmTbLayer.FeatureClass.Update(null, true); |
|
idx = NmTbLayer.FeatureClass.FindField("BSM"); |
|
if (idx == -1) return; |
|
while ((f = _cursor.NextFeature()) != null) |
|
{ |
|
string bsm = f.Value[idx].ToTrim(); |
|
if (DicJcBSMs.ContainsKey(bsm)) |
|
{ |
|
f.Value[idx] = "-1"; |
|
_cursor.UpdateFeature(f); |
|
} |
|
} |
|
_cursor.Flush(); |
|
(NmTbLayer.FeatureClass as ITable).DeleteSearchedRows(new QueryFilterClass() { WhereClause = "BSM = '-1'" }); |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(GxTbLayer.FeatureClass); |
|
fcAPI.FcToFc(NmTbLayer.FeatureClass, null, false); |
|
|
|
ITable nmkTable = NmTbLayer.FeatureClass as ITable; |
|
//更新后年末库 |
|
ICursor nmkCur = nmkTable.Update(null, true); |
|
IRow nmkRow = null; |
|
int bsmIdx = nmkTable.FindField("BSM"); |
|
int zldwIdx = nmkTable.FindField("ZLDWDM"); |
|
int xzqdmIdx = nmkTable.FindField("XZQDM"); |
|
int XZQTZLXmIdx = nmkTable.FindField("XZQTZLX"); |
|
int HDMCIdx = nmkTable.FindField("HDMC"); |
|
while ((nmkRow = nmkCur.NextRow()) != null) |
|
{ |
|
if (zldwIdx != -1 && xzqdmIdx != -1) |
|
{ |
|
string zldwdm = nmkRow.Value[zldwIdx].ToTrim(); |
|
if (!string.IsNullOrWhiteSpace(zldwdm) && zldwdm.Length > 9) |
|
{ |
|
nmkRow.Value[xzqdmIdx] = zldwdm.Substring(0, 9); |
|
} |
|
} |
|
if (HDMCIdx != -1) |
|
nmkRow.Value[HDMCIdx] = nmkRow.Value[HDMCIdx].ToString().ToTrim() == "" ? "" : nmkRow.Value[HDMCIdx].ToString().ToTrim(); |
|
nmkCur.UpdateRow(nmkRow); |
|
} |
|
nmkCur.Flush(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine("Err:地类图斑数据提取-生成年末库数据异常!" + ex.Message); |
|
Console.WriteLine("Err:地类图斑数据提取-生成年末库数据异常!" + ex.StackTrace); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (_cursor != null) |
|
Marshal.ReleaseComObject(_cursor); |
|
} |
|
} |
|
|
|
public virtual void CreateNMK(DBLayerSourceHelper pLayerSource) |
|
{ |
|
IFeatureCursor _cursor = null; |
|
try |
|
{ |
|
//GeoprocessorHelper gpHelper = new GeoprocessorHelper(); |
|
//string path = Path.Combine(parm.PrjInfo.ProjDir, "NMDB" + ".gdb"); |
|
|
|
//FileInfo fileInfo = new FileInfo(parm.PrjInfo.BGDatabase); |
|
//string path = Path.Combine(fileInfo.DirectoryName, "NMDB" + ".gdb"); |
|
//if (JcTbLayer == null || GxTbLayer == null) |
|
// OpenDB(parm); |
|
IFeatureLayer TempNMKLayer = null; |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureLayer = pLayerSource.JcTbLayer;//基础地类图斑要素类 |
|
//gPParamClass.SecondFeatureLayer = GxTbLayer;//地类图斑更新要素类 |
|
gPParamClass.OutFeatureClassPath = pLayerSource.NmWsAPI.CurrentWorkspace.PathName;// + "\\" + "DLTB_NMK";//要添加的要素类图层 |
|
gPParamClass.IsGetOutPutFeature = true;//是否获取GP工具生成后的图层 |
|
gPParamClass.GPType = EnumGPType.FcToFc; |
|
gPParamClass.FcName = "DLTB_NMK"; |
|
GPHelper.Instance.ExeGPForProces(gPParamClass, ref TempNMKLayer);//擦除/相减分析 |
|
|
|
_cursor = pLayerSource.GxgcTBLayer.FeatureClass.Search(new QueryFilterClass() { SubFields = "BGQTBBSM" }, true); |
|
Dictionary<string, int> DicJcBSMs = new Dictionary<string, int>(); |
|
IFeature f = null; |
|
int idx = pLayerSource.GxgcTBLayer.FeatureClass.FindField("BGQTBBSM"); |
|
if (idx == -1) return; |
|
while ((f = _cursor.NextFeature()) != null) |
|
{ |
|
string jcbsm = f.Value[idx].ToTrim(); |
|
if (!DicJcBSMs.ContainsKey(jcbsm)) |
|
DicJcBSMs.Add(jcbsm, 0); |
|
} |
|
_cursor = TempNMKLayer.FeatureClass.Update(null, true); |
|
idx = TempNMKLayer.FeatureClass.FindField("BSM"); |
|
if (idx == -1) return; |
|
while ((f = _cursor.NextFeature()) != null) |
|
{ |
|
string bsm = f.Value[idx].ToTrim(); |
|
if (DicJcBSMs.ContainsKey(bsm)) |
|
{ |
|
f.Value[idx] = "-1"; |
|
_cursor.UpdateFeature(f); |
|
} |
|
} |
|
_cursor.Flush(); |
|
(TempNMKLayer.FeatureClass as ITable).DeleteSearchedRows(new QueryFilterClass() { WhereClause = "BSM = '-1'" }); |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(pLayerSource.GxTbLayer.FeatureClass); |
|
fcAPI.FcToFc(TempNMKLayer.FeatureClass, null, false); |
|
|
|
fcAPI = new FeatureClassAPI(TempNMKLayer.FeatureClass); |
|
fcAPI.AddField("XZQDM", esriFieldType.esriFieldTypeString, "行政区代码"); |
|
fcAPI.AddField("XZQTZLX", esriFieldType.esriFieldTypeInteger, "行政区调整类型"); |
|
////fcAPI.FcToFc(NMKLayer.FeatureClass, null, false); |
|
//fcAPI = new FeatureClassAPI(pLayerSource.GxTbLayer.FeatureClass); |
|
//fcAPI.FcToFc(TempNMKLayer.FeatureClass, null, false); |
|
|
|
ITable nmkTable = TempNMKLayer.FeatureClass as ITable; |
|
//更新后年末库 |
|
ICursor nmkCur = nmkTable.Update(null, true); |
|
IRow nmkRow = null; |
|
int bsmIdx = nmkTable.FindField("BSM"); |
|
int zldwIdx = nmkTable.FindField("ZLDWDM"); |
|
int xzqdmIdx = nmkTable.FindField("XZQDM"); |
|
int XZQTZLXmIdx = nmkTable.FindField("XZQTZLX"); |
|
int HDMCIdx = nmkTable.FindField("HDMC"); |
|
while ((nmkRow = nmkCur.NextRow()) != null) |
|
{ |
|
//string bsm = nmkRow.Value[bsmIdx].ToTrim(); |
|
//if (hcbghbsm.Contains(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 2; |
|
//} |
|
//else if (msbghbsm.Contains(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 4; |
|
//} |
|
//else if (msbgqbsm.Contains(bsm) && !bghbsmDic.ContainsKey(bsm)) |
|
//{ |
|
// nmkRow.Value[XZQTZLXmIdx] = 4; |
|
//} |
|
//if (bhxxDic.ContainsKey(bsm)) |
|
//{ |
|
// for (int i = 0; i < nmkRow.Fields.FieldCount; i++) |
|
// { |
|
// IField field = nmkRow.Fields.Field[i]; |
|
// string bghField = "BGH" + field.Name; |
|
// DataRow dr = bhxxDic[bsm]; |
|
// if (!dr.Table.Columns.Contains(bghField)) |
|
// bghField = "BGHTB" + field.Name; |
|
// if (dr.Table.Columns.Contains(bghField)) |
|
// { |
|
// if (field.Type == esriFieldType.esriFieldTypeString) |
|
// { |
|
// nmkRow.Value[i] = msbghbsm.Contains(bsm) ? "" : dr[bghField]; |
|
// } |
|
// else if (field.Type == esriFieldType.esriFieldTypeDouble) |
|
// { |
|
// nmkRow.Value[i] = msbghbsm.Contains(bsm) ? 0 : dr[bghField].ToDouble(); |
|
// } |
|
// } |
|
// } |
|
//} |
|
if (zldwIdx != -1 && xzqdmIdx != -1) |
|
{ |
|
string zldwdm = nmkRow.Value[zldwIdx].ToTrim(); |
|
if (!string.IsNullOrWhiteSpace(zldwdm) && zldwdm.Length > 9) |
|
{ |
|
nmkRow.Value[xzqdmIdx] = zldwdm.Substring(0, 9); |
|
} |
|
} |
|
if (HDMCIdx != -1) |
|
nmkRow.Value[HDMCIdx] = nmkRow.Value[HDMCIdx].ToString().ToTrim() == "" ? "" : nmkRow.Value[HDMCIdx].ToString().ToTrim(); |
|
nmkCur.UpdateRow(nmkRow); |
|
} |
|
nmkCur.Flush(); |
|
//nmkTable.DeleteSearchedRows(new QueryFilterClass() { WhereClause = "XZQTZLX=4 or XZQTZLX=2" }); |
|
_nmTbLayer = TempNMKLayer; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
internal IFeatureLayer OpenLayer(LayerCfg pLayerInfo) |
|
{ |
|
try |
|
{ |
|
if (pLayerInfo == null) |
|
return null; |
|
if (string.IsNullOrWhiteSpace(pLayerInfo.FcPath) || string.IsNullOrWhiteSpace(pLayerInfo.FcName)) |
|
return null; |
|
if (!File.Exists(pLayerInfo.FcPath) && !Directory.Exists(pLayerInfo.FcPath)) |
|
return null; |
|
FileInfo fInfo = new FileInfo(pLayerInfo.FcPath); |
|
WorkspaceTypeEnum wsType = WorkspaceTypeEnum.GDBFile; |
|
if (fInfo.FullName.EndsWith(".gdb")) |
|
wsType = WorkspaceTypeEnum.GDBFile; |
|
else if (fInfo.FullName.EndsWith(".mdb")) |
|
wsType = WorkspaceTypeEnum.MDBFile; |
|
else |
|
wsType = WorkspaceTypeEnum.ShapeFile; |
|
if (DicWsAPI == null) |
|
DicWsAPI = new Dictionary<string, IWorkspaceAPI>(); |
|
if (!DicWsAPI.ContainsKey(fInfo.FullName)) |
|
{ |
|
IWorkspaceAPI wsAPI = null; |
|
if (wsType == WorkspaceTypeEnum.GDBFile) |
|
wsAPI = new WorkspaceAPI(fInfo.FullName, wsType, true); |
|
else |
|
wsAPI = new WorkspaceAPI(fInfo.FullName, wsType); |
|
DicWsAPI.Add(fInfo.FullName, wsAPI); |
|
} |
|
IFeatureClassAPI fcAPI = DicWsAPI[fInfo.FullName].OpenFeatureClass(pLayerInfo.FcName); |
|
return new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = fcAPI.FeatureClass.AliasName }; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message + ex.StackTrace); |
|
throw ex; |
|
} |
|
|
|
} |
|
internal IFeatureLayer OpenLayer(IWorkspaceAPI pWsAPI, string pLayerName) |
|
{ |
|
try |
|
{ |
|
if (string.IsNullOrWhiteSpace(pLayerName)) |
|
return null; |
|
if (pWsAPI != null && pWsAPI.CurrentWorkspace != null) |
|
{ |
|
IFeatureClassAPI fcAPI = pWsAPI.OpenFeatureClass(pLayerName); |
|
return new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = fcAPI.FeatureClass.AliasName }; |
|
} |
|
return null; |
|
} |
|
catch (Exception) |
|
{ |
|
Console.WriteLine(string.Format("Err:{0}图层获取失败", pLayerName)); |
|
return null; |
|
} |
|
} |
|
|
|
public string GetTime(DateTime timeA) |
|
{ |
|
//timeA 表示需要计算 |
|
DateTime timeB = DateTime.Now; //获取当前时间 |
|
TimeSpan ts = timeB - timeA; //计算时间差 |
|
//string time = ts.TotalSeconds.ToString(); //将时间差转换为秒 |
|
|
|
string str = ""; |
|
if (ts.Hours > 0) |
|
{ |
|
str = String.Format("{0:00}", ts.Hours) + ":" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds); |
|
} |
|
if (ts.Hours == 0 && ts.Minutes > 0) |
|
{ |
|
str = "00:" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds); |
|
} |
|
if (ts.Hours == 0 && ts.Minutes == 0) |
|
{ |
|
str = "00:00:" + String.Format("{0:00}", ts.Seconds); |
|
} |
|
return str; |
|
} |
|
|
|
private bool disposed = false; |
|
public void Dispose() |
|
{ |
|
Dispose(true); |
|
GC.SuppressFinalize(this); |
|
} |
|
|
|
protected virtual void Dispose(bool disposing) |
|
{ |
|
if (!disposed) |
|
{ |
|
if (disposing) |
|
{ |
|
// 释放其他托管资源(如数据库连接等) |
|
} |
|
// 释放非托管资源 |
|
#region 释放数据库链接 |
|
ZlWsAPI?.CloseWorkspace(); |
|
JCWsAPI?.CloseWorkspace(); |
|
NmWsAPI?.CloseWorkspace(); |
|
#endregion |
|
|
|
if (_jcCzcLayer != null) |
|
Marshal.ReleaseComObject(_jcCzcLayer); |
|
_jcCzcLayer = null; |
|
|
|
disposed = true; |
|
} |
|
} |
|
} |
|
|
|
public class DBLayerSourceHelper |
|
{ |
|
public Dictionary<string, IWorkspaceAPI> DicWsAPI { get; set; } |
|
public IWorkspaceAPI BgWsAPI { get; set; } |
|
public IWorkspaceAPI ZlWsAPI { get; set; } |
|
public IWorkspaceAPI NmWsAPI { get; set; } |
|
//public IFeatureLayer JCLayer { get => jCLayer; set => jCLayer = value; } |
|
//public IFeatureLayer GXLayer { get => gXLayer; set => gXLayer = value; } |
|
public IFeatureLayer NmTbLayer { get; set; } |
|
#region 地类图斑 |
|
public IFeatureLayer JcTbLayer { get; set; } |
|
public IFeatureLayer JcPdtLayer { get; set; } |
|
public IFeatureLayer GxgcTBLayer { get; set; } |
|
public IFeatureLayer GxTbLayer { get; set; } |
|
public IFeatureLayer GxPdtLayer { get; set; } |
|
public IFeatureLayer BgTbLayer { get; set; } |
|
#endregion |
|
|
|
#region 村级调查区 |
|
public IFeatureLayer JcCjdcqLayer { get; set; } |
|
public IFeatureLayer JcCjdcqJxLayer { get; set; } |
|
public IFeatureLayer GxCjdcqLayer { get; set; } |
|
public IFeatureLayer GxgcCjdcqLayer { get; set; } |
|
public IFeatureLayer GxCjdcqJxLayer { get; set; } |
|
#endregion |
|
|
|
#region 行政区 |
|
public IFeatureLayer JcXzqLayer { get; set; } |
|
public IFeatureLayer JcXzqJxLayer { get; set; } |
|
public IFeatureLayer GxXzqLayer { get; set; } |
|
public IFeatureLayer GxgcXzqLayer { get; set; } |
|
public IFeatureLayer GxXzqJxLayer { get; set; } |
|
#endregion |
|
|
|
#region 城镇村 |
|
public IFeatureLayer JcCzcLayer { get; set; } |
|
public IFeatureLayer GxCzcLayer { get; set; } |
|
public IFeatureLayer GxgcCzcLayer { get; set; } |
|
#endregion |
|
|
|
#region 耕地等别 |
|
public IFeatureLayer JcGddbLayer { get; set; } |
|
public IFeatureLayer GxGddbLayer { get; set; } |
|
#endregion |
|
|
|
public IFeatureLayer OpenLayer(LayerCfg pLayerInfo) |
|
{ |
|
if (pLayerInfo == null) |
|
return null; |
|
if (string.IsNullOrWhiteSpace(pLayerInfo.FcPath) || string.IsNullOrWhiteSpace(pLayerInfo.FcName)) |
|
return null; |
|
if (!File.Exists(pLayerInfo.FcPath) && !Directory.Exists(pLayerInfo.FcPath)) |
|
return null; |
|
FileInfo fInfo = new FileInfo(pLayerInfo.FcPath); |
|
WorkspaceTypeEnum wsType = WorkspaceTypeEnum.GDBFile; |
|
if (fInfo.FullName.EndsWith(".gdb")) |
|
wsType = WorkspaceTypeEnum.GDBFile; |
|
else if (fInfo.FullName.EndsWith(".mdb")) |
|
wsType = WorkspaceTypeEnum.MDBFile; |
|
else |
|
wsType = WorkspaceTypeEnum.ShapeFile; |
|
if (DicWsAPI == null) |
|
DicWsAPI = new Dictionary<string, IWorkspaceAPI>(); |
|
if (!DicWsAPI.ContainsKey(fInfo.FullName)) |
|
{ |
|
IWorkspaceAPI wsAPI = new WorkspaceAPI(fInfo.FullName, wsType); |
|
DicWsAPI.Add(fInfo.FullName, wsAPI); |
|
} |
|
IFeatureClassAPI fcAPI = DicWsAPI[fInfo.FullName].OpenFeatureClass(pLayerInfo.FcName); |
|
return new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = fcAPI.FeatureClass.AliasName }; |
|
} |
|
public IFeatureLayer OpenLayer(IWorkspaceAPI pWsAPI, string pLayerName) |
|
{ |
|
try |
|
{ |
|
if (string.IsNullOrWhiteSpace(pLayerName)) |
|
return null; |
|
if (pWsAPI != null && pWsAPI.CurrentWorkspace != null) |
|
{ |
|
IFeatureClassAPI fcAPI = pWsAPI.OpenFeatureClass(pLayerName); |
|
return new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass, Name = fcAPI.FeatureClass.AliasName }; |
|
} |
|
return null; |
|
} |
|
catch (Exception ex) |
|
{ |
|
Console.WriteLine(string.Format("Err:{0}图层获取失败", pLayerName)); |
|
return null; |
|
} |
|
} |
|
} |
|
}
|
|
|