|
|
|
|
using ESRI.ArcGIS.Carto;
|
|
|
|
|
using ESRI.ArcGIS.Controls;
|
|
|
|
|
using ESRI.ArcGIS.Geodatabase;
|
|
|
|
|
using KGIS.Framework.AE;
|
|
|
|
|
using KGIS.Framework.Maps;
|
|
|
|
|
using KGIS.Framework.OpenData.Control;
|
|
|
|
|
using KGIS.Framework.OpenData.Filter;
|
|
|
|
|
using KGIS.Framework.OpenData.InterFace;
|
|
|
|
|
using KGIS.Framework.Platform;
|
|
|
|
|
using KGIS.Framework.Platform.Helper;
|
|
|
|
|
using KGIS.Framework.Utils;
|
|
|
|
|
using KGIS.Framework.Utils.Helper;
|
|
|
|
|
using Kingo.OpenData.Filter;
|
|
|
|
|
using Kingo.Plugin.BatchDataLoad.Model;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using UIShell.OSGi;
|
|
|
|
|
using KGIS.Framework.AE.Enum;
|
|
|
|
|
using Kingo.PluginServiceInterface;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using KGIS.Framework.Utils.Utility;
|
|
|
|
|
using KGIS.Framework.OpenData.Enum;
|
|
|
|
|
using KGIS.Framework.DBOperator;
|
|
|
|
|
using Kingo.Framework.LayerStyleConvert.XSDClass;
|
|
|
|
|
using Kingo.Framework.LayerStyleConvert.Common;
|
|
|
|
|
using ESRI.ArcGIS.DataSourcesFile;
|
|
|
|
|
using ESRI.ArcGIS.DataSourcesRaster;
|
|
|
|
|
using KUI.Windows;
|
|
|
|
|
using Kingo.PluginServiceInterface.Helper.VCT;
|
|
|
|
|
using Kingo.PluginServiceInterface.Model;
|
|
|
|
|
using ESRI.ArcGIS.Geometry;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using ESRI.ArcGIS.Display;
|
|
|
|
|
using ESRI.ArcGIS.esriSystem;
|
|
|
|
|
using Kingo.Plugin.BHTB_Extract.View;
|
|
|
|
|
|
|
|
|
|
namespace Kingo.Plugin.BatchDataLoad.View
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// UcBatchDataLoad.xaml 的交互逻辑
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class UcBatchDataLoad : BaseWindow
|
|
|
|
|
{
|
|
|
|
|
private IHookHelper hookHelper = null;
|
|
|
|
|
List<AddTreeList> addTreeLayerCfg = new List<AddTreeList>();
|
|
|
|
|
public string ImportDataType { get; set; }
|
|
|
|
|
private string SourceMDBPath { get; set; }
|
|
|
|
|
List<string> itemSources;
|
|
|
|
|
List<LayerCfg> nodes = new List<LayerCfg>();
|
|
|
|
|
private IDataCatalogService _DataCatalog = null;
|
|
|
|
|
private ISystemCfg SystemCfg = null;
|
|
|
|
|
private SystemConfig2 Cfg = null;
|
|
|
|
|
string titleName;
|
|
|
|
|
private string rootFilePath = "";
|
|
|
|
|
ILayer m_featureLayer = null;
|
|
|
|
|
IEnvelope CurrentEnvelope = null;
|
|
|
|
|
public double FramingSize = 10000;
|
|
|
|
|
public UcBatchDataLoad(IHookHelper hook)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
itemSources = new List<string>();
|
|
|
|
|
hookHelper = hook;
|
|
|
|
|
if (_DataCatalog == null)
|
|
|
|
|
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>();
|
|
|
|
|
|
|
|
|
|
SystemCfg = BundleRuntime.Instance.GetFirstOrDefaultService<ISystemCfg>();
|
|
|
|
|
Cfg = SystemCfg.Load();
|
|
|
|
|
if (Cfg != null && Cfg.BHTBLayerLoadCfg != null && Cfg.BHTBLayerLoadCfg.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
LayerCfg rootLayer = Cfg.BHTBLayerLoadCfg.Find(a => a.PID == 0 && a.ID == 1);
|
|
|
|
|
itemSources.Add(rootLayer.FcPath);
|
|
|
|
|
}
|
|
|
|
|
cobDataBase.ItemsSource = itemSources;
|
|
|
|
|
nodes = Cfg.BHTBLayerLoadCfg;
|
|
|
|
|
BatchLoadDataModel.Instance.BatchLoadDatas = Cfg.BHTBLayerLoadCfg;
|
|
|
|
|
if (itemSources != null && itemSources.Count != 0)
|
|
|
|
|
cobDataBase.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
Dictionary<string, object> pathGroupLayerDic = new Dictionary<string, object>();
|
|
|
|
|
private void BtnOK_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (BatchLoadDataModel.Instance == null || BatchLoadDataModel.Instance.BatchLoadDatas == null || BatchLoadDataModel.Instance.BatchLoadDatas.Count == 0) return;
|
|
|
|
|
|
|
|
|
|
EngineEditor engineEditor = new EngineEditor();
|
|
|
|
|
if (engineEditor.EditState == esriEngineEditState.esriEngineStateEditing)
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowTips("当前处于编辑状态,请关闭编辑后重试!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (BatchLoadDataModel.Instance.BatchLoadDatas.FindAll(a => a.LayerType != EnumLayerType.GroupLayer).Count == 0)
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowTips("当前选择文件不包含图层数据!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.ShowLoading("正在进行数据加载...", 0, 0);
|
|
|
|
|
addTreeLayerCfg.Clear();
|
|
|
|
|
//加载树表头
|
|
|
|
|
object GroupLayerInfo = null;
|
|
|
|
|
ILayer groupLayer = MapsManager.Instance.MapService.GetGroupLayer(titleName);
|
|
|
|
|
if (groupLayer != null)
|
|
|
|
|
{
|
|
|
|
|
_DataCatalog.RemoveLayer(groupLayer);
|
|
|
|
|
_DataCatalog.UpdateTree();
|
|
|
|
|
}
|
|
|
|
|
groupLayer = new GroupLayer() { Name = titleName };
|
|
|
|
|
ILayerGeneralProperties layerGeneralProperties = groupLayer as ILayerGeneralProperties;
|
|
|
|
|
layerGeneralProperties.LayerDescription = titleName;
|
|
|
|
|
GroupLayerInfo = _DataCatalog.AddLayer(groupLayer);
|
|
|
|
|
|
|
|
|
|
AddTreeList rootTreeList = new AddTreeList() { AddTreeListGroupLayerInfo = GroupLayerInfo };
|
|
|
|
|
addTreeLayerCfg.Add(rootTreeList);
|
|
|
|
|
|
|
|
|
|
pathGroupLayerDic.Clear();
|
|
|
|
|
pathGroupLayerDic.Add(BatchLoadDataModel.Instance.BatchLoadDatas.Find(a=>a.LayerName == titleName).FcPath, GroupLayerInfo);
|
|
|
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(cobDataBase.Text);
|
|
|
|
|
AddChildrenTree(directoryInfo, rootTreeList);
|
|
|
|
|
|
|
|
|
|
List<LayerCfg> featureLayers = BatchLoadDataModel.Instance.BatchLoadDatas.FindAll(a => a.LayerType != EnumLayerType.GroupLayer);
|
|
|
|
|
foreach (LayerCfg item in featureLayers)
|
|
|
|
|
{
|
|
|
|
|
if (item.IsChecked)
|
|
|
|
|
{
|
|
|
|
|
bool parentIsCheck = GetParentIsChecked(item.PID);
|
|
|
|
|
if (!parentIsCheck) continue;
|
|
|
|
|
CreateBHTBTQ(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (_DataCatalog != null)
|
|
|
|
|
{
|
|
|
|
|
_DataCatalog.UpdateTree();
|
|
|
|
|
}
|
|
|
|
|
//批量数据加载图层树顺序调整
|
|
|
|
|
List<LayerCfg> childlayers = (_DataCatalog.CurrentLayers as LayerCfg).Layers;
|
|
|
|
|
if (childlayers != null && childlayers.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
LayerCfg firstlayerCfg = childlayers[0];
|
|
|
|
|
int lastIndx = childlayers.Count - 1;
|
|
|
|
|
for (int i = 0; i < lastIndx; i++)
|
|
|
|
|
{
|
|
|
|
|
childlayers[i] = childlayers[i + 1];
|
|
|
|
|
}
|
|
|
|
|
childlayers[lastIndx] = firstlayerCfg;
|
|
|
|
|
(_DataCatalog.CurrentLayers as LayerCfg).Layers = childlayers;
|
|
|
|
|
}
|
|
|
|
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" });
|
|
|
|
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "InitProject" });
|
|
|
|
|
|
|
|
|
|
//自动生成作业区
|
|
|
|
|
if (chkIsCreateZYQ.IsChecked == true)
|
|
|
|
|
{
|
|
|
|
|
GetEnvelopeBorder();
|
|
|
|
|
}
|
|
|
|
|
//刷新作业区管理列表
|
|
|
|
|
if (UcZYQMagr.Instance.IsLoaded)
|
|
|
|
|
{
|
|
|
|
|
UcZYQMagr.Instance.InitTreeView();
|
|
|
|
|
MarkLayer();
|
|
|
|
|
}
|
|
|
|
|
IUcMulitMapControlHelper ucMulitMapControlHelper = BundleRuntime.Instance.GetFirstOrDefaultService<IUcMulitMapControlHelper>();
|
|
|
|
|
if (ucMulitMapControlHelper != null)
|
|
|
|
|
{
|
|
|
|
|
ucMulitMapControlHelper.ClearData();
|
|
|
|
|
ucMulitMapControlHelper.SetLayer();
|
|
|
|
|
ucMulitMapControlHelper.MarkLabelLayer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加遮罩 更新地图视图
|
|
|
|
|
//ShowMaskHelper showMaskForBHTBHelper = new ShowMaskHelper();
|
|
|
|
|
//showMaskForBHTBHelper.axMapControl = MapsManager.Instance.MapService.getAxMapControl();
|
|
|
|
|
//showMaskForBHTBHelper.ShowBorderMask();
|
|
|
|
|
this.CloseLoading();
|
|
|
|
|
MessageHelper.ShowTips("图层加载完成。");
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this.CloseLoading();
|
|
|
|
|
MessageHelper.ShowError("加载图层失败:" + ex.Message);
|
|
|
|
|
LogAPI.Debug("加载图层失败:" + ex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddChildrenTree(DirectoryInfo directoryInfo, AddTreeList rootTreeList)
|
|
|
|
|
{
|
|
|
|
|
var subDirectory = directoryInfo.GetDirectories();
|
|
|
|
|
if (subDirectory.Length != 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < subDirectory.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (rootTreeList == null || rootTreeList.AddTreeListGroupLayerInfo == null) continue;
|
|
|
|
|
if (subDirectory[i].Name.ToLower().Contains("gdb") || subDirectory[i].Name.ToLower().Contains("mdb") || subDirectory[i].Name.ToLower().Contains("shp") || subDirectory[i].Name.ToLower().Contains("vct") || subDirectory[i].Name.ToLower().Contains("img") || subDirectory[i].Name.ToLower().Contains("jpg") || subDirectory[i].Name.ToLower().Contains("jpeg") || subDirectory[i].Name.ToLower().Contains("png") || subDirectory[i].Name.ToLower().Contains("tif")) continue;
|
|
|
|
|
//if (Directory.GetDirectories(subDirectory[i].FullName).Length == 0 || Directory.GetFiles(subDirectory[i].FullName).Length == 0) continue;
|
|
|
|
|
LayerCfg tempLayerCfg = BatchLoadDataModel.Instance.BatchLoadDatas.Find(a => a.FcPath == subDirectory[i].FullName);
|
|
|
|
|
if (tempLayerCfg == null) continue;
|
|
|
|
|
object tempGroupLayerInfo = null;
|
|
|
|
|
if (tempLayerCfg.IsChecked && GetParentIsChecked(tempLayerCfg.PID))
|
|
|
|
|
{
|
|
|
|
|
ILayer tempgroupLayer = new GroupLayer() { Name = subDirectory[i].Name };
|
|
|
|
|
ILayerGeneralProperties layerGeneralProperties = tempgroupLayer as ILayerGeneralProperties;
|
|
|
|
|
layerGeneralProperties.LayerDescription = subDirectory[i].Name;
|
|
|
|
|
tempGroupLayerInfo = _DataCatalog.AddLayer(tempgroupLayer, rootTreeList.AddTreeListGroupLayerInfo);
|
|
|
|
|
if (!pathGroupLayerDic.Keys.Contains(subDirectory[i].FullName))
|
|
|
|
|
{
|
|
|
|
|
pathGroupLayerDic.Add(subDirectory[i].FullName, tempGroupLayerInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rootTreeList.AddTreeListLayers.Add(new AddTreeList()
|
|
|
|
|
{
|
|
|
|
|
AddTreeListGroupLayerInfo = tempGroupLayerInfo
|
|
|
|
|
});
|
|
|
|
|
addTreeLayerCfg.Add(rootTreeList.AddTreeListLayers[rootTreeList.AddTreeListLayers.Count - 1]);
|
|
|
|
|
AddChildrenTree(subDirectory[i], rootTreeList.AddTreeListLayers[rootTreeList.AddTreeListLayers.Count - 1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建变化图斑提取图层
|
|
|
|
|
private void CreateBHTBTQ(LayerCfg layerCfg)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (layerCfg == null) return;
|
|
|
|
|
string filePath = layerCfg.FcPath;
|
|
|
|
|
if (string.IsNullOrEmpty(filePath)) return;
|
|
|
|
|
if (_DataCatalog == null) return;
|
|
|
|
|
IWorkspaceAPI wsAPI = null;
|
|
|
|
|
|
|
|
|
|
LayerCfg parent = BatchLoadDataModel.Instance.BatchLoadDatas.Find(a => a.ID == layerCfg.PID);
|
|
|
|
|
//object GroupLayerInfo = _DataCatalog.GetNodeByLayerName(parent.LayerName);
|
|
|
|
|
//if (GroupLayerInfo == null)
|
|
|
|
|
//{
|
|
|
|
|
// GroupLayerInfo = MapsManager.Instance.MapService.GetGroupLayer(parent.LayerName);
|
|
|
|
|
//}
|
|
|
|
|
object GroupLayerInfo = null;
|
|
|
|
|
pathGroupLayerDic.TryGetValue(parent.FcPath, out GroupLayerInfo);
|
|
|
|
|
|
|
|
|
|
if (filePath.EndsWith("MDB") || filePath.EndsWith("mdb") || filePath.EndsWith("VCT") || filePath.EndsWith("vct"))
|
|
|
|
|
{
|
|
|
|
|
wsAPI = new WorkspaceAPI(filePath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.MDBFile);
|
|
|
|
|
}
|
|
|
|
|
else if (filePath.EndsWith("GDB") || filePath.EndsWith("gdb"))
|
|
|
|
|
{
|
|
|
|
|
wsAPI = new WorkspaceAPI(filePath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
|
|
|
|
|
}
|
|
|
|
|
else if (filePath.EndsWith("SHP") || filePath.EndsWith("shp"))
|
|
|
|
|
{
|
|
|
|
|
//wsAPI = new WorkspaceAPI(filePath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.ShapeFile);
|
|
|
|
|
string filePathName = System.IO.Path.GetFileNameWithoutExtension(filePath);
|
|
|
|
|
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
|
|
|
|
|
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(filePath), 0);
|
|
|
|
|
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
|
|
|
|
|
IFeatureClass pSourceFeatureClass = pFeatureWorkspace.OpenFeatureClass(filePathName);
|
|
|
|
|
|
|
|
|
|
IFeatureLayer tempLayer = new FeatureLayer() { Name = filePathName, FeatureClass = pSourceFeatureClass };
|
|
|
|
|
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (filePath.EndsWith("TIF") || filePath.EndsWith("tif") || filePath.EndsWith("TIFF") || filePath.EndsWith("tiff") || filePath.ToLower().EndsWith("img") || filePath.ToLower().EndsWith("jpg") || filePath.ToLower().EndsWith("jpeg") || filePath.ToLower().EndsWith("png"))
|
|
|
|
|
{
|
|
|
|
|
int Index = filePath.LastIndexOf("\\");
|
|
|
|
|
string fileName = filePath.Substring(Index + 1);
|
|
|
|
|
string filePathName = filePath.Substring(0, Index);
|
|
|
|
|
//IWorkspaceFactory workspcFac = new RasterWorkspaceFactoryClass();
|
|
|
|
|
//IWorkspace works = workspcFac.OpenFromFile(filePathName, 0);
|
|
|
|
|
//IRasterWorkspace rasterworkspc = workspcFac.OpenFromFile(filePathName, 0) as IRasterWorkspace;
|
|
|
|
|
//IRasterDataset rasterDatst = rasterworkspc.OpenRasterDataset(fileName);
|
|
|
|
|
//IRasterLayer layer = new RasterLayer();
|
|
|
|
|
//layer.CreateFromDataset(rasterDatst);
|
|
|
|
|
|
|
|
|
|
//IFeatureLayer tempLayer = new FeatureLayer() { Name = filePathName, FeatureClass = rasterDatst };
|
|
|
|
|
//_DataCatalog.AddLayer(layer, GroupLayerInfo);
|
|
|
|
|
|
|
|
|
|
IRasterLayer layer = new RasterLayerClass();
|
|
|
|
|
layer.CreateFromFilePath(filePath);
|
|
|
|
|
layer.Name = fileName;
|
|
|
|
|
_DataCatalog.AddLayer(layer, GroupLayerInfo);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (wsAPI == null) return;
|
|
|
|
|
|
|
|
|
|
List<IFeatureClass> featureClasses = wsAPI.GetAllFeatureClass(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
|
|
|
|
|
for (int i = 0; i < featureClasses.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
string name = featureClasses[i].AliasName;
|
|
|
|
|
if (!layerCfg.LayerName.Contains(name)) continue;
|
|
|
|
|
IFeatureClassAPI s_FcAPI = wsAPI.OpenFeatureClass(name);
|
|
|
|
|
IFeatureLayer tempLayer = new FeatureLayer() { Name = name, FeatureClass = s_FcAPI.FeatureClass };
|
|
|
|
|
SetILayerSymbol(tempLayer, name);
|
|
|
|
|
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//MessageHelper.ShowError("加载图层失败:" + ex.Message);
|
|
|
|
|
LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetILayerSymbol(IFeatureLayer tempLayer, string LayerAliseName)
|
|
|
|
|
{
|
|
|
|
|
IFeatureRenderer result = null;
|
|
|
|
|
LayerCfg layerCfg = Cfg.BHTBLayerLoadCfg.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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool GetParentIsChecked(int PID)
|
|
|
|
|
{
|
|
|
|
|
LayerCfg parent = BatchLoadDataModel.Instance.BatchLoadDatas.Find(a => a.ID == PID);
|
|
|
|
|
if (parent == null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (!parent.IsChecked)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return GetParentIsChecked(parent.PID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectFile_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.FolderBrowserDialog openFileDialog = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
|
|
if (cobDataBase.ItemsSource != null && itemSources.Count != 0)
|
|
|
|
|
openFileDialog.SelectedPath = cobDataBase.ItemsSource.FindFirst().ToString();
|
|
|
|
|
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
string[] str = openFileDialog.SelectedPath.Split('\\');
|
|
|
|
|
if (str == null || str.Length == 0) return;
|
|
|
|
|
titleName = str[str.Length - 1];
|
|
|
|
|
|
|
|
|
|
this.cobDataBase.ItemsSource = null;
|
|
|
|
|
itemSources.Clear();
|
|
|
|
|
itemSources.Add(openFileDialog.SelectedPath);
|
|
|
|
|
this.cobDataBase.ItemsSource = itemSources;
|
|
|
|
|
this.cobDataBase.SelectedIndex = 0;
|
|
|
|
|
|
|
|
|
|
BatchLoadDataModel.Instance.BatchLoadDatas.Clear();
|
|
|
|
|
nodes.Clear();
|
|
|
|
|
|
|
|
|
|
rootFilePath = openFileDialog.SelectedPath;
|
|
|
|
|
//表头
|
|
|
|
|
string size = GetFileSize(GetDirectoryLength(openFileDialog.SelectedPath));
|
|
|
|
|
LayerCfg node = new LayerCfg()
|
|
|
|
|
{
|
|
|
|
|
IsChecked = true,
|
|
|
|
|
LayerName = titleName,
|
|
|
|
|
FcPath = openFileDialog.SelectedPath,
|
|
|
|
|
FileSize = size,
|
|
|
|
|
LayerType = EnumLayerType.GroupLayer,
|
|
|
|
|
AbsolutePathType = "AddLayerWay" //标记为外部路径数据
|
|
|
|
|
};
|
|
|
|
|
nodes.Add(node);
|
|
|
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(openFileDialog.SelectedPath);
|
|
|
|
|
GetChildren(directoryInfo, node);
|
|
|
|
|
|
|
|
|
|
LoadFileDataPath(openFileDialog.SelectedPath);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("选择文件失败:" + ex);
|
|
|
|
|
MessageHelper.Show("选择文件失败:" + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetChildren(DirectoryInfo directoryInfo, LayerCfg node)
|
|
|
|
|
{
|
|
|
|
|
var subDirectory = directoryInfo.GetDirectories();
|
|
|
|
|
if (subDirectory.Length != 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < subDirectory.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (subDirectory[i].Name.ToLower().Contains("gdb") || subDirectory[i].Name.ToLower().Contains("mdb") || subDirectory[i].Name.ToLower().Contains("shp") || subDirectory[i].Name.ToLower().Contains("vct") || subDirectory[i].Name.ToLower().Contains("img") || subDirectory[i].Name.ToLower().Contains("jpg") || subDirectory[i].Name.ToLower().Contains("jpeg") || subDirectory[i].Name.ToLower().Contains("png") || subDirectory[i].Name.ToLower().Contains("tif")) continue;
|
|
|
|
|
|
|
|
|
|
string size1 = GetFileSize(GetDirectoryLength(subDirectory[i].FullName));
|
|
|
|
|
if (size1 == "0" && (Directory.GetDirectories(subDirectory[i].FullName).Length == 0 || Directory.GetFiles(subDirectory[i].FullName).Length == 0)) continue;
|
|
|
|
|
string str = subDirectory[i].FullName.Replace(rootFilePath, "");
|
|
|
|
|
str = str.Trim();
|
|
|
|
|
int length = str.Split('\\').Length;
|
|
|
|
|
if (length <= 3)
|
|
|
|
|
{
|
|
|
|
|
string size = GetFileSize(GetDirectoryLength(subDirectory[i].FullName));
|
|
|
|
|
node.Layers.Add(new LayerCfg(node)
|
|
|
|
|
{
|
|
|
|
|
IsChecked = true,
|
|
|
|
|
LayerName = subDirectory[i].Name,
|
|
|
|
|
FcPath = subDirectory[i].FullName,
|
|
|
|
|
FileSize = size,
|
|
|
|
|
LayerType = EnumLayerType.GroupLayer,
|
|
|
|
|
AbsolutePathType = "AddLayerWay" //标记为外部路径数据
|
|
|
|
|
});
|
|
|
|
|
nodes.Add(node.Layers[node.Layers.Count - 1]);
|
|
|
|
|
GetChildren(subDirectory[i], node.Layers[node.Layers.Count - 1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void LoadFileDataPath(string projectPath)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(projectPath))
|
|
|
|
|
{
|
|
|
|
|
List<string> dataPathList = new List<string>();
|
|
|
|
|
|
|
|
|
|
GetOtherDataPath(projectPath, dataPathList);
|
|
|
|
|
if (dataPathList.Count != 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (string path in dataPathList)
|
|
|
|
|
{
|
|
|
|
|
//获取gdb内部表
|
|
|
|
|
ImportDataType = System.IO.Path.GetExtension(path).ToUpper().Replace('.', ' ').TrimStart();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(ImportDataType) || (ImportDataType != "VCT" && ImportDataType != "GDB" && ImportDataType != "MDB" && ImportDataType != "SHP" && ImportDataType != "TIF" && ImportDataType != "TIFF" && ImportDataType != "IMG" && ImportDataType != "JPG" && ImportDataType != "JPEG" && ImportDataType != "PNG")) continue;
|
|
|
|
|
if (ImportDataType == "SHP")
|
|
|
|
|
{
|
|
|
|
|
ImportDataType = "Shape";
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(ImportDataType) && ImportDataType.Equals("VCT"))
|
|
|
|
|
{
|
|
|
|
|
string TempMDBFolderPath = System.IO.Path.GetTempPath();
|
|
|
|
|
string TempMDBPath = System.IO.Path.Combine(TempMDBFolderPath, string.Format("{0}.mdb", System.IO.Path.GetFileNameWithoutExtension(path)));
|
|
|
|
|
if (File.Exists(TempMDBPath))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(TempMDBPath);
|
|
|
|
|
}
|
|
|
|
|
VCTToMDBHelper3 vcttomdb = new VCTToMDBHelper3
|
|
|
|
|
{
|
|
|
|
|
RootPath = TempMDBFolderPath
|
|
|
|
|
};
|
|
|
|
|
vcttomdb.VCTToMDB(path);
|
|
|
|
|
if (!File.Exists(TempMDBPath)) continue;
|
|
|
|
|
SourceMDBPath = TempMDBPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetPathIDPID(path, out LayerCfg parentLayer);
|
|
|
|
|
SetTableMapping(path, parentLayer);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (dataPathList.Count == 0 && projectPath.ToLower().EndsWith("gdb"))
|
|
|
|
|
{
|
|
|
|
|
GetPathIDPID(projectPath, out LayerCfg parentLayer);
|
|
|
|
|
SetTableMapping(projectPath, parentLayer);
|
|
|
|
|
}
|
|
|
|
|
BatchLoadDataModel.Instance.BatchLoadDatas = nodes;
|
|
|
|
|
Cfg.BHTBLayerLoadCfg = BatchLoadDataModel.Instance.BatchLoadDatas;
|
|
|
|
|
UcTreeListViewControl.Instance.Refresh();
|
|
|
|
|
Cfg.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("获取数据文件失败:" + ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void SetTableMapping(string path, LayerCfg parentLayer)
|
|
|
|
|
{
|
|
|
|
|
if (parentLayer == null) return;
|
|
|
|
|
IWorkspaceAPI t_WsAPI = null;
|
|
|
|
|
IWorkspaceAPI s_WsAPI = null;
|
|
|
|
|
IFeatureClassAPI s_FCAPI = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string s_MdbPath = null;
|
|
|
|
|
if (ImportDataType == "VCT")
|
|
|
|
|
{
|
|
|
|
|
s_MdbPath = SourceMDBPath;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s_MdbPath = path;
|
|
|
|
|
}
|
|
|
|
|
if ((ImportDataType == "MDB" || ImportDataType == "VCT") && !File.Exists(s_MdbPath))
|
|
|
|
|
{
|
|
|
|
|
if (!System.IO.Path.GetFileName(s_MdbPath).Equals(".mdb"))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ImportDataType == "GDB" && !Directory.Exists(s_MdbPath))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ImportDataType == "MDB" || ImportDataType == "VCT")
|
|
|
|
|
{
|
|
|
|
|
s_WsAPI = new WorkspaceAPI(s_MdbPath, WorkspaceTypeEnum.MDBFile);
|
|
|
|
|
}
|
|
|
|
|
else if (ImportDataType == "Shape")
|
|
|
|
|
{
|
|
|
|
|
//s_WsAPI = new WorkspaceAPI(s_MdbPath, WorkspaceTypeEnum.ShapeFile);
|
|
|
|
|
string filePathName = System.IO.Path.GetFileNameWithoutExtension(path);
|
|
|
|
|
//IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
|
|
|
|
|
//IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(Path.GetDirectoryName(s_MdbPath), 0);
|
|
|
|
|
//IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
|
|
|
|
|
//IFeatureClass pSourceFeatureClass = pFeatureWorkspace.OpenFeatureClass(filePathName);
|
|
|
|
|
LayerCfg newLayerCfg = new LayerCfg(parentLayer)
|
|
|
|
|
{
|
|
|
|
|
IsChecked = true,
|
|
|
|
|
//LayerName = pSourceFeatureClass.AliasName.ToString(),
|
|
|
|
|
LayerName = filePathName,
|
|
|
|
|
FcPath = path,
|
|
|
|
|
FileSize = "",
|
|
|
|
|
LayerType = EnumLayerType.FeatureLayer,
|
|
|
|
|
AbsolutePathType = "AddLayerWay" //标记为外部路径数据
|
|
|
|
|
};
|
|
|
|
|
parentLayer.Layers.Add(newLayerCfg);
|
|
|
|
|
nodes.Add(newLayerCfg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (ImportDataType == "TIF" || ImportDataType == "TIFF" || ImportDataType == "IMG" || ImportDataType == "JPG" || ImportDataType == "JPEG" || ImportDataType == "PNG")
|
|
|
|
|
{
|
|
|
|
|
//s_WsAPI = new WorkspaceAPI(s_MdbPath, WorkspaceTypeEnum.RasterFile);
|
|
|
|
|
string filePathName = System.IO.Path.GetFileName(path);
|
|
|
|
|
LayerCfg newLayerCfg = new LayerCfg(parentLayer)
|
|
|
|
|
{
|
|
|
|
|
IsChecked = true,
|
|
|
|
|
LayerName = filePathName.ToString(),
|
|
|
|
|
FcPath = path,
|
|
|
|
|
FileSize = "",
|
|
|
|
|
LayerType = EnumLayerType.RasterLayer,
|
|
|
|
|
AbsolutePathType = "AddLayerWay" //标记为外部路径数据
|
|
|
|
|
};
|
|
|
|
|
parentLayer.Layers.Add(newLayerCfg);
|
|
|
|
|
nodes.Add(newLayerCfg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s_WsAPI = new WorkspaceAPI(s_MdbPath, WorkspaceTypeEnum.GDBFile);
|
|
|
|
|
}
|
|
|
|
|
//源数据获取图层
|
|
|
|
|
if (s_WsAPI == null) return;//源数据不能为空
|
|
|
|
|
List<KeyAndValue> s_TbList = s_WsAPI.GetFeatureClassName(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset).Where(x => !x.Value.StartsWith("TDQSQ")).Select(x => new KeyAndValue() { S_Key = x.Key, S_Value = x.Value }).ToList();
|
|
|
|
|
Dictionary<string, string> s_TbList2 = s_WsAPI.GetFeatureClassName(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass);
|
|
|
|
|
foreach (string item in s_TbList2.Keys)
|
|
|
|
|
{
|
|
|
|
|
if (!s_TbList.Select(x => x.S_Value).Contains(item))
|
|
|
|
|
s_TbList.Add(new KeyAndValue() { S_Key = item, S_Value = s_TbList2[item] });
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < s_TbList.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
LayerCfg newLayerCfg = new LayerCfg(parentLayer)
|
|
|
|
|
{
|
|
|
|
|
IsChecked = true,
|
|
|
|
|
LayerName = s_TbList[i].S_Key.ToString(),
|
|
|
|
|
FcPath = path,
|
|
|
|
|
FileSize = "",
|
|
|
|
|
LayerType = EnumLayerType.FeatureLayer,
|
|
|
|
|
AbsolutePathType = "AddLayerWay" //标记为外部路径数据
|
|
|
|
|
};
|
|
|
|
|
parentLayer.Layers.Add(newLayerCfg);
|
|
|
|
|
nodes.Add(newLayerCfg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (s_WsAPI != null)
|
|
|
|
|
s_WsAPI.CloseWorkspace();
|
|
|
|
|
if (t_WsAPI != null)
|
|
|
|
|
t_WsAPI.CloseWorkspace();
|
|
|
|
|
if (s_FCAPI != null)
|
|
|
|
|
{
|
|
|
|
|
s_FCAPI.CloseFeatureClass();
|
|
|
|
|
s_FCAPI = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void cobDataBase_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (cobDataBase.ItemsSource != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BatchLoadDataModel.Instance.BatchLoadDatas.Clear();
|
|
|
|
|
nodes.Clear();
|
|
|
|
|
string selectedPath = this.cobDataBase.SelectedItem.ToString();
|
|
|
|
|
string[] str = selectedPath.Split('\\');
|
|
|
|
|
if (str == null || str.Length == 0) return;
|
|
|
|
|
titleName = str[str.Length - 1];
|
|
|
|
|
|
|
|
|
|
rootFilePath = selectedPath;
|
|
|
|
|
//表头
|
|
|
|
|
string size = GetFileSize(GetDirectoryLength(selectedPath));
|
|
|
|
|
LayerCfg node = new LayerCfg()
|
|
|
|
|
{
|
|
|
|
|
IsChecked = true,
|
|
|
|
|
LayerName = titleName,
|
|
|
|
|
FcPath = selectedPath,
|
|
|
|
|
FileSize = size,
|
|
|
|
|
LayerType = EnumLayerType.GroupLayer,
|
|
|
|
|
AbsolutePathType = "AddLayerWay" //标记为外部路径数据
|
|
|
|
|
};
|
|
|
|
|
nodes.Add(node);
|
|
|
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(selectedPath);
|
|
|
|
|
GetChildren(directoryInfo, node);
|
|
|
|
|
LoadFileDataPath(selectedPath);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("选择基础数据库失败:" + ex);
|
|
|
|
|
ProgressHelper.CloseProcessBar();
|
|
|
|
|
MessageHelper.Show("选择基础数据库失败:" + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetPathIDPID(string path, out LayerCfg parentLayer)
|
|
|
|
|
{
|
|
|
|
|
parentLayer = null;
|
|
|
|
|
if (string.IsNullOrEmpty(path)) return;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (LayerCfg item in nodes)
|
|
|
|
|
{
|
|
|
|
|
if (item.FcPath == path)
|
|
|
|
|
{
|
|
|
|
|
parentLayer = item;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (parentLayer == null)
|
|
|
|
|
{
|
|
|
|
|
path = path.Substring(0, path.LastIndexOf('\\'));
|
|
|
|
|
GetPathIDPID(path, out parentLayer);
|
|
|
|
|
//path = path.Substring(0, path.LastIndexOf('\\'));
|
|
|
|
|
//foreach (LayerCfg item in nodes)
|
|
|
|
|
//{
|
|
|
|
|
// if (item.FcPath == path)
|
|
|
|
|
// {
|
|
|
|
|
// parentLayer = item;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("获取数据失败:" + ex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private long GetDirectoryLength(string dirPath)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(dirPath))
|
|
|
|
|
return FileSize(dirPath);
|
|
|
|
|
long len = 0;
|
|
|
|
|
DirectoryInfo di = new DirectoryInfo(dirPath);
|
|
|
|
|
foreach (FileInfo fi in di.GetFiles())
|
|
|
|
|
{
|
|
|
|
|
len += fi.Length;
|
|
|
|
|
}
|
|
|
|
|
DirectoryInfo[] dis = di.GetDirectories();
|
|
|
|
|
if (dis.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < dis.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
len += GetDirectoryLength(dis[i].FullName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("获取文件大小失败:" + ex);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private long FileSize(string filePath)
|
|
|
|
|
{
|
|
|
|
|
long temp = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(filePath) == false)
|
|
|
|
|
{
|
|
|
|
|
string[] str1 = Directory.GetFileSystemEntries(filePath);
|
|
|
|
|
foreach (string s1 in str1)
|
|
|
|
|
{
|
|
|
|
|
temp += FileSize(s1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FileInfo fileInfo = new FileInfo(filePath);
|
|
|
|
|
return fileInfo.Length;
|
|
|
|
|
}
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("计算文件大小失败:" + e);
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetFileSize(long filesize)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (filesize <= 0) { return "0"; }
|
|
|
|
|
else if (filesize >= 1024 * 1024 * 1024) //文件大小大于或等于1024MB
|
|
|
|
|
{
|
|
|
|
|
return string.Format("{0:0.00} GB", (double)filesize / (1024 * 1024 * 1024));
|
|
|
|
|
}
|
|
|
|
|
else if (filesize >= 1024 * 1024) //文件大小大于或等于1024KB
|
|
|
|
|
{
|
|
|
|
|
return string.Format("{0:0.00} MB", (double)filesize / (1024 * 1024));
|
|
|
|
|
}
|
|
|
|
|
else if (filesize >= 1024) //文件大小大于等于1024bytes
|
|
|
|
|
{
|
|
|
|
|
return string.Format("{0:0.00} KB", (double)filesize / 1024);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return string.Format("{0:0.00} bytes", filesize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("计算文件大小失败:" + ex);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetOtherDataPath(string dirPath, List<string> pathList)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string[] dirArr = Directory.GetDirectories(dirPath);
|
|
|
|
|
string[] fileArr = Directory.GetFiles(dirPath);
|
|
|
|
|
|
|
|
|
|
// 遍历所有文件
|
|
|
|
|
if (fileArr.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
string fileName;
|
|
|
|
|
foreach (string file in fileArr)
|
|
|
|
|
{
|
|
|
|
|
fileName = System.IO.Path.GetFileName(file);
|
|
|
|
|
if ((fileName.ToLower().EndsWith(".vct") || fileName.ToLower().EndsWith(".mdb") || fileName.ToLower().EndsWith(".shp") || fileName.ToLower().EndsWith(".tif") || fileName.ToLower().EndsWith(".tiff") || fileName.ToLower().EndsWith(".img") || fileName.ToLower().EndsWith(".jpg") || fileName.ToLower().EndsWith(".jpeg") || fileName.ToLower().EndsWith(".png")) && !pathList.Contains(file))
|
|
|
|
|
{
|
|
|
|
|
pathList.Add(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 遍历所有文件夹
|
|
|
|
|
if (dirArr.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
string folderName;
|
|
|
|
|
string dir;
|
|
|
|
|
for (int i = 0; i < dirArr.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
dir = dirArr[i];
|
|
|
|
|
//if (GetFileSize(GetDirectoryLength(dir)) == "0" && (Directory.GetDirectories(dir).Length == 0 || Directory.GetFiles(dir).Length == 0)) continue;
|
|
|
|
|
folderName = System.IO.Path.GetFileName(dir);
|
|
|
|
|
if (!pathList.Contains(dir))
|
|
|
|
|
{
|
|
|
|
|
pathList.Add(dir);
|
|
|
|
|
}
|
|
|
|
|
GetOtherDataPath(dir, pathList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("获取数据文件失败:" + ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetEnvelopeBorder()
|
|
|
|
|
{
|
|
|
|
|
List<ILayer> MapLayerList = MapsManager.Instance.MapService.GetAllLayerInMap<ILayer>();
|
|
|
|
|
List<ILayer> SelectLayerList = new List<ILayer>();
|
|
|
|
|
|
|
|
|
|
foreach (ILayer item in MapLayerList)
|
|
|
|
|
{
|
|
|
|
|
if ((item as RasterLayer) != null || (item as KOTilesLayer) != null)
|
|
|
|
|
{
|
|
|
|
|
m_featureLayer = item;
|
|
|
|
|
if (CurrentEnvelope == null)
|
|
|
|
|
CurrentEnvelope = item.AreaOfInterest;
|
|
|
|
|
else
|
|
|
|
|
CurrentEnvelope.Union(item.AreaOfInterest);
|
|
|
|
|
SelectLayerList.Add(item);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (SelectLayerList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (ILayer item in MapLayerList)
|
|
|
|
|
{
|
|
|
|
|
if ((item as IFeatureLayer) != null)
|
|
|
|
|
{
|
|
|
|
|
if ((item as IFeatureLayer).FeatureClass.FeatureCount(null) == 0) continue;
|
|
|
|
|
m_featureLayer = item;
|
|
|
|
|
//确保最大范围
|
|
|
|
|
if (CurrentEnvelope == null)
|
|
|
|
|
CurrentEnvelope = item.AreaOfInterest;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IEnvelope env = item.AreaOfInterest;
|
|
|
|
|
//if (env != null)
|
|
|
|
|
// CurrentEnvelope.Union(env);
|
|
|
|
|
|
|
|
|
|
if (env.XMin < 0 || env.YMin < 0) continue;
|
|
|
|
|
if (env.XMax > CurrentEnvelope.XMax)
|
|
|
|
|
{
|
|
|
|
|
CurrentEnvelope.XMax = env.XMax;
|
|
|
|
|
}
|
|
|
|
|
if (env.YMax > CurrentEnvelope.YMax)
|
|
|
|
|
{
|
|
|
|
|
CurrentEnvelope.YMax = env.YMax;
|
|
|
|
|
}
|
|
|
|
|
if (env.XMin < CurrentEnvelope.XMin)
|
|
|
|
|
{
|
|
|
|
|
CurrentEnvelope.XMin = env.XMin;
|
|
|
|
|
}
|
|
|
|
|
if (env.YMin < CurrentEnvelope.YMin)
|
|
|
|
|
{
|
|
|
|
|
CurrentEnvelope.YMin = env.YMin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
SelectLayerList.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
IEnvelope envelope = CurrentEnvelope;
|
|
|
|
|
if (envelope == null) return;
|
|
|
|
|
IFeatureCursor insertCur = null;
|
|
|
|
|
IFeatureBuffer newFeature = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Rectangle wjfw = new Rectangle();
|
|
|
|
|
wjfw.MinX = envelope.XMin;
|
|
|
|
|
wjfw.MaxX = envelope.XMax;
|
|
|
|
|
wjfw.MaxY = envelope.YMax;
|
|
|
|
|
wjfw.MinY = envelope.YMin;
|
|
|
|
|
List<BHTBFramingDatas> bwtfList = GetBWTFH(wjfw);
|
|
|
|
|
if (bwtfList.Count == 0) return;
|
|
|
|
|
|
|
|
|
|
IFeatureClass featureClass = MapsManager.Instance.MapService.GetFeatureClassByName("ZYQ");
|
|
|
|
|
if (featureClass == null) return;
|
|
|
|
|
(featureClass as ITable).DeleteSearchedRows(null);
|
|
|
|
|
ISpatialReference spr = (featureClass as IGeoDataset).SpatialReference;
|
|
|
|
|
insertCur = featureClass.Insert(true);
|
|
|
|
|
int k = 0;
|
|
|
|
|
foreach (var item in bwtfList)
|
|
|
|
|
{
|
|
|
|
|
k++;
|
|
|
|
|
newFeature = featureClass.CreateFeatureBuffer();
|
|
|
|
|
newFeature.Shape = GetGeoByWJFW(item.WJFW, spr);//同时转换坐标系统
|
|
|
|
|
newFeature.set_Value(newFeature.Fields.FindField("ZYQBH"), item.TFH);
|
|
|
|
|
newFeature.set_Value(newFeature.Fields.FindField("ZYQMC"), item.TBName);
|
|
|
|
|
newFeature.set_Value(newFeature.Fields.FindField("ZYQZT"), 0);
|
|
|
|
|
newFeature.set_Value(newFeature.Fields.FindField("HH"), item.HH);
|
|
|
|
|
newFeature.set_Value(newFeature.Fields.FindField("LH"), item.LH);
|
|
|
|
|
insertCur.InsertFeature(newFeature);
|
|
|
|
|
if (k % 500 == 0)
|
|
|
|
|
{
|
|
|
|
|
k = 0;
|
|
|
|
|
insertCur.Flush();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (k > 0)
|
|
|
|
|
{
|
|
|
|
|
insertCur.Flush();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("图斑分幅时发生异常,异常信息如下:");
|
|
|
|
|
LogAPI.Debug(ex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (insertCur != null)
|
|
|
|
|
Marshal.ReleaseComObject(insertCur);
|
|
|
|
|
if (newFeature != null)
|
|
|
|
|
Marshal.ReleaseComObject(newFeature);
|
|
|
|
|
|
|
|
|
|
GC.Collect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<BHTBFramingDatas> GetBWTFH(Rectangle wjfw)
|
|
|
|
|
{
|
|
|
|
|
if (wjfw == null) return null;
|
|
|
|
|
List<BHTBFramingDatas> bwtfList = new List<BHTBFramingDatas>();
|
|
|
|
|
IIdentify indentify = null;
|
|
|
|
|
IGeometry pGeometry = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (m_featureLayer != null)
|
|
|
|
|
indentify = m_featureLayer as IIdentify;
|
|
|
|
|
double xlength = wjfw.MaxX - wjfw.MinX;
|
|
|
|
|
double ylength = wjfw.MaxY - wjfw.MinY;
|
|
|
|
|
int xCount = (int)Math.Ceiling(xlength / FramingSize);
|
|
|
|
|
int yCount = (int)Math.Ceiling(ylength / FramingSize);
|
|
|
|
|
int num = 0;
|
|
|
|
|
for (int y = 0; y < yCount; y++)
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < xCount; x++)
|
|
|
|
|
{
|
|
|
|
|
Rectangle rectangle = new Rectangle()
|
|
|
|
|
{
|
|
|
|
|
MinX = wjfw.MinX + x * FramingSize,
|
|
|
|
|
MinY = wjfw.MinY + y * FramingSize,
|
|
|
|
|
MaxX = wjfw.MinX + (x + 1) * FramingSize,
|
|
|
|
|
MaxY = wjfw.MinY + (y + 1) * FramingSize
|
|
|
|
|
};
|
|
|
|
|
if (rectangle.MaxX > wjfw.MaxX)
|
|
|
|
|
{
|
|
|
|
|
rectangle.MaxX = wjfw.MaxX;
|
|
|
|
|
}
|
|
|
|
|
if (rectangle.MaxY > wjfw.MaxY)
|
|
|
|
|
{
|
|
|
|
|
rectangle.MaxY = wjfw.MaxY;
|
|
|
|
|
}
|
|
|
|
|
if (indentify != null)
|
|
|
|
|
{
|
|
|
|
|
IEnvelope envelope = new EnvelopeClass();
|
|
|
|
|
envelope.XMax = rectangle.MaxX;
|
|
|
|
|
envelope.XMin = rectangle.MinX;
|
|
|
|
|
envelope.YMax = rectangle.MaxY;
|
|
|
|
|
envelope.YMin = rectangle.MinY;
|
|
|
|
|
pGeometry = envelope as IGeometry;
|
|
|
|
|
if (pGeometry != null)
|
|
|
|
|
{
|
|
|
|
|
IArray pIDs = indentify.Identify(pGeometry);
|
|
|
|
|
if (pIDs == null || pIDs.Count == 0) continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
num++;
|
|
|
|
|
BHTBFramingDatas bwtf = new BHTBFramingDatas();
|
|
|
|
|
bwtf.TFH = "ZYQ" + num.ToString("000000");
|
|
|
|
|
bwtf.TBName = "作业区_" + num.ToString("000000");
|
|
|
|
|
bwtf.IsModify = "否";
|
|
|
|
|
bwtf.HH = x;
|
|
|
|
|
bwtf.LH = y;
|
|
|
|
|
bwtf.WJFW = rectangle;
|
|
|
|
|
bwtfList.Add(bwtf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bwtfList;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("图斑分幅错误:" + ex);
|
|
|
|
|
return bwtfList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IGeometry GetGeoByWJFW(Rectangle reg, ISpatialReference spr)
|
|
|
|
|
{
|
|
|
|
|
ArrayList result = new ArrayList();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result.Add((byte)1);//顺序
|
|
|
|
|
result.AddRange(BitConverter.GetBytes(3));//类型 面
|
|
|
|
|
result.AddRange(BitConverter.GetBytes(1));//环数
|
|
|
|
|
ArrayList jmdArray = new ArrayList();
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MinX));
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MinY));
|
|
|
|
|
//上边
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MinX));
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MaxY));
|
|
|
|
|
//右边
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MaxX));
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MaxY));
|
|
|
|
|
//下边
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MaxX));
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MinY));
|
|
|
|
|
//首尾相连
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MinX));
|
|
|
|
|
jmdArray.AddRange(BitConverter.GetBytes((double)reg.MinY));
|
|
|
|
|
result.AddRange(BitConverter.GetBytes(jmdArray.Count / 16));
|
|
|
|
|
result.AddRange(jmdArray);
|
|
|
|
|
|
|
|
|
|
byte[] wkb = (byte[])result.ToArray(typeof(byte));
|
|
|
|
|
|
|
|
|
|
IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;
|
|
|
|
|
IGeometry geom;
|
|
|
|
|
int countin = wkb.GetLength(0);
|
|
|
|
|
factory.CreateGeometryFromWkbVariant(wkb, out geom, out countin);
|
|
|
|
|
|
|
|
|
|
if ((geom as IArea).Area < 0)
|
|
|
|
|
{
|
|
|
|
|
IPolygon pPolygon = geom as IPolygon;
|
|
|
|
|
pPolygon.ReverseOrientation();
|
|
|
|
|
}
|
|
|
|
|
if (geom == null) return null;
|
|
|
|
|
return geom;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("获取分幅后的图斑形状异常:" + ex);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MarkLayer()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
IFeatureLayer pFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("ZYQ");
|
|
|
|
|
if (pFeatureLayer == null) return;
|
|
|
|
|
IGeoFeatureLayer pGeoLayer = pFeatureLayer as IGeoFeatureLayer;
|
|
|
|
|
IRgbColor pColor = new RgbColorClass() { Red = 85, Blue = 105, Green = 255 };
|
|
|
|
|
stdole.IFontDisp pFont = new stdole.StdFont()
|
|
|
|
|
{
|
|
|
|
|
Name = "宋体",
|
|
|
|
|
//Bold = true
|
|
|
|
|
} as stdole.IFontDisp;
|
|
|
|
|
|
|
|
|
|
ITextSymbol pTextSymbol = new TextSymbolClass()
|
|
|
|
|
{
|
|
|
|
|
Color = pColor,
|
|
|
|
|
Font = pFont,
|
|
|
|
|
Size = 8
|
|
|
|
|
};
|
|
|
|
|
IBasicOverposterLayerProperties pBasicOverLayerPro = new BasicOverposterLayerPropertiesClass();
|
|
|
|
|
pBasicOverLayerPro.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
|
|
|
|
|
pBasicOverLayerPro.GenerateUnplacedLabels = true;
|
|
|
|
|
pBasicOverLayerPro.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;
|
|
|
|
|
|
|
|
|
|
ILabelEngineLayerProperties pLableEngine = new LabelEngineLayerPropertiesClass()
|
|
|
|
|
{
|
|
|
|
|
Symbol = pTextSymbol,
|
|
|
|
|
IsExpressionSimple = true
|
|
|
|
|
};
|
|
|
|
|
IOverposterLayerProperties2 pOverLayerProper = pBasicOverLayerPro as IOverposterLayerProperties2;
|
|
|
|
|
pOverLayerProper.TagUnplaced = true;//设置该属性,目的是不被其他element遮挡
|
|
|
|
|
pLableEngine.BasicOverposterLayerProperties = pBasicOverLayerPro;
|
|
|
|
|
IAnnotateLayerProperties pAnnoPros = pLableEngine as IAnnotateLayerProperties;
|
|
|
|
|
pGeoLayer.AnnotationProperties.Add(pAnnoPros);
|
|
|
|
|
pGeoLayer.DisplayAnnotation = true;
|
|
|
|
|
AxMapControl axMapControl1 = MapsManager.Instance.MapService.getAxMapControl();
|
|
|
|
|
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, axMapControl1.Extent);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogAPI.Debug("设置标注时发生异常,异常信息如下:" + ex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Rectangle
|
|
|
|
|
{
|
|
|
|
|
public double MaxX { get; set; }
|
|
|
|
|
public double MaxY { get; set; }
|
|
|
|
|
public double MinX { get; set; }
|
|
|
|
|
public double MinY { get; set; }
|
|
|
|
|
}
|
|
|
|
|
public class BHTBFramingDatas
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图幅号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string TFH { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图斑名称
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string TBName { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否已修改
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string IsModify { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 外接范围
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Rectangle WJFW { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 行号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int HH { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 列号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int LH { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|