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.
1202 lines
57 KiB
1202 lines
57 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.GPHelper; |
|
using KGIS.Framework.AE.ExtensionMethod; |
|
using KGIS.Framework.DBOperator; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Platform.Helper; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Runtime.InteropServices; |
|
|
|
namespace Kingo.Plugin.LocationChange |
|
{ |
|
public class BGHelper |
|
{ |
|
public static void GenerateGxgcData() |
|
{ |
|
Geoprocessor gp = null; |
|
IWorkspaceFactory pFtWsFct = null; |
|
IWorkspaceName workspaceName = null; |
|
try |
|
{ |
|
ProgressHelper.ShowProcessBar("正在生成更新过程数据……"); |
|
IMapService _MapService = MapsManager.Instance.MapService; |
|
gp = new Geoprocessor() |
|
{ |
|
OverwriteOutput = true |
|
}; |
|
IGpValueTableObject gpValueTableObject = new GpValueTableObjectClass();//对两个要素类进行相交运算 |
|
gpValueTableObject.SetColumns(2); |
|
|
|
string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\GXGC"; |
|
if (!Directory.Exists(gdbFolder)) |
|
{ |
|
Directory.CreateDirectory(gdbFolder); |
|
} |
|
try |
|
{ |
|
DelectDir(gdbFolder);//能删除就删除 删除报错不处理 |
|
} |
|
catch |
|
{ } |
|
|
|
pFtWsFct = new FileGDBWorkspaceFactory(); |
|
|
|
string gdbFileName = Guid.NewGuid().ToString() + ".gdb"; |
|
string path = System.IO.Path.Combine(gdbFolder, gdbFileName); |
|
|
|
workspaceName = pFtWsFct.Create(gdbFolder, gdbFileName, null, 0); |
|
|
|
object o1 = _MapService.GetFeatureClassByName("JC_DLTB"); |
|
|
|
IFeatureLayer pdltbFeatureLayer = null; |
|
GPParamClass gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureClass = o1 as IFeatureClass; |
|
gPParamClass.OutFeatureClassPath = path; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.FeatureClassToFeatureClass(gPParamClass, "JC_DLTB", ref pdltbFeatureLayer); |
|
IFeatureClass jcFc2 = _MapService.GetFeatureClassByName("XZQTZQJCTB"); |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(jcFc2); |
|
fcAPI.FcToFc(pdltbFeatureLayer.FeatureClass, null, false); |
|
|
|
o1 = pdltbFeatureLayer.FeatureClass; |
|
object o2 = _MapService.GetFeatureClassByName("DLTBGX"); |
|
|
|
IFeatureClass bgtbFc = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBBG");//PrjDB.gdb基础库 |
|
IFeatureLayer bgtb_Layer = GeoDBAPI.CreateFeatureLayerInmemeory("DLTBGX201", "地类图斑更新201数据", (bgtbFc as IGeoDataset).SpatialReference, bgtbFc.ShapeType, bgtbFc.Fields); |
|
InsertDataToMemeoryLayer(bgtbFc, bgtb_Layer.FeatureClass, new QueryFilterClass() { WhereClause = "XZQTZLX='1' or XZQTZLX='2' or XZQTZLX='3' or XZQTZLX='4'" }); |
|
|
|
object o3 = bgtb_Layer.FeatureClass; |
|
gpValueTableObject.AddRow(ref o1); |
|
gpValueTableObject.AddRow(ref o2); |
|
|
|
Intersect process = new Intersect(); |
|
process.in_features = gpValueTableObject; |
|
process.out_feature_class = path + "\\" + "TempDLTBGXGC2"; |
|
process.join_attributes = "ALL"; |
|
IGeoProcessorResult tGeoResult = (IGeoProcessorResult)gp.Execute(process, null); |
|
if (tGeoResult == null || tGeoResult.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) |
|
{ |
|
string msg = ReturnMessages(gp); |
|
throw new Exception(msg); |
|
} |
|
IFeatureClass outFc = GetOutPutFeatureClass(tGeoResult); |
|
|
|
IFeatureLayer pjbntFeatureLayer = null; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureClass = outFc; |
|
gPParamClass.SecondFeatureClass = bgtb_Layer.FeatureClass; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "TempDLTBGXGC"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.UnionAnalysis(gPParamClass, ref pjbntFeatureLayer); |
|
outFc = pjbntFeatureLayer.FeatureClass; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureClass = outFc; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "TempGXGC_MToS"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.MultipartToSinglePath(gPParamClass, ref pjbntFeatureLayer); |
|
outFc = pjbntFeatureLayer.FeatureClass; |
|
ProgressHelper.CloseProcessBar(); |
|
|
|
Dictionary<int, BGHAttributeModel> bghAttr = new Dictionary<int, BGHAttributeModel>(); |
|
Dictionary<int, GXAttributeModel> gxAttr = new Dictionary<int, GXAttributeModel>(); |
|
|
|
ProgressHelper.ShowProcessBar("正在进行属性赋值……"); |
|
SetAttribue(outFc, ref bghAttr, ref gxAttr); |
|
ProgressHelper.CloseProcessBar(); |
|
|
|
IFeatureClass hrFc = _MapService.GetFeatureClassByName("DLTBHR"); |
|
ITable dltbhrTb = hrFc as ITable; |
|
dltbhrTb.DeleteSearchedRows(null); |
|
IFeatureClass gxgcFc = _MapService.GetFeatureClassByName("DLTBGXGC"); |
|
ITable dltbgxgcTb = gxgcFc as ITable; |
|
dltbgxgcTb.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", "")); |
|
if (sIndex == -1) |
|
sIndex = outFc.FindField(field.Name.Replace("BGQTB", "")); |
|
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", "") + "_1"); |
|
if (sIndex == -1) |
|
sIndex = outFc.FindField(field.Name.Replace("BGHTB", "") + "_1"); |
|
if (sIndex != -1) |
|
{ |
|
target_SourMaping.Add(i, sIndex); |
|
fieldValues.Add(field.Name, sIndex); |
|
} |
|
continue; |
|
} |
|
else if (field.Name == "TBBGMJ") |
|
{ |
|
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 hrCursor = hrFc.Insert(true); |
|
IFeatureCursor t_cursor = gxgcFc.Insert(true); |
|
IFeatureCursor s_cursor = outFc.Search(null, true); |
|
IFeature s = null; |
|
int kdIndex = gxgcFc.FindField("BGHXZDWKD"); |
|
int gxsjIndex = gxgcFc.FindField("GXSJ"); |
|
int bghTBBSMIndex = gxgcFc.FindField("BGHTBBSM"); |
|
int bghTBBHIndex = gxgcFc.FindField("BGHTBBH"); |
|
int bgmjIndex = gxgcFc.FindField("TBBGMJ"); |
|
int bgxwIndex = gxgcFc.FindField("BGXW"); |
|
int xzqtzlxIndex = gxgcFc.FindField("XZQTZLX"); |
|
int bgqkcxsIdx = gxgcFc.FindField("BGQKCXS"); |
|
int bgqkcmjIdx = gxgcFc.FindField("BGQKCMJ"); |
|
int bgqtbdlmjIdx = gxgcFc.FindField("BGQTBDLMJ"); |
|
int bghkcxsIdx = gxgcFc.FindField("BGHKCXS"); |
|
int bghkcmjIdx = gxgcFc.FindField("BGHKCMJ"); |
|
int bghtbdlmjIdx = gxgcFc.FindField("BGHTBDLMJ"); |
|
|
|
ProgressHelper.ShowProcessBar("正在写入数据……"); |
|
int count = outFc.FeatureCount(null); |
|
double curr = 0; |
|
IQueryFilter delFilter = new QueryFilterClass() { WhereClause = "1=2" }; |
|
//创建地类图斑变化信息表 |
|
string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite"; |
|
IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite); ; |
|
if (!rdbHelper.TableIsExist("BHXXB")) |
|
{ |
|
rdbHelper.ExecuteSQL(" Create TABLE BHXXB ( BGQTBBSM text(100),BGHTBBSM text(100),BGQTBBH text(100),BGHTBBH text(100),BGQZLDWDM text(100),BGHZLDWDM text(100)," + |
|
"BGQZLDWMC text(100),BGHZLDWMC text(100),BGQQSDWDM text(100),BGHQSDWDM text(100),BGQQSDWMC text(100),BGHQSDWMC text(100),BGQQSXZ text(100),BGHQSXZ text(100)," + |
|
"BGQDLBM text(100),BGHDLBM text(100),BGQKCDLBM text(100),BGHKCDLBM text(100),BGQKCXS text(100),BGHKCXS text(100),BGQKCMJ NUMERIC,BGHKCMJ NUMERIC,BGQGDLX text(100),BGHGDLX text(100),BGQGDPDJB text(100),BGHGDPDJB text(100),BGQCZCSXM text(100),BGHCZCSXM text(100)," + |
|
"BGQTBXHDM text(100),BGHTBXHDM text(100),BGQZZSXDM text(100),BGHZZSXDM text(100),BGQMSSM text(100),BGHMSSM text(100),BGQGDDB text(100),BGHGDDB text(100)," + |
|
"BGMJ NUMERIC,XZQTZLX text(100),BZ text(10),BGXW text(10) ) "); |
|
} |
|
else |
|
{ |
|
rdbHelper.ExecuteSQL(" delete from BHXXB where BZ='TBBG'"); |
|
} |
|
string bhxxbField = "BGQTBBSM,BGHTBBSM,BGQTBBH,BGHTBBH,BGQZLDWDM,BGHZLDWDM,BGQZLDWMC,BGHZLDWMC,BGQQSDWDM,BGHQSDWDM,BGQQSDWMC,BGHQSDWMC,BGQQSXZ,BGHQSXZ,BGQDLBM,BGHDLBM,BGQKCDLBM,BGHKCDLBM,BGQKCXS,BGHKCXS,BGQKCMJ,BGHKCMJ,BGQGDLX,BGHGDLX,BGQGDPDJB,BGHGDPDJB,BGQCZCSXM,BGHCZCSXM,BGQTBXHDM,BGHTBXHDM,BGQZZSXDM,BGHZZSXDM,BGQMSSM,BGHMSSM,BGQGDDB,BGHGDDB,BGMJ,XZQTZLX,BZ,BGXW"; |
|
List<string> strSQL = new List<string>(); |
|
int bgqbsm = outFc.FindField("BSM"); |
|
List<string> delBGHBSM = new List<string>(); |
|
while ((s = s_cursor.NextFeature()) != null) |
|
{ |
|
curr++; |
|
if (curr % (count / 100) == 0) |
|
ProgressHelper.Message = string.Format("正在写入数据……{0}", ((curr / count) * 100).ToDouble(0) + "%"); |
|
string[] bhxxbfieldArr = bhxxbField.Split(','); |
|
string bhxxbValue = string.Empty; |
|
foreach (var item in bhxxbfieldArr) |
|
{ |
|
if (bghAttr.ContainsKey(s.OID)) |
|
{ |
|
if (item == "BGHTBBSM") |
|
{ |
|
if (bghAttr.ContainsKey(s.OID) && bghAttr[s.OID].XZQTZLX != "4") |
|
bhxxbValue += string.Format("'{0}',", bghAttr[s.OID].BGHTBBSM); |
|
else |
|
bhxxbValue += "'',"; |
|
continue; |
|
} |
|
if (item == "BGHTBBH") |
|
{ |
|
if (bghAttr.ContainsKey(s.OID) && bghAttr[s.OID].XZQTZLX != "4") |
|
bhxxbValue += string.Format("'{0}',", bghAttr[s.OID].BGHTBBH); |
|
else |
|
bhxxbValue += "'',"; |
|
continue; |
|
} |
|
if (item == "BGMJ") |
|
{ |
|
if (bghAttr.ContainsKey(s.OID)) |
|
bhxxbValue += string.Format("{0},", bghAttr[s.OID].BGMJ); |
|
else |
|
bhxxbValue += "0,"; |
|
continue; |
|
} |
|
if (item == "XZQTZLX") |
|
{ |
|
if (bghAttr.ContainsKey(s.OID)) |
|
{ |
|
bhxxbValue += string.Format("'{0}',", bghAttr[s.OID].XZQTZLX); |
|
} |
|
else |
|
{ |
|
bhxxbValue += string.Format("'{0}',", 0); |
|
} |
|
continue; |
|
} |
|
if (item == "BGXW") |
|
{ |
|
if (bghAttr[s.OID].XZQTZLX == "4") |
|
{ |
|
bhxxbValue += "'0',"; |
|
continue; |
|
} |
|
if (bghAttr.ContainsKey(s.OID)) |
|
bhxxbValue += string.Format("'{0}',", bghAttr[s.OID].BGXW); |
|
else |
|
bhxxbValue += "'',"; |
|
continue; |
|
} |
|
} |
|
if (item == "BZ") |
|
{ |
|
bhxxbValue += string.Format("'{0}',", "TBBG"); |
|
continue; |
|
} |
|
if (fieldValues.ContainsKey(item)) |
|
{ |
|
if (item == "BGQKCMJ") |
|
{ |
|
double bgq_kcxs = s.Value[fieldValues["BGQKCXS"].ToInt()].ToDouble(); |
|
if (bghAttr.ContainsKey(s.OID) && bghAttr[s.OID].XZQTZLX != "3") |
|
bhxxbValue += string.Format("{0},", (bghAttr[s.OID].BGMJ * bgq_kcxs).ToDecimal(2)); |
|
else |
|
bhxxbValue += "0,"; |
|
} |
|
else if (item == "BGHKCMJ") |
|
{ |
|
double bgh_kcxs = s.Value[fieldValues["BGHKCXS"].ToInt()].ToDouble(); |
|
if (bghAttr.ContainsKey(s.OID) && bghAttr[s.OID].XZQTZLX != "4" && bghAttr[s.OID].XZQTZLX != "2") |
|
bhxxbValue += string.Format("{0},", (bghAttr[s.OID].BGMJ * bgh_kcxs).ToDecimal(2)); |
|
else |
|
bhxxbValue += "0,"; |
|
} |
|
else if (item.StartsWith("BGQ") && bghAttr[s.OID].XZQTZLX == "3") |
|
{ |
|
bhxxbValue += "'',"; |
|
continue; |
|
} |
|
else |
|
{ |
|
if (bghAttr[s.OID].XZQTZLX == "4" && item.StartsWith("BGH")) |
|
{ |
|
bhxxbValue += "'',"; |
|
} |
|
else |
|
{ |
|
bhxxbValue += string.Format("'{0}',", s.Value[fieldValues[item].ToInt()]); |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
bhxxbValue += string.Format("'{0}',", ""); |
|
} |
|
} |
|
bhxxbValue = bhxxbValue.TrimEnd(','); |
|
string strSQLTemp = string.Format("Insert into BHXXB ({0}) values ({1})", bhxxbField, bhxxbValue); |
|
//属性变更的,对比变更前、变更后属性是否一直 |
|
if (bghAttr.ContainsKey(s.OID)) |
|
{ |
|
string UnEqualAttr = string.Empty; |
|
if (bghAttr[s.OID].BGXW == "1" && BGQ_BGH_AttrEqual(s, ref UnEqualAttr) && bghAttr[s.OID].XZQTZLX != "3" && bghAttr[s.OID].XZQTZLX != "4") |
|
{ |
|
if (bghAttr[s.OID].XZQTZLX == "1") |
|
{ |
|
IFeatureBuffer hrBuff = hrFc.CreateFeatureBuffer(); |
|
hrBuff.Shape = s.ShapeCopy; |
|
for (int i = 0; i < hrBuff.Fields.FieldCount; i++) |
|
{ |
|
IField field = hrBuff.Fields.Field[i]; |
|
if (field.Name.ToUpper().Contains(hrFc.ShapeFieldName) || !field.Editable) continue; |
|
string strField = field.Name + "_1"; |
|
int sIndex = outFc.FindField(strField); |
|
if (sIndex == -1) continue; |
|
hrBuff.Value[i] = s.Value[sIndex]; |
|
} |
|
int bsmIndex2 = hrFc.FindField("BSM"); |
|
int tbbhIndex2 = hrFc.FindField("TBBH"); |
|
int tbmjIndex2 = hrFc.FindField("TBMJ"); |
|
int kcxsIndex2 = hrFc.FindField("KCXS"); |
|
int tbdlmjIndex2 = hrFc.FindField("TBDLMJ"); |
|
int kcmjIndex2 = hrFc.FindField("KCMJ"); |
|
|
|
if (bsmIndex2 != -1) |
|
hrBuff.Value[bsmIndex2] = bghAttr[s.OID].BGHTBBSM; |
|
if (tbbhIndex2 != -1) |
|
hrBuff.Value[tbbhIndex2] = bghAttr[s.OID].BGHTBBH; |
|
if (tbmjIndex2 != -1) |
|
hrBuff.Value[tbmjIndex2] = bghAttr[s.OID].BGMJ; |
|
if (kcxsIndex2 != -1 && kcmjIndex2 != -1 && tbdlmjIndex2 != -1) |
|
{ |
|
double kcxs = hrBuff.Value[kcxsIndex2].ToDouble(); |
|
hrBuff.Value[kcmjIndex2] = (bghAttr[s.OID].BGMJ * kcxs).ToDecimal(2); |
|
hrBuff.Value[tbdlmjIndex2] = (bghAttr[s.OID].BGMJ - (bghAttr[s.OID].BGMJ * kcxs).ToDecimal(2).ToDouble()).ToDecimal(2); |
|
} |
|
hrCursor.InsertFeature(hrBuff); |
|
} |
|
if (!string.IsNullOrWhiteSpace(UnEqualAttr) || ("1,2,3,4".Contains(bghAttr[s.OID].XZQTZLX) && !string.IsNullOrWhiteSpace(bghAttr[s.OID].XZQTZLX))) |
|
{ |
|
//仅记录变更一览表,不记录更新层和过程层 |
|
strSQLTemp = strSQLTemp.Replace("TBBG", "ZLBG"); |
|
strSQL.Add(strSQLTemp); |
|
rdbHelper.ExecuteSQL(string.Format(" delete from BHXXB where BGQTBBSM='{0}' and BGHTBBSM='{0}'", bghAttr[s.OID].BGHTBBSM)); |
|
} |
|
else if (bghAttr[s.OID].XZQTZLX == "4") |
|
{ |
|
} |
|
delFilter.WhereClause = string.Format("OBJECTID = {0}", bghAttr[s.OID].BGHOID); |
|
(o2 as ITable).DeleteSearchedRows(delFilter); |
|
continue; |
|
} |
|
else if (bghAttr[s.OID].XZQTZLX == "4" && bghAttr[s.OID].BGXW == "1") |
|
{ |
|
delFilter.WhereClause = string.Format("OBJECTID = {0}", bghAttr[s.OID].BGHOID); |
|
(o2 as ITable).DeleteSearchedRows(delFilter); |
|
bghAttr[s.OID].BGXW = "0"; |
|
} |
|
if (bghAttr[s.OID].XZQTZLX == "3") |
|
{ |
|
bghAttr[s.OID].BGXW = "3"; |
|
} |
|
if (bghAttr[s.OID].XZQTZLX == "4") |
|
{ |
|
bghAttr[s.OID].BGXW = "0"; |
|
} |
|
} |
|
IArea area = s.ShapeCopy as IArea; |
|
strSQL.Add(strSQLTemp); |
|
IFeatureBuffer buf = gxgcFc.CreateFeatureBuffer(); |
|
foreach (var item in target_SourMaping) |
|
{ |
|
if (bghAttr.ContainsKey(s.OID)) |
|
{ |
|
if (bghAttr[s.OID].BGXW == "0") |
|
{ |
|
if (buf.Fields.Field[item.Key].Name.StartsWith("BGH")) |
|
continue; |
|
} |
|
else if (bghAttr[s.OID].XZQTZLX == "3") |
|
{ |
|
if (buf.Fields.Field[item.Key].Name.StartsWith("BGQ")) |
|
continue; |
|
} |
|
} |
|
buf.Value[item.Key] = s.Value[item.Value]; |
|
} |
|
|
|
if (kdIndex != -1) |
|
{ |
|
if (buf.Value[kdIndex] != DBNull.Value) |
|
buf.Value[kdIndex] = buf.Value[kdIndex].ToDouble(1); |
|
} |
|
if (gxsjIndex != -1) |
|
{ |
|
buf.Value[gxsjIndex] = new DateTime(DateTime.Now.Year - 1, 12, 31); |
|
} |
|
if (bghAttr.ContainsKey(s.OID)) |
|
{ |
|
double bghkcxs = buf.Value[bghkcxsIdx].ToDouble(); |
|
if (bghAttr[s.OID].BGXW == "0" || bghAttr[s.OID].XZQTZLX == "2" || bghAttr[s.OID].XZQTZLX == "4") |
|
{ |
|
buf.Value[bghkcmjIdx] = 0; |
|
buf.Value[bghtbdlmjIdx] = 0; |
|
if (!delBGHBSM.Contains(bghAttr[s.OID].BGHTBBSM)) |
|
delBGHBSM.Add(bghAttr[s.OID].BGHTBBSM); |
|
} |
|
else |
|
{ |
|
if (bghTBBSMIndex != -1) |
|
buf.Value[bghTBBSMIndex] = bghAttr[s.OID].BGHTBBSM; |
|
if (bghTBBHIndex != -1) |
|
buf.Value[bghTBBHIndex] = bghAttr[s.OID].BGHTBBH; |
|
buf.Value[bghkcmjIdx] = (bghAttr[s.OID].BGMJ * bghkcxs).ToDecimal(2); |
|
buf.Value[bghtbdlmjIdx] = (bghAttr[s.OID].BGMJ - buf.Value[bghkcmjIdx].ToDouble()).ToDecimal(2); |
|
} |
|
if (bgmjIndex != -1) |
|
buf.Value[bgmjIndex] = bghAttr[s.OID].BGMJ; |
|
if (bgxwIndex != -1) |
|
buf.Value[bgxwIndex] = bghAttr[s.OID].BGXW; |
|
if (xzqtzlxIndex != -1) |
|
{ |
|
buf.Value[xzqtzlxIndex] = string.IsNullOrWhiteSpace(bghAttr[s.OID].XZQTZLX) ? "0" : bghAttr[s.OID].XZQTZLX; |
|
} |
|
double bgqkcxs = buf.Value[bgqkcxsIdx].ToDouble(); |
|
if (bghAttr[s.OID].XZQTZLX == "3") |
|
{ |
|
buf.Value[bgqkcxsIdx] = 0; |
|
buf.Value[bgqkcmjIdx] = 0; |
|
buf.Value[bgqtbdlmjIdx] = 0; |
|
} |
|
else |
|
{ |
|
buf.Value[bgqkcmjIdx] = (bghAttr[s.OID].BGMJ * bgqkcxs).ToDecimal(2); |
|
buf.Value[bgqtbdlmjIdx] = (bghAttr[s.OID].BGMJ - buf.Value[bgqkcmjIdx].ToDouble()).ToDecimal(2); |
|
} |
|
} |
|
buf.Shape = s.ShapeCopy; |
|
object o = t_cursor.InsertFeature(buf); |
|
} |
|
rdbHelper.BeginTransaction(); |
|
count = strSQL.Count; |
|
curr = 0; |
|
foreach (var item in strSQL) |
|
{ |
|
curr++; |
|
if (curr % (count / 100) == 0) |
|
ProgressHelper.Message = string.Format("正在写入图斑变化信息……{0}", ((curr / count) * 100).ToDouble(0) + "%"); |
|
rdbHelper.ExecuteSQL(item); |
|
} |
|
rdbHelper.Commit(); |
|
rdbHelper.DisConnect(); |
|
t_cursor.Flush(); |
|
hrCursor.Flush(); |
|
ProgressHelper.CloseProcessBar(); |
|
ICursor cursor = (o2 as ITable).Update(null, true); |
|
IRow row = null; |
|
int bsmIndex = (o2 as ITable).FindField("BSM"); |
|
int tbbhIndex = (o2 as ITable).FindField("TBBH"); |
|
int tbmjIndex = (o2 as ITable).FindField("TBMJ"); |
|
int kcxsIndex = (o2 as ITable).FindField("KCXS"); |
|
int tbdlmjIndex = (o2 as ITable).FindField("TBDLMJ"); |
|
int kcmjIndex = (o2 as ITable).FindField("KCMJ"); |
|
kdIndex = (o2 as ITable).FindField("XZDWKD"); |
|
while ((row = cursor.NextRow()) != null) |
|
{ |
|
if (gxAttr.ContainsKey(row.OID) && !delBGHBSM.Contains(gxAttr[row.OID].BSM)) |
|
{ |
|
if (kdIndex != -1) |
|
{ |
|
row.Value[kdIndex] = row.Value[kdIndex].ToDouble(1); |
|
} |
|
if (bsmIndex != -1) |
|
row.Value[bsmIndex] = gxAttr[row.OID].BSM; |
|
if (tbbhIndex != -1) |
|
row.Value[tbbhIndex] = gxAttr[row.OID].TBBH; |
|
if (tbmjIndex != -1) |
|
row.Value[tbmjIndex] = gxAttr[row.OID].TBMJ; |
|
if (kcxsIndex != -1 && kcmjIndex != -1 && tbdlmjIndex != -1) |
|
{ |
|
double kcxs = row.Value[kcxsIndex].ToDouble(); |
|
row.Value[kcmjIndex] = (gxAttr[row.OID].TBMJ * kcxs).ToDecimal(2); |
|
row.Value[tbdlmjIndex] = (gxAttr[row.OID].TBMJ - (gxAttr[row.OID].TBMJ * kcxs).ToDecimal(2).ToDouble()).ToDecimal(2); |
|
} |
|
cursor.UpdateRow(row); |
|
} |
|
else |
|
{ |
|
delFilter.WhereClause = string.Format("OBJECTID = {0}", row.OID); |
|
(o2 as ITable).DeleteSearchedRows(delFilter); |
|
} |
|
} |
|
cursor.Flush(); |
|
|
|
IFeatureLayer msTBLayer = GeoDBAPI.CreateFeatureLayerInmemeory("MSDLTB", "灭失图斑", (bgtbFc as IGeoDataset).SpatialReference, bgtbFc.ShapeType, bgtbFc.Fields); |
|
IQueryFilter filter2 = new QueryFilterClass(); |
|
filter2.WhereClause = " XZQTZLX='2' or XZQTZLX='4'"; |
|
(msTBLayer.FeatureClass as ITable).DeleteSearchedRows(null); |
|
InsertDataToMemeoryLayer(bgtbFc, msTBLayer.FeatureClass, filter2); |
|
|
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureClass = o2 as IFeatureClass; |
|
gPParamClass.SecondFeatureClass = msTBLayer.FeatureClass; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "TempDLTBGX2"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.EraseAnalysis(gPParamClass, ref pjbntFeatureLayer); |
|
|
|
IFeatureLayer TempDLTB_MToS = null; |
|
gPParamClass = new GPParamClass(); |
|
gPParamClass.FirstFeatureClass = pjbntFeatureLayer.FeatureClass; |
|
gPParamClass.OutFeatureClassPath = path + "\\" + "TempDLTBGX2_MToS"; |
|
gPParamClass.IsGetOutPutFeature = true; |
|
GeoprocessorHelper.MultipartToSinglePath(gPParamClass, ref TempDLTB_MToS); |
|
|
|
(o2 as ITable).DeleteSearchedRows(null); |
|
|
|
InsertDataToMemeoryLayer(TempDLTB_MToS.FeatureClass, o2 as IFeatureClass); |
|
|
|
IFeatureClass bgFc = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBBG"); |
|
(bgFc as FeatureClass).Workspace.ExecuteSQL("UPDATE DLTBBG SET BGZT = '已变更'"); |
|
IFeatureClass xzqtqFc = MapsManager.Instance.MapService.GetFeatureClassByName("XZQTQTB"); |
|
(xzqtqFc as FeatureClass).Workspace.ExecuteSQL("UPDATE XZQTQTB SET BGZT = '已变更'"); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("生成更新过程数据失败:"); |
|
LogAPI.Debug(ex); |
|
MessageHelper.ShowError("生成更新过程数据失败:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
ProgressHelper.CloseProcessBar(); |
|
} |
|
} |
|
|
|
private static void InsertDataToMemeoryLayer(IFeatureClass pSource, IFeatureClass pTarget, IQueryFilter pFilter = null) |
|
{ |
|
try |
|
{ |
|
if (pSource == null || pTarget == null) return; |
|
IFeatureClassAPI fcAPI = new FeatureClassAPI(pSource); |
|
if (pTarget != null) |
|
fcAPI.FcToFc(pTarget, pFilter, false); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取城镇村范围数据失败:"); |
|
LogAPI.Debug(ex); |
|
} |
|
} |
|
/// <summary> |
|
/// 获取GP任务执行信息 |
|
/// </summary> |
|
/// <param name="gp"></param> |
|
/// <returns></returns> |
|
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; |
|
} |
|
private static IFeatureClass GetOutPutFeatureClass(IGeoProcessorResult tGeoResult) |
|
{ |
|
IGPUtilities pGPUtilities = new GPUtilitiesClass(); |
|
IFeatureClass pFeatureClass = null; |
|
IQueryFilter pQueryFilter = null; |
|
try |
|
{ |
|
pGPUtilities.DecodeFeatureLayer(tGeoResult.GetOutput(0), out pFeatureClass, out pQueryFilter); |
|
return pFeatureClass; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw new Exception("获取生成图层异常:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
if (pQueryFilter != null) |
|
{ |
|
Marshal.ReleaseComObject(pQueryFilter); |
|
} |
|
} |
|
} |
|
public static void SetAttribue(IFeatureClass pGxgcFc, ref Dictionary<int, BGHAttributeModel> bghAttr, ref Dictionary<int, GXAttributeModel> gxAttr) |
|
{ |
|
try |
|
{ |
|
IMapService _MapService = MapsManager.Instance.MapService; |
|
IFeatureLayer gxLayer = _MapService.GetFeatureLayerByName("DLTBGX"); |
|
IFeatureClass jcFc = _MapService.GetFeatureClassByName("JC_DLTB"); |
|
IQueryFilter filter = new QueryFilterClass() { SubFields = "OBJECTID,FID_JC_DLTB,BSM,TBBH,TBMJ,FID_DLTBGX,ZLDWDM,ZLDWDM_1,XZQTZLX_1,SHAPE_AREA" }; |
|
IFeatureCursor cursor = pGxgcFc.Search(filter, true); |
|
IFeature fe = null; |
|
int jcOIDIndex = pGxgcFc.FindField("FID_JC_DLTB"); |
|
int jcTBMJIndex = pGxgcFc.FindField("TBMJ"); |
|
int jcBSMIndex = pGxgcFc.FindField("BSM"); |
|
int jcTBBHIndex = pGxgcFc.FindField("TBBH"); |
|
int gxOIDIndex = pGxgcFc.FindField("FID_DLTBGX"); |
|
int gxZLDWDMIndex = pGxgcFc.FindField("ZLDWDM_1"); |
|
int bgqZLDWDMIndex = pGxgcFc.FindField("ZLDWDM"); |
|
int gxXZQTZLXIndex = pGxgcFc.FindField("XZQTZLX_1"); |
|
int areaIndex = pGxgcFc.FindField("SHAPE_AREA"); |
|
List<OIDMapping> txbgOID = new List<OIDMapping>(); |
|
List<OIDMapping> list = new List<OIDMapping>(); |
|
string msg = "正在进行属性赋值({0})……{1}"; |
|
ProgressHelper.Message = string.Format(msg, 1, ""); |
|
int count = pGxgcFc.FeatureCount(null); |
|
double curr = 0; |
|
while ((fe = cursor.NextFeature()) != null) |
|
{ |
|
curr++; |
|
if (curr % (count / 100) == 0) |
|
ProgressHelper.Message = string.Format(msg, 1, ((curr / count) * 100).ToDouble(0) + "%"); |
|
int jcOID = (int)fe.Value[jcOIDIndex]; |
|
double tbmj = fe.Value[jcTBMJIndex].ToDouble(); |
|
double area = fe.Value[areaIndex].ToDouble(); |
|
OIDMapping oMaping = new OIDMapping(); |
|
int gxOID = (int)fe.Value[gxOIDIndex]; |
|
oMaping.gcOID = fe.OID; |
|
oMaping.bgqOID = jcOID; |
|
oMaping.bgqTBBSM = fe.Value[jcBSMIndex].ToTrim(); |
|
oMaping.bgqTBBH = fe.Value[jcTBBHIndex].ToTrim(); |
|
oMaping.bghTBBSM = oMaping.bgqTBBSM; |
|
oMaping.bghTBBH = oMaping.bgqTBBH; |
|
oMaping.bghOID = gxOID; |
|
oMaping.bghZLDWDM = fe.Value[gxZLDWDMIndex].ToTrim(); |
|
oMaping.bgqZLDWDM = fe.Value[bgqZLDWDMIndex].ToTrim(); |
|
oMaping.BGMJ = tbmj; |
|
oMaping.XZQTZLX = string.IsNullOrWhiteSpace(fe.Value[gxXZQTZLXIndex].ToTrim()) ? "0" : fe.Value[gxXZQTZLXIndex].ToTrim(); |
|
if (string.IsNullOrWhiteSpace(oMaping.bghZLDWDM)) |
|
{ |
|
LogAPI.Debug("存在变更后坐落单位代码为空的数据!请检查变更图斑的坐落单位代码字段是否存在错误数据"); |
|
} |
|
else |
|
{ |
|
if (!oMaping.bgqZLDWDM.StartsWith(oMaping.bghZLDWDM.Substring(0, 6))) |
|
oMaping.XZQTZLX = "5"; |
|
} |
|
list.Add(oMaping); |
|
} |
|
string MaxBSM = string.Empty; |
|
Dictionary<string, int> dicTBBH = new Dictionary<string, int>(); |
|
if (list.Count != 0 && list[0].XZQTZLX == "5") |
|
{ |
|
MaxBSM = list[0].bghZLDWDM.Substring(0, 6) + "2110" + 1.ToString().PadLeft(8, '0'); |
|
} |
|
else |
|
{ |
|
if (string.IsNullOrWhiteSpace(MaxBSM)) |
|
MaxBSM = GetNewBSM(new List<IFeatureClass>() { jcFc }); |
|
} |
|
if (dicTBBH.Count == 0) |
|
GetMaxTBBH(jcFc, ref dicTBBH); |
|
IEnumerable<IGrouping<int, OIDMapping>> groupbgq = list.GroupBy(g => g.bgqOID); |
|
count = groupbgq.Count(); |
|
curr = 0; |
|
foreach (var item in groupbgq) |
|
{ |
|
if (item.Key == 71477) |
|
{ |
|
} |
|
curr++; |
|
if (curr % (count / 100) == 0) |
|
ProgressHelper.Message = string.Format(msg, 2, ((curr / count) * 100).ToDouble(0) + "%"); |
|
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 = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).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 = o.bghZLDWDM; |
|
if (dicTBBH.ContainsKey(strZLDW)) |
|
{ |
|
dicTBBH[strZLDW] = dicTBBH[strZLDW] + 1; |
|
bghTBBH = dicTBBH[strZLDW].ToTrim(); |
|
} |
|
else//新增村 |
|
{ |
|
dicTBBH.Add(strZLDW, 1); |
|
bghTBBH = dicTBBH[strZLDW].ToTrim(); |
|
} |
|
o.IsTXBG = true; |
|
o.bghTBBSM = MaxBSM; |
|
o.bghTBBH = bghTBBH; |
|
o.IsSplit = true; |
|
IFeature gcF = pGxgcFc.GetFeature(o.gcOID); |
|
o.BGMJ = (gcF.ShapeCopy as IPolygon).GetEllipseArea(); |
|
Marshal.ReleaseComObject(gcF); |
|
}); |
|
tempList = tempList.OrderByDescending(o => o.BGMJ).ToList(); |
|
double mjc = (tempList.Sum(s => s.BGMJ).ToDouble(2) - kzmj).ToDouble(2); |
|
while (mjc != 0) |
|
{ |
|
int tpsm = (int)(Math.Abs(Math.Round(mjc, 2)) / 0.01); |
|
int e = tpsm / tempList.Count; |
|
int f = tpsm % tempList.Count; |
|
if (f != 0) |
|
{ |
|
double tpmj = (e + 1) * 0.01; |
|
for (int i = 0; i < f; i++) |
|
{ |
|
if (mjc < 0) |
|
tempList[i].BGMJ += tpmj; |
|
else |
|
tempList[i].BGMJ -= tpmj; |
|
} |
|
} |
|
if (e != 0) |
|
{ |
|
double tpmj = e * 0.01; |
|
for (int i = f; i < tempList.Count; i++) |
|
{ |
|
if (mjc < 0) |
|
tempList[i].BGMJ += tpmj; |
|
else |
|
tempList[i].BGMJ -= tpmj; |
|
} |
|
} |
|
mjc = (tempList.Sum(s => s.BGMJ).ToDouble(2) - kzmj).ToDouble(2); |
|
} |
|
} |
|
else if (tempList[0].XZQTZLX == "1" || tempList[0].XZQTZLX == "3" || tempList[0].XZQTZLX == "5") |
|
{ |
|
string bghBSM = string.Empty; |
|
string bsmPrefix = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + MaxBSM.Substring(6, 4); |
|
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9)); |
|
bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); |
|
MaxBSM = bghBSM; |
|
tempList[0].bghTBBSM = bghBSM; |
|
if (tempList[0].XZQTZLX != "5") |
|
{ |
|
string bghTBBH = string.Empty; |
|
string strZLDW = item.ToList()[0].bghZLDWDM; |
|
if (dicTBBH.ContainsKey(strZLDW)) |
|
{ |
|
dicTBBH[strZLDW] = dicTBBH[strZLDW] + 1; |
|
bghTBBH = dicTBBH[strZLDW].ToTrim(); |
|
} |
|
else |
|
{//新增村 |
|
dicTBBH.Add(strZLDW, 1); |
|
bghTBBH = dicTBBH[strZLDW].ToTrim(); |
|
} |
|
tempList[0].bghTBBH = bghTBBH; |
|
} |
|
} |
|
else if (tempList.Count == 1) |
|
{ |
|
//属性变更,坐落单位变化,重新赋值图斑编号 |
|
if (tempList[0].bghZLDWDM != tempList[0].bgqZLDWDM && tempList[0].IsTXBG == false) |
|
{ |
|
if (dicTBBH.ContainsKey(tempList[0].bghZLDWDM)) |
|
{ |
|
dicTBBH[tempList[0].bghZLDWDM] = dicTBBH[tempList[0].bghZLDWDM] + 1; |
|
tempList[0].bghTBBH = dicTBBH[tempList[0].bghZLDWDM].ToTrim(); |
|
} |
|
else//新增村 |
|
{ |
|
dicTBBH.Add(tempList[0].bghZLDWDM, 1); |
|
tempList[0].bghTBBH = dicTBBH[tempList[0].bghZLDWDM].ToTrim(); |
|
} |
|
} |
|
} |
|
} |
|
groupbgq = list.GroupBy(g => g.bghOID); |
|
count = groupbgq.Count(); |
|
curr = 0; |
|
foreach (var item in groupbgq) |
|
{ |
|
curr++; |
|
if (curr % (count / 100) == 0) |
|
ProgressHelper.Message = string.Format(msg, 3, ((curr / count) * 100).ToDouble(0) + "%"); |
|
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 = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).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; |
|
if (dicTBBH.Count == 0) |
|
GetMaxTBBH(jcFc, ref dicTBBH); |
|
if (dicTBBH.ContainsKey(strZLDW)) |
|
{ |
|
dicTBBH[strZLDW] = dicTBBH[strZLDW] + 1; |
|
bghTBBH = dicTBBH[strZLDW].ToTrim(); |
|
} |
|
else//新增村 |
|
{ |
|
dicTBBH.Add(strZLDW, 1); |
|
bghTBBH = dicTBBH[strZLDW].ToTrim(); |
|
} |
|
|
|
item.ToList().ForEach(o => |
|
{ |
|
o.IsTXBG = true; |
|
o.bghTBBSM = MaxBSM; |
|
o.bghTBBH = bghTBBH; |
|
}); |
|
} |
|
else if (tempList[0].XZQTZLX == "1" || tempList[0].XZQTZLX == "3" || tempList[0].XZQTZLX == "5") |
|
{ |
|
string bghBSM = string.Empty; |
|
string bsmPrefix = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + MaxBSM.Substring(6, 4); |
|
int MaxNum = Convert.ToInt32(MaxBSM.Substring(9)); |
|
bghBSM = bsmPrefix + (MaxNum + 1).ToString().PadLeft(8, '0'); |
|
MaxBSM = bghBSM; |
|
tempList[0].bghTBBSM = bghBSM; |
|
if (tempList[0].XZQTZLX != "5") |
|
{ |
|
string bghTBBH = string.Empty; |
|
string strZLDW = item.ToList()[0].bghZLDWDM; |
|
if (dicTBBH.ContainsKey(strZLDW)) |
|
{ |
|
dicTBBH[strZLDW] = dicTBBH[strZLDW] + 1; |
|
bghTBBH = dicTBBH[strZLDW].ToTrim(); |
|
} |
|
else//新增村 |
|
{ |
|
dicTBBH.Add(strZLDW, 1); |
|
bghTBBH = dicTBBH[strZLDW].ToTrim(); |
|
} |
|
tempList[0].bghTBBH = bghTBBH; |
|
} |
|
} |
|
} |
|
int idxBGQBSM = pGxgcFc.FindField("BSM"); |
|
int idxBGHBSM = pGxgcFc.FindField("BSM_1"); |
|
int idxBGQTBBH = pGxgcFc.FindField("TBBH"); |
|
int idxBGHTBBH = pGxgcFc.FindField("TBBH_1"); |
|
int idxBGHZLDW = pGxgcFc.FindField("ZLDWDM_1"); |
|
int idxTBMJ = pGxgcFc.FindField("TBMJ"); |
|
int idxGXBSM = gxLayer.FeatureClass.FindField("BSM"); |
|
List<IFeatureClass> fcList = new List<IFeatureClass>() { jcFc }; |
|
count = list.Count; |
|
curr = 0; |
|
foreach (var item in list) |
|
{ |
|
curr++; |
|
if (curr % (count / 100) == 0) |
|
ProgressHelper.Message = string.Format(msg, 4, ((curr / count) * 100).ToDouble(0) + "%"); |
|
if (!bghAttr.ContainsKey(item.gcOID)) |
|
{ |
|
bghAttr.Add(item.gcOID, new BGHAttributeModel() |
|
{ |
|
BGHOID = item.bghOID, |
|
BGHTBBH = item.bghTBBH, |
|
BGHTBBSM = item.bghTBBSM, |
|
BGMJ = item.BGMJ, |
|
BGXW = item.IsTXBG ? "2" : "1", |
|
XZQTZLX = item.XZQTZLX |
|
}); |
|
|
|
if (bghAttr[item.gcOID].XZQTZLX == "3") |
|
bghAttr[item.gcOID].BGXW = "3"; |
|
} |
|
else |
|
{ |
|
bghAttr[item.gcOID] = new BGHAttributeModel() |
|
{ |
|
BGHOID = item.bghOID, |
|
BGHTBBH = item.bghTBBH, |
|
BGHTBBSM = item.bghTBBSM, |
|
BGMJ = item.BGMJ, |
|
BGXW = item.IsTXBG ? "2" : "1", |
|
XZQTZLX = item.XZQTZLX |
|
}; |
|
if (bghAttr[item.gcOID].XZQTZLX == "3") |
|
bghAttr[item.gcOID].BGXW = "3"; |
|
|
|
} |
|
if (item.XZQTZLX == "4") |
|
continue; |
|
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; |
|
} |
|
} |
|
dtBHXXBTBBH.Clear(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("属性赋值失败:"); |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
dtBHXXBTBBH.Clear(); |
|
} |
|
} |
|
static System.Data.DataTable dtBHXXBTBBH = new System.Data.DataTable(); |
|
private static bool BGQ_BGH_AttrEqual(IFeature pf, ref string UnEqualAttr) |
|
{ |
|
bool result = true; |
|
for (int i = 0; i < pf.Fields.FieldCount; i++) |
|
{ |
|
IField field = pf.Fields.Field[i]; |
|
if ("BSM,TBBH,TBYBH,YSDM,BZ".Contains(field.Name.ToUpper()) || field.Name.ToUpper().Contains("MJ")) continue; |
|
int bghIdx = pf.Fields.FindField(field.Name.ToUpper() + "_1"); |
|
if (bghIdx == -1) continue; |
|
if ("BSM,TBBH,ZLDWDM,ZLDWMC,QSDWDM,QSDWMC".Contains(field.Name.ToUpper())) |
|
{ |
|
if (pf.Value[i].ToTrim() != pf.Value[bghIdx].ToTrim()) |
|
{ |
|
UnEqualAttr += field.Name.ToUpper() + ","; |
|
} |
|
continue; |
|
} |
|
if (!Equals(pf.Value[i].ToTrim(), pf.Value[bghIdx].ToTrim())) |
|
{ |
|
result = false; |
|
break; |
|
} |
|
} |
|
return result; |
|
} |
|
private new static bool Equals(object obj1, object obj2) |
|
{ |
|
if (obj1 == null || obj1 is DBNull) |
|
{ |
|
obj1 = ""; |
|
} |
|
if (obj2 == null || obj2 is DBNull) |
|
{ |
|
obj2 = ""; |
|
} |
|
if (obj2.ToString() == "0") |
|
obj2 = ""; |
|
if (obj1.ToString() == "0") |
|
obj1 = ""; |
|
if (obj1.ToTrim() == obj2.ToTrim()) |
|
{ |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
#region 获取最新图斑编号 |
|
//private static int GetNewTBBH(List<IFeatureClass> fc, string pZLDWDM) |
|
//{ |
|
// int result = 0; |
|
// foreach (var item in fc) |
|
// { |
|
// int maxTBBH = GetMaxTBBH(item, pZLDWDM); |
|
// //LogAPI.Debug(item.AliasName + "的 坐落单位代码(" + pZLDWDM + ") 当前的 最大图斑编号(TBBH): " + maxTBBH + " ;\r\n ");//验证专用日志 |
|
// if (result < maxTBBH) |
|
// result = maxTBBH; |
|
// } |
|
// result++; |
|
|
|
// return result; |
|
//} |
|
private static void GetMaxTBBH(IFeatureClass fc, ref Dictionary<string, int> 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), (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).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 static 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 = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE + "1210"; |
|
result = leftStr + xh.ToString().PadLeft(8, '0'); |
|
return result; |
|
} |
|
private static 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接口对象 |
|
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 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) |
|
{ |
|
throw; |
|
} |
|
} |
|
} |
|
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 bgqZLDWDM { 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; } |
|
} |
|
public class BGHAttributeModel |
|
{ |
|
public int BGHOID { get; set; } |
|
public string BGHTBBSM { 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; } |
|
} |
|
}
|
|
|