年度变更建库软件5.0版本
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.

341 lines
18 KiB

6 months ago
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using KGIS.Framework.AE;
using KGIS.Framework.Commands;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.Plugin.BGSetting.Views;
using Kingo.PluginServiceInterface;
using System;
using System.IO;
using KGIS.Framework.AE.ExtensionMethod;
using UIShell.OSGi;
using System.Collections.Generic;
using System.Linq;
using Kingo.Framework.LayerStyleConvert.XSDClass;
using Kingo.Framework.LayerStyleConvert.Common;
using KGIS.Framework.AE.Enum;
using ESRI.ArcGIS.Geodatabase;
namespace Kingo.Plugin.BGSetting.Commands
{
/// <summary>
/// 系统设置-功能点
/// </summary>
public class CmdCreateZLDB : BaseMenuCommand
{
private IDataCatalogService _DataCatalog = null;
/// <summary>
/// 编辑器
/// </summary>
private EngineEditorClass pEditor = null;
private IHookHelper hookHelper = null;
private SystemConfig2 SystemCfg = null;
public override void OnClick()
{
IWorkspaceAPI wsAPI = null;
try
{
if (_DataCatalog == null)
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>();
if (_DataCatalog == null)
return;
if (!(MapsManager.Instance.MapService.GetProjectInfo() is ProjectInfo ProInfo))
{
return;
}
if (pEditor == null)
pEditor = new EngineEditorClass();
if (pEditor.EditState != esriEngineEditState.esriEngineStateNotEditing)
{
MessageHelper.ShowTips("请先关闭编辑!");
return;
}
DirectoryCopy(SysAppPath.GetCurrentAppPath() + string.Format("工作空间\\模板\\新建变更工程\\{0}\\ZLDB.gdb", (int)Math.Floor(Math.Round(10 / ProInfo.XYResolution))), ProInfo.ProjDir);
DirectoryCopy(SysAppPath.GetCurrentAppPath() + string.Format("工作空间\\模板\\新建变更工程\\{0}\\NMDB.gdb", (int)Math.Floor(Math.Round(10 / ProInfo.XYResolution))), ProInfo.ProjDir);
ProInfo.ZLDatabase = Path.Combine(ProInfo.ProjDir, "ZLDB.gdb");
ProInfo.NMDatabase = Path.Combine(ProInfo.ProjDir, "NMDB.gdb");
//ProInfo.Save();
ISystemCfg cfg2 = BundleRuntime.Instance.GetFirstOrDefaultService<ISystemCfg>();
SystemCfg = cfg2.Load();
if (SystemCfg.ZLLayerLoadCfg == null)
{
SystemCfg.ZLLayerLoadCfg = new List<LayerCfg>();
}
#region 增量数据库创建
wsAPI = new WorkspaceAPI(ProInfo.ZLDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(wsAPI.CurrentWorkspace, hookHelper.FocusMap.SpatialReference, ProInfo.XYResolution);
IGroupLayer rootGroupLayer = new GroupLayer() { Name = "增量成果" };
ILayerGeneralProperties zlcglp = rootGroupLayer as ILayerGeneralProperties;
zlcglp.LayerDescription = "ZLCG";
LayerCfg GroupLayerInfo = _DataCatalog.AddLayer(rootGroupLayer) as LayerCfg;
#region 添加单独图层
IFeatureClassAPI PDTGXFcAPI = wsAPI.OpenFeatureClass("PDTGX");
IFeatureLayer tempLayer = new FeatureLayer() { Name = "坡度图更新", FeatureClass = PDTGXFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "PDTGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI CCWJQGXFcAPI = wsAPI.OpenFeatureClass("CCWJQGX");
tempLayer = new FeatureLayer() { Name = "拆除未尽区更新", FeatureClass = CCWJQGXFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "CCWJQGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI GDDBGXFcAPI = wsAPI.OpenFeatureClass("GDDBGX");
tempLayer = new FeatureLayer() { Name = "耕地等别更新层", FeatureClass = GDDBGXFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "GDDBGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI GFBQGXFcAPI = wsAPI.OpenFeatureClass("GFBQGX");
tempLayer = new FeatureLayer() { Name = "光伏板区更新层", FeatureClass = GFBQGXFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "GFBQGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
//23年规则起,不在包含“临时用地”单独图层
//IFeatureClassAPI LSYDGXFcAPI = wsAPI.OpenFeatureClass("LSYDGX");
//tempLayer = new FeatureLayer() { Name = "临时用地更新层", FeatureClass = LSYDGXFcAPI.FeatureClass };
//SetILayerSymbol(tempLayer, "LSYDGX");
//_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
//23年新增“工厂化工种植更新”
if (wsAPI.ExistFeatureClass("GCHZZGX"))
{
IFeatureClassAPI GCHZZGXFcAPI = wsAPI.OpenFeatureClass("GCHZZGX");
tempLayer = new FeatureLayer() { Name = "工厂化种植更新", FeatureClass = GCHZZGXFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "GCHZZGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
}
IFeatureClassAPI LMFWGXFcAPI = wsAPI.OpenFeatureClass("LMFWGX");
tempLayer = new FeatureLayer() { Name = "路面范围更新层", FeatureClass = LMFWGXFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "LMFWGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI TTQGXFcAPI = wsAPI.OpenFeatureClass("TTQGX");
tempLayer = new FeatureLayer() { Name = "推土区更新层", FeatureClass = TTQGXFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "TTQGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
#endregion
//hookHelper.FocusMap.AddLayer(rootGroupLayer);
IGroupLayer groupLayer = new GroupLayer() { Name = "增量图层" };
ILayerGeneralProperties zltclp = groupLayer as ILayerGeneralProperties;
zltclp.LayerDescription = "ZLTC";
GroupLayerInfo = _DataCatalog.AddLayer(groupLayer, GroupLayerInfo) as LayerCfg;
//rootGroupLayer.Add(groupLayer);
IFeatureClassAPI xzqgcFcAPI = wsAPI.OpenFeatureClass("XZQGXGC");
tempLayer = new FeatureLayer() { Name = "行政区更新过程", FeatureClass = xzqgcFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "XZQGXGC");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI xzqjxgxFcAPI = wsAPI.OpenFeatureClass("XZQJXGX");
tempLayer = new FeatureLayer() { Name = "行政区界线更新", FeatureClass = xzqjxgxFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "XZQJXGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI xzqgxFcAPI = wsAPI.OpenFeatureClass("XZQGX");
tempLayer = new FeatureLayer() { Name = "行政区更新", FeatureClass = xzqgxFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "XZQGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI cjdcqgcFcAPI = wsAPI.OpenFeatureClass("CJDCQGXGC");
tempLayer = new FeatureLayer() { Name = "村级调查区更新过程", FeatureClass = cjdcqgcFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "CJDCQGXGC");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI cjdcqjxgxFcAPI = wsAPI.OpenFeatureClass("CJDCQJXGX");
tempLayer = new FeatureLayer() { Name = "村级调查区界线更新", FeatureClass = cjdcqjxgxFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "CJDCQJXGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI cjdcqgxFcAPI = wsAPI.OpenFeatureClass("CJDCQGX");
tempLayer = new FeatureLayer() { Name = "村级调查区更新", FeatureClass = cjdcqgxFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "CJDCQGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI czcgcFcAPI = wsAPI.OpenFeatureClass("CZCDYDGXGC");
tempLayer = new FeatureLayer() { Name = "城镇村更新过程", FeatureClass = czcgcFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "CZCDYDGXGC");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI czcgxFcAPI = wsAPI.OpenFeatureClass("CZCDYDGX");
tempLayer = new FeatureLayer() { Name = "城镇村更新", FeatureClass = czcgxFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "CZCDYDGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI bgtbFcAPI = wsAPI.OpenFeatureClass("DLTBGXGC");
AddFieldSXWHForDBLayer.JudgeTypeAddField(ProInfo, bgtbFcAPI.FeatureClass);
tempLayer = new FeatureLayer() { Name = "地类图斑更新过程", FeatureClass = bgtbFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "DLTBGXGC");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
IFeatureClassAPI jctbFcAPI = wsAPI.OpenFeatureClass("DLTBGX");
AddFieldSXWHForDBLayer.JudgeTypeAddField(ProInfo, jctbFcAPI.FeatureClass);
tempLayer = new FeatureLayer() { Name = "地类图斑更新", FeatureClass = jctbFcAPI.FeatureClass };
SetILayerSymbol(tempLayer, "DLTBGX");
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
#endregion
ILayer groupLayerNM = MapsManager.Instance.MapService.GetGroupLayer("NMSJ");
object GroupLayerInfoNM = _DataCatalog.GetNodeByLayer(groupLayerNM);
IWorkspaceAPI NmWsAPI = new WorkspaceAPI(ProInfo.NMDatabase, WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(NmWsAPI.CurrentWorkspace, hookHelper.FocusMap.SpatialReference, ProInfo.XYResolution);
IFeatureLayer JCdltb_Layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
IFeatureClassAPI DLTBNMKAPI = null;// NmWsAPI.CreateFeatureClass("DLTB_NMK", (JCdltb_Layer.FeatureClass as IGeoDataset).SpatialReference, JCdltb_Layer.FeatureClass.Fields);
DLTBNMKAPI = NmWsAPI.OpenFeatureClass2("DLTB_NMK");
if (DLTBNMKAPI != null)
{
if (DLTBNMKAPI.FeatureClass.FindField("XZQDM") == -1)
DLTBNMKAPI.AddField("XZQDM", ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString, "行政区代码");
if (DLTBNMKAPI != null && DLTBNMKAPI.FeatureClass.FindField("XZQTZLX") == -1)
DLTBNMKAPI.AddField("XZQTZLX", ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeInteger, "行政区调整类型");
tempLayer = new FeatureLayer() { Name = "地类图斑年末库", FeatureClass = DLTBNMKAPI.FeatureClass };
_DataCatalog.AddLayer(tempLayer, GroupLayerInfoNM);
}
_DataCatalog.UpdateTree();
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" });
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "InitProject" });
if (NmWsAPI != null) NmWsAPI.CloseWorkspace();
if (DLTBNMKAPI != null) DLTBNMKAPI.CloseFeatureClass();
}
catch (Exception ex)
{
MessageHelper.ShowTips("系统设置初始化页面失败:" + ex.Message);
LogAPI.Debug(ex);
}
finally
{
if (wsAPI != null)
{
wsAPI.CloseWorkspace();
wsAPI = null;
}
}
}
private void SetILayerSymbol(IFeatureLayer tempLayer, string LayerAliseName)
{
IFeatureRenderer result = null;
LayerCfg layerCfg = SystemCfg.ZLLayerLoadCfg.FirstOrDefault(x => x.FcName == LayerAliseName);//默认配置默认不为NULL
if (layerCfg == null)
layerCfg = SystemCfg.ZLLayerLoadCfg[0].Layers.FirstOrDefault(x => x.FcName == LayerAliseName);//默认配置默认不为NULL
if (layerCfg != null && !string.IsNullOrWhiteSpace(layerCfg.Symbol))
{
AdvancedDrawingInfo ad = AdvancedDrawingInfo.FromJson(layerCfg.Symbol);
if (ad != null)
{
if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.SimpleRenderer)
{
Symbol symbol1 = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.SimpleRenderer).Symbol;
ISimpleRenderer simpleRander2 = SymbolConvert.Instance().GetSimpleRenderer(symbol1, SymbolTypeEnum.Fill);
result = simpleRander2 as IFeatureRenderer;
}
else if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer)
{
Renderer rander = ad.DrawingInfo.Renderer;
IUniqueValueRenderer uniqueValueRander = SymbolConvert.Instance().GetUniqueValueRenderer(rander, SymbolTypeEnum.Fill);
result = uniqueValueRander as IFeatureRenderer;
}
}
#region 样式
if (result != null)
(tempLayer as IGeoFeatureLayer).Renderer = result;
#endregion
#region 显示比例设置
tempLayer.MinimumScale = layerCfg.MinScale;
tempLayer.MaximumScale = layerCfg.MaxScale;
#endregion
#region 图层透明度
if (tempLayer is ILayerEffects mLayerEffects)//透明度
mLayerEffects.Transparency = (short)layerCfg.Transparency;
#endregion
#region 是否显示
tempLayer.Visible = layerCfg.Visible;//是否显示
#endregion
#region 是否可选择
tempLayer.Selectable = layerCfg.Selectable;
#endregion
#region 过滤条件
IFeatureLayerDefinition pFLDefinition = tempLayer as IFeatureLayerDefinition;
if (pFLDefinition != null)
{
pFLDefinition.DefinitionExpression = layerCfg.DefinitionExpression;
}
#endregion
}
}
public override void OnCreate(object Hook)
{
if (hookHelper == null)
hookHelper = new HookHelperClass();
hookHelper.Hook = Hook;
pEditor = new EngineEditorClass();
}
public override bool Enabled
{
get
{
//验证是否打开工程
if (!(MapsManager.Instance.MapService.GetProjectInfo() is ProjectInfo ProInfo))
return false;
else
return string.IsNullOrWhiteSpace(ProInfo.ZLDatabase) && !string.IsNullOrWhiteSpace(ProInfo.BGDatabase);//对应BUG:6333,创建变更数据库后才能创建增量数据库
}
}
public bool DirectoryCopy(string sourceDir, string targetDirPath)
{
try
{
if (!Directory.Exists(sourceDir)) return false;
string targetDir = targetDirPath + "\\" + Path.GetFileName(sourceDir);
if (!Directory.Exists(targetDir)) Directory.CreateDirectory(targetDir);
// 文件及文件夹名称数组
string[] dirColl = Directory.GetDirectories(sourceDir);
string[] fileColl = Directory.GetFiles(sourceDir);
// 便利所有文件
if (fileColl.Length > 0)
{
string fileName;
foreach (string fileDir in fileColl)
{
fileName = System.IO.Path.GetFileName(fileDir);
File.Copy(sourceDir + "\\" + fileName, targetDir + "\\" + fileName, true);
}
}
// 遍历所有文件夹
if (dirColl.Length > 0)
{
string folderName;
foreach (string dir in dirColl)
{
folderName = System.IO.Path.GetFileName(dir);
// 递归调用
Directory.CreateDirectory(targetDir + "\\" + folderName);
DirectoryCopy(dir, targetDir + "\\" + folderName);
}
}
return true;
}
catch (Exception ex)
{
LogAPI.Debug("新建工程页面中,文件夹复制时失败,异常原因: " + ex + " ; ");
return false;
throw;
}
}
}
}