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

3652 lines
156 KiB

using System;
using System.Collections.Generic;
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.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.Mobile.Shape2KOTool.KoDataBase;
using Kingo.Mobile.Shape2KOTool.XSDClass;
using Kingo.Plugin.MakeTaskPackage.Entity;
using Kingo.Plugin.MakeTaskPackage.Common;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils.Dialog;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using Kingo.Plugin.MakeTaskPackage.Model;
using System.Threading;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Data;
using System.Data.OleDb;
using System.IO;
using KGIS.Framework.OpenData.Control;
using KGIS.Framework.OpenData.Filter;
using KGIS.Framework.OpenData.InterFace;
using ESRI.ArcGIS.esriSystem;
using System.Xml;
using Raster2KOTiles;
using System.Diagnostics;
using Kingo.PluginServiceInterface;
using UIShell.OSGi;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Utils.Utility;
using KGIS.Framework.Platform;
using DevExpress.Xpf.Grid;
using DevExpress.Data.TreeList;
using static Kingo.Plugin.MakeTaskPackage.Model.MakeTaskPackageModel;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.DataSourcesRaster;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using System.Runtime.InteropServices;
using KGIS.Framework.ThreadManager;
using System.ComponentModel;
namespace Kingo.Plugin.MakeTaskPackage.View
{
/// <summary>
/// FrmMakeTaskPackage.xaml 的交互逻辑
/// </summary>
public partial class FrmMakeTaskPackage : BaseWindow
{
private IFeatureClass pCustomFC = null;
private bool isCustom = false;
private List<string> selectedXzq = new List<string>();
private int koIndex = 0;
private int createCount = 0;
private List<KODBFeatureLayer> lstPLayers = null;
private List<MakeTaskPackageModel> exportDataList = null;
private List<MakeTaskPackageModel> rasterDataList = null;
private string exportFolder = string.Empty;
private int currentIndex = 0;
private string keyField { get; set; }
private string WhereStr { get; set; }
private double maxDis = 0;
private string tilesType = "png";
private int tileSize = 512;
private int sectionlevel = 7;
private int threadNum = 3;
private bool convertWebMercator = false;
List<Thread> openThreads = new List<Thread>();
private LayerConfig cfg_JZRW = new LayerConfig();
private LayerConfig cfg_OneMap = new LayerConfig();
private bool exportSuccess = true;
private string errorMsg = string.Empty;
private string customLayerPath = string.Empty;
private string customLayerName = string.Empty;
private Dictionary<string, OSGeo.OGR.Geometry> geometrys = new Dictionary<string, OSGeo.OGR.Geometry>();
private double distance = 100.0;
private OSGeo.OGR.Layer toplayer = null;
private List<MakeTaskPackageModel> delModelList = null;
private IBundle bundle = null;
private TaskPackagePathConfig taskPackagePathConfig = null;
private OutputPath outputPathCfg = null;
private FrmXZQSelected frmXZQSelected = null;
private int selectedRWDCZTIndex = 1;
public FrmMakeTaskPackage()
{
InitializeComponent();
this.Closing += FrmMobileDataExport_Closing;
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void rdoAll_Click(object sender, RoutedEventArgs e)
{
this.txtExtentData.Text = string.Empty;
this.txtExtentData.IsEnabled = false;
this.btnSelectExtentData.IsEnabled = false;
}
private void RdoCustom_Click(object sender, RoutedEventArgs e)
{
this.txtExtentData.IsEnabled = true;
this.btnSelectExtentData.IsEnabled = true;
}
private void BtnExport_Click(object sender, RoutedEventArgs e)
{
try
{
if (this.exportDataList == null || this.exportDataList.Count == 0)
{
MessageHelper.Show("未查询到需要导出的数据,请检查数据是否存在!");
return;
}
if (string.IsNullOrWhiteSpace(this.txtExportPath.Text))
{
MessageHelper.Show("请先选择导出位置!");
return;
}
if (this.rdoCustom.IsChecked == true)
{
if (selectedXzq == null || selectedXzq.Count <= 0)
{
MessageHelper.Show("请导入范围或者选着全部");
return;
}
else
isCustom = true;
}
else
{
isCustom = false;
}
this.btnExport.IsEnabled = false;
if (!Isint(this.txtTilesize.Text, out int titlesize))
{
MessageHelper.Show("瓦片尺寸必须为整数");
return;
}
if (!Isint(this.txtSectionlevel.Text, out int sectionlevel))
{
MessageHelper.Show("切片级别必须为整数");
return;
}
if (sectionlevel > 12)
{
MessageHelper.Show("切片级别不能大于12");
return;
}
if (!Isint(this.txtThreadnum.Text, out int threadnum))
{
MessageHelper.Show("线程数必须为整数");
return;
}
if (threadnum > 10)
{
MessageHelper.Show("线程数不能大于10");
return;
}
if (!double.TryParse(this.txtBufferdistance.Text, out double bufferdistance))
{
MessageHelper.Show("缓冲距离必须为数字");
return;
}
exportFolder = this.txtExportPath.Text + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss");
if (!Directory.Exists(exportFolder))
Directory.CreateDirectory(exportFolder);
if (this.comTieletype.SelectedValue != null)
this.tilesType = this.comTieletype.SelectedValue.ToString().ToLower();
this.tileSize = titlesize;
this.sectionlevel = sectionlevel;
this.threadNum = threadnum;
if (this.checkWebMercator.IsChecked == true)
this.convertWebMercator = true;
this.selectedRWDCZTIndex = this.comRWDCZT.SelectedIndex;
string msg = CheckFieldValue();
if (!string.IsNullOrWhiteSpace(msg))
{
MessageHelper.Show(msg);
this.btnExport.IsEnabled = true;
return;
}
ExportDataByGeometry();
if (this.rdoWYDHRWB.IsChecked == true)
ExportQueryDB();
}
catch (Exception ex)
{
LogAPI.Debug("数据导出失败:" + ex);
MessageHelper.Show("数据导出失败:" + ex);
}
}
private bool Isint(string str, out int result)
{
return int.TryParse(str, out result);
}
public void ExportKO()
{
try
{
lstPLayers = new List<KODBFeatureLayer>();
List<MakeTaskPackageModel> exportDatalist = this.rwzzTreeList.ItemsSource as List<MakeTaskPackageModel>;
for (int i = 0; i < exportDatalist.Count; i++)
{
if (exportDatalist[i].Type == "图层组")
{
continue;
}
if (!exportDatalist[i].IsCheck)
{
continue;
}
if (exportDatalist[i].Layer is List<IRasterLayer>)
{
List<IRasterLayer> imgsList = exportDatalist[i].Layer as List<IRasterLayer>;
if (imgsList == null || imgsList.Count <= 0)
continue;
MakeTaskPackageModel rasterDataExportModel = exportDatalist[i] as MakeTaskPackageModel;
if (isCustom && geometrys != null && geometrys.Count != 0)
{
for (int j = 0; j < geometrys.Count; j++)
{
string packName = geometrys.ElementAt(j).Key;
rasterDataExportModel.CustomPackName = packName;
// rasterDataExportModel.CurrentIndex = 0;
//ThreadPool.QueueUserWorkItem(new WaitCallback(CreateKotilesImg), rasterDataExportModel);
ThreadManager.Instance.QueueUserWorkItem(new WaitCallback(CreateKotilesImg), rasterDataExportModel);
createCount++;
}
}
else
{
//rasterDataExportModel.CurrentIndex = 0;
//ThreadPool.QueueUserWorkItem(new WaitCallback(CreateKotilesImg), rasterDataExportModel);
ThreadManager.Instance.QueueUserWorkItem(new WaitCallback(CreateKotilesImg), rasterDataExportModel);
createCount++;
}
}
else
{
MakeTaskPackageModel shpDataExportModel = exportDatalist[i] as MakeTaskPackageModel;
if (shpDataExportModel == null) continue;
if (shpDataExportModel.Type == "瓦片")
{
shpDataExportModel.GridRowIndex = i;
mxdIndex = 0;
MxdParameters mxdParameters = new MxdParameters()
{
SaveFileName = shpDataExportModel.FileName,
ThreadNum = 3,
TileSize = Convert.ToInt32(this.txtTilesize.Text),
MinLevel = Convert.ToInt32(this.txtSectionlevel.Text),
MaxScale = Convert.ToInt32(this.txtMaxScale.Text),
MinScale = Convert.ToInt32(this.comMinScale.SelectedItem)
};
shpDataExportModel.MxdCutParameters = mxdParameters;
Thread threadKotiles = new Thread(new ParameterizedThreadStart(ExportKotilesParame));
threadKotiles.SetApartmentState(ApartmentState.STA);
threadKotiles.IsBackground = true;
threadKotiles.Start(shpDataExportModel);
createCount++;
}
else
{
if (isCustom && selectedXzq != null && selectedXzq.Count != 0)
{
for (int j = 0; j < selectedXzq.Count; j++)
{
shpDataExportModel.CustomPackName = selectedXzq[j];
ThreadManager.Instance.QueueUserWorkItem(new WaitCallback(ExportVectorKoThread), shpDataExportModel);
createCount++;
}
}
else
{
ThreadManager.Instance.QueueUserWorkItem(new WaitCallback(ExportVectorKoThread), shpDataExportModel);
createCount++;
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("数据导出失败:" + ex);
}
}
private void ExportDataByGeometry()
{
try
{
if (this.rdoWYDHRWB.IsChecked == true)
ExportKO();
else
{
List<MakeTaskPackageModel> exportDatalist = this.rwzzTreeList.ItemsSource as List<MakeTaskPackageModel>;
for (int i = 0; i < exportDatalist.Count; i++)
{
if (exportDatalist[i].Type == "图层组")
{
continue;
}
if (!exportDatalist[i].IsCheck)
{
continue;
}
MakeTaskPackageModel shpDataExportModel = exportDatalist[i] as MakeTaskPackageModel;
ExportWRJ(shpDataExportModel);
}
}
if (createCount == 0)
{
MessageHelper.Show("导出成功");
this.btnExport.IsEnabled = true;
}
}
catch (Exception ex)
{
LogAPI.Debug("数据导出失败:" + ex);
}
}
public ILayer FindLayer(string mxdPath, string layerName)
{
IMapDocument pMapDocument = null;
try
{
if (!File.Exists(mxdPath)) return null;
pMapDocument = new MapDocumentClass();
pMapDocument.Open(mxdPath);
IMap map = pMapDocument.get_Map(0);
if (map == null || map.LayerCount == 0) return null;
ILayer layer = null;
for (int i = 0; i < map.LayerCount; i++)
{
layer = GetLayer(map.get_Layer(i), layerName);
if (layer != null)
break;
}
return layer;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return null;
}
finally
{
if (pMapDocument != null)
pMapDocument.Close();
}
}
private ILayer GetLayer(ILayer layer, string layername)
{
try
{
if (layer is IGroupLayer)
{
IGroupLayer group = layer as IGroupLayer;
ILayerGeneralProperties lp = group as ILayerGeneralProperties;
ICompositeLayer pComLayer = layer as ICompositeLayer;
for (int j = 0; j < pComLayer.Count; j++)
{
ILayer lay = GetLayer(pComLayer.get_Layer(j), layername);
if (lay != null)
return lay;
}
}
if (layer.Name.ToUpper().Equals(layername.ToUpper()))
return layer;
return null;
}
catch (Exception ex)
{
throw ex;
}
}
private void ExportVectorKoThread(object obj)
{
string layerName = string.Empty;
try
{
MakeTaskPackageModel model = obj as MakeTaskPackageModel;
if (model.Type == "图层组")
return;
string newFilePath = System.IO.Path.Combine(exportFolder, model.OutPath);
string packName = "Data";
if (!string.IsNullOrWhiteSpace(model.TaskName))
{
packName = model.TaskName;
}
if (isCustom)
{
if (!Directory.Exists(newFilePath))
Directory.CreateDirectory(newFilePath);
packName = model.CustomPackName;
}
newFilePath = System.IO.Path.Combine(newFilePath, packName, "Source");
if (!System.IO.Directory.Exists(newFilePath))
System.IO.Directory.CreateDirectory(newFilePath);
int layerIndex = exportDataList.IndexOf(model);
if (layerIndex == -1) return;
CreateConfig(((model.Layer as IFeatureLayer) as IGeoDataset).SpatialReference.FactoryCode);
string strLayerPath = string.Format("\"" + model.LayerSource + "\"");
string strLayerName = string.Format("\"" + model.FileName + "\"");
string strOutputPath = string.Format("\"" + newFilePath + "\"");
string strWhere = string.Format("\"" + model.FilterWhere + "\"");
string customLayerPath = string.Format("\"" + this.customLayerPath + "\"");
string customLayerName = string.Format("\"" + this.customLayerName + "\"");
string customstrWhere = string.Format("\"" + this.WhereStr + "\"");
string customKeyValue = string.Format("\"" + packName + "\"");
var psi = new ProcessStartInfo("Kingo.Plugin.ShapeToKOApp.exe", string.Format("{0} {1} {2} {3} {4} {5} {6} {7} ", strLayerPath, strLayerName, strOutputPath, strWhere, customLayerPath, customLayerName, customstrWhere, customKeyValue));
string a = psi.Arguments;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
var pes = Process.Start(psi);
var sout = pes.StandardOutput;
while (!sout.EndOfStream)
{
var line = sout.ReadLine();
if (string.IsNullOrEmpty(line)) continue;
if (line.ToString().Contains(";"))
{
string[] strArr = line.ToString().Split(';');
if (strArr.Length == 2)
{
this.exportDataList[layerIndex].CurrNum = Convert.ToInt32(strArr[0]);
this.exportDataList[layerIndex].FcCount = Convert.ToInt32(strArr[1]);
}
else if (strArr.Length == 3)
{
this.exportDataList[layerIndex].Make = strArr[0];
this.exportDataList[layerIndex].CurrNum = Convert.ToInt32(strArr[1]);
this.exportDataList[layerIndex].FcCount = Convert.ToInt32(strArr[2]);
}
else
{
this.exportDataList[layerIndex].FcCount = 100;
this.exportDataList[layerIndex].CurrNum = 100;
}
}
else
{
this.exportDataList[layerIndex].Make = line.ToString();
}
}
pes.WaitForExit();
pes.Close();
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
this.exportDataList[layerIndex].OutFilePath = System.IO.Path.Combine(model.OutPath, packName, "Source", model.FileName + ".kotiles");
createCount--;
if (createCount == 0)
{
FunctionOutXml outxml = new FunctionOutXml();
outxml.SaveConfig(exportDataList, isCustom, exportFolder, selectedXzq);
if (this.exportSuccess == true)
{
List<MakeTaskPackageModel> jzrwModelList = exportDataList.FindAll(x => x.Type.Contains("举证任务") && (x.FileName == "JCTB" || x.FileName == "监测图斑"));
if (jzrwModelList != null && jzrwModelList.Count != 0)
{
IQueryFilter pQuery = new QueryFilterClass();
foreach (MakeTaskPackageModel item in jzrwModelList)
{
if (!item.Make.Contains("完成"))
continue;
IFeatureLayer featureLayer = item.Layer as IFeatureLayer;
if (featureLayer != null && featureLayer.FeatureClass != null && !string.IsNullOrWhiteSpace(item.FilterWhere))
{
pQuery.WhereClause = item.FilterWhere;
IFeatureCursor featureCursor = featureLayer.FeatureClass.Update(pQuery, true);
IFeature feature = null;
int dcztIdx = featureLayer.FeatureClass.FindField("RWDCZT");//任务导出状态,数据导出成功后,更新导出状态为已制作
int wyzzsjIdx = featureLayer.FeatureClass.FindField("WYZZSJ");//外业制作时间
DateTime dateTime = DateTime.Now;
while ((feature = featureCursor.NextFeature()) != null)
{
if (dcztIdx != -1)
feature.Value[dcztIdx] = "已制作";
if (wyzzsjIdx != -1)
feature.Value[wyzzsjIdx] = dateTime;
featureCursor.UpdateFeature(feature);
}
featureCursor.Flush();
Thread.Sleep(3000);
}
}
}
MessageHelper.Show("导出成功");
}
else
{
MessageHelper.Show("导出失败:\r\n" + errorMsg);
}
this.btnExport.IsEnabled = true;
}
}));
}
catch (Exception ex)
{
LogAPI.Debug("矢量数据导入KO失败:" + ex);
this.exportSuccess = false;
errorMsg += string.Format("{0}矢量数据导入KO失败:{1}\r\n", layerName, ex.Message);
createCount--;
}
}
private void ExportVectorKoThread1(object obj)
{
string layerName = string.Empty;
IWorkspaceFactory pWSFactory = null;
try
{
MakeTaskPackageModel model = obj as MakeTaskPackageModel;
IGeometry geometryNow = null;
if (model.Type == "图层组")
return;
string newFilePath = System.IO.Path.Combine(exportFolder, model.OutPath);
string packName = "Data";
if (!string.IsNullOrWhiteSpace(model.TaskName))
{
packName = model.TaskName;
}
if (isCustom)
{
packName = selectedXzq[model.CurrentIndex];
if (!Directory.Exists(newFilePath))
Directory.CreateDirectory(newFilePath);
geometryNow = XzqGeometry(selectedXzq[model.CurrentIndex], keyField);
}
newFilePath = System.IO.Path.Combine(newFilePath, packName, "Source");
layerName = model.FileAliasName;
if (!System.IO.Directory.Exists(newFilePath))
System.IO.Directory.CreateDirectory(newFilePath);
int layerIndex = exportDataList.IndexOf(model);
if (layerIndex == -1) return;
KODBFeatureLayer pLayer = null;
pLayer = new KODBFeatureLayer();
pLayer.LayerIndex = model.LayerIndex;
ILayer featureLayer = null;
if (!string.IsNullOrWhiteSpace(model.LayerSource))
{
string filename = System.IO.Path.GetDirectoryName(model.LayerSource);
if (model.LayerSource.ToLower().Contains(".shp"))
{
pWSFactory = new ShapefileWorkspaceFactoryClass();
}
else if (model.LayerSource.ToLower().Contains(".gdb"))
{
pWSFactory = new FileGDBWorkspaceFactory();
string fileExtension = System.IO.Path.GetExtension(filename);
if (string.IsNullOrWhiteSpace(fileExtension))
{
filename = System.IO.Path.GetDirectoryName(filename);
}
}
else if (model.LayerSource.ToLower().Contains(".mdb"))
{
pWSFactory = new AccessWorkspaceFactory();
string fileExtension = System.IO.Path.GetExtension(filename);
if (string.IsNullOrWhiteSpace(fileExtension))
{
filename = System.IO.Path.GetDirectoryName(filename);
}
}
if (model.LayerSource.ToLower().Contains(".mxd"))
{
featureLayer = FindLayer(model.LayerSource, (model.Layer as ILayer).Name);
}
else if (model.LayerSource.ToLower().Contains(".tif") || model.LayerSource.ToLower().Contains(".tiff") || model.LayerSource.ToLower().Contains(".img"))
{
string Path = System.IO.Path.GetDirectoryName(model.LayerSource); //获取文件路径
string strFileName = System.IO.Path.GetFileName(model.LayerSource); //获取栅格文件名
IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(Path, 0);
IRasterWorkspace pRasterWorkspace = pWorkspace as IRasterWorkspace;
IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(strFileName);
IRaster pRaster = pRasterDataset.CreateDefaultRaster();
IRasterLayer pRasterLayer = new RasterLayer();
pRasterLayer.CreateFromRaster(pRaster);
featureLayer = pRasterLayer as ILayer;
}
else
{
IWorkspace pWorkspace = pWSFactory.OpenFromFile(filename, 0);
System.Runtime.InteropServices.Marshal.ReleaseComObject(pWSFactory);
pWSFactory = null;
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pSourceFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(model.LayerSource));
if (pSourceFeatureClass != null)
{
IFeatureLayer layer = new FeatureLayerClass();
layer.FeatureClass = pSourceFeatureClass;
featureLayer = layer;
}
}
}
else
{
string path = ((model.Layer as IFeatureLayer).FeatureClass as FeatureClass).Workspace.PathName;
KGIS.Framework.AE.IWorkspaceAPI wsAPI = new KGIS.Framework.AE.WorkspaceAPI(path, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile);
KGIS.Framework.AE.IFeatureClassAPI fcAPI = wsAPI.OpenFeatureClass(((model.Layer as IFeatureLayer).FeatureClass as FeatureClass).BrowseName);
featureLayer = new FeatureLayerClass() { FeatureClass = fcAPI.FeatureClass };
}
if (featureLayer == null || (featureLayer as IFeatureLayer).FeatureClass == null)
{
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
this.exportDataList[layerIndex].Make = "生成KO文件失败,获取图层信息异常";
this.exportDataList[layerIndex].CurrNum = 0;
}));
return;
}
ISpatialDataSource pSpatialDataSource = new ArcFeatureDataSource(featureLayer as IFeatureLayer, geometryNow, model.FilterWhere);
// pSpatialDataSource.DataSourcePath = model.LayerSource;
pLayer.FieldInfos = pSpatialDataSource.Fields;
//设置样式
pLayer.Render = SymbolConvert.Instance().GetRenderer((featureLayer as IGeoFeatureLayer).Renderer);
pLayer.ItemInfoRender = SymbolConvert.Instance().GetItemInfoRenderer((featureLayer as IGeoFeatureLayer).Renderer);
//最小比例尺
pLayer.MinScale = (int)featureLayer.MinimumScale;
//最大比例尺
pLayer.MaxScale = (int)featureLayer.MaximumScale;
IGeoFeatureLayer geolayer = featureLayer as IGeoFeatureLayer;
if (geolayer != null)
{
IElementCollection ec;
IAnnotateLayerProperties pAnnoLayerProps;
geolayer.AnnotationProperties.QueryItem(0, out pAnnoLayerProps, out ec, out ec);
ILabelEngineLayerProperties pLabelEngineLayerProps = (ILabelEngineLayerProperties)pAnnoLayerProps;
if (pLabelEngineLayerProps != null)
{
if (!string.IsNullOrWhiteSpace(pLabelEngineLayerProps.Expression) && geolayer.DisplayAnnotation)
{
pLayer.LayerLabelName = pLabelEngineLayerProps.Expression.Substring(1, pLabelEngineLayerProps.Expression.Length - 2);
}
else
{
pLayer.LayerLabelName = "";
}
}
}
//设置显示字段
pLayer.DisplayField = (featureLayer as IFeatureLayer).DisplayField;
LabelStyleConvert styleConvert = new LabelStyleConvert();
List<LabelingInfo> labelInfo = styleConvert.EsriLabelToCustomLabels((featureLayer as IGeoFeatureLayer).AnnotationProperties);
if (labelInfo != null && labelInfo.Count > 0)
pLayer.LabelingInfo = labelInfo[0];
//设置labelinginfo
pLayer.EncryptData = true;
pLayer.WKID = (featureLayer as IGeoDataset).SpatialReference.FactoryCode;
CreateConfig(pLayer.WKID);
string fileName = (featureLayer as IDataset).BrowseName;
pLayer.OutputFileName = newFilePath + "\\" + fileName + ".ko";
pLayer.SpatialDataSource = pSpatialDataSource;
LayerComm layerComm = new LayerComm();
pLayer.ItemInfo = layerComm.FeatureLayerToEntity(featureLayer as IFeatureLayer);
if (pLayer.Render is Kingo.Mobile.Shape2KOTool.XSDClass.SimpleRenderer)
pLayer.FeatureSymbol = (pLayer.Render as Kingo.Mobile.Shape2KOTool.XSDClass.SimpleRenderer).Symbol;
else if (pLayer.Render is Kingo.Mobile.Shape2KOTool.XSDClass.UniqueValueRenderer)
{
Kingo.Mobile.Shape2KOTool.XSDClass.UniqueValueRenderer uniqueValueRander = pLayer.Render as Kingo.Mobile.Shape2KOTool.XSDClass.UniqueValueRenderer;
if (uniqueValueRander != null)
pLayer.FeatureSymbol = uniqueValueRander.DefaultSymbol;
}
pLayer.Tag = model;
DateTime dt1 = DateTime.Now;
pLayer.Report += (s, c) =>
{
if (pLayer == null) return;
string start = string.Format("正在处理{0},共{1}条记录,", featureLayer.Name, pLayer.SpatialDataSource.RecordCount);
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
if (s == "插入数据完成!" || c == -1)
{
DateTime dt3 = DateTime.Now;
if (c == -1)
{
this.exportDataList[layerIndex].Make = s;
}
else
{
this.exportDataList[layerIndex].Make = "完成,共用时" + dt3.Subtract(dt1).TotalSeconds.ToString("0.0") + "秒";
}
if (pLayer.SpatialDataSource.RecordCount == 0)
{
this.exportDataList[layerIndex].FcCount = 100;
this.exportDataList[layerIndex].CurrNum = 100;
}
else
{
this.exportDataList[layerIndex].FcCount = pLayer.SpatialDataSource.RecordCount;
this.exportDataList[layerIndex].CurrNum = pLayer.SpatialDataSource.RecordCount;
}
//bool isChecked = this.exportDataList[layerIndex].IsSlice;
//if (isChecked)
// ExportKotilesByKo(pLayer.Tag as MakeTaskPackageModel, layerIndex);
string layerFileName = exportDataList[layerIndex].FileName;
if (isCustom)
{
if (s == "数据已全部加密成功!")
{
koIndex++;
}
MakeTaskPackageModel customModel = pLayer.Tag as MakeTaskPackageModel;
customModel.CurrentIndex = customModel.CurrentIndex + 1;
if (customModel.CurrentIndex > selectedXzq.Count) return;
if (customModel.CurrentIndex == selectedXzq.Count)
{
exportDataList[layerIndex].OutFilePath = System.IO.Path.Combine(this.exportDataList[layerIndex].OutPath, packName, "Source", layerFileName + ".ko");
createCount--;
if (createCount == 0)
{
FunctionOutXml outxml = new FunctionOutXml();
outxml.SaveConfig(exportDataList, isCustom, exportFolder, selectedXzq);
if (this.exportSuccess == true)
{
MessageHelper.Show("导出成功");
}
else
{
MessageHelper.Show("导出失败:\r\n" + errorMsg);
}
this.btnExport.IsEnabled = true;
}
return;
}
// pLayer.Tag = customModel;
ExportVectorKoThread(customModel);
}
else
{
exportDataList[layerIndex].OutFilePath = System.IO.Path.Combine(this.exportDataList[layerIndex].OutPath, packName, "Source", layerFileName + ".ko");
createCount--;
if (createCount == 0)
{
FunctionOutXml outxml = new FunctionOutXml();
outxml.SaveConfig(exportDataList, isCustom, exportFolder, selectedXzq);
if (this.exportSuccess == true)
{
MessageHelper.Show("导出成功");
}
else
{
MessageHelper.Show("导出失败:\r\n" + errorMsg);
}
this.btnExport.IsEnabled = true;
}
}
//AddTBMJFieldToKOFDT(pLayer);
if (pLayer != null)
pLayer.Dispose();
pLayer = null;
GC.Collect();
}
else
{
this.exportDataList[layerIndex].Make = s;
this.exportDataList[layerIndex].FcCount = pLayer.SpatialDataSource.RecordCount;
this.exportDataList[layerIndex].CurrNum = c;
}
}));
};
lstPLayers.Add(pLayer);
pLayer.CreateLayerUdp();
}
catch (Exception ex)
{
LogAPI.Debug("矢量数据导入KO失败:" + ex);
this.exportSuccess = false;
errorMsg += string.Format("{0}矢量数据导入KO失败:{1}\r\n", layerName, ex.Message);
createCount--;
}
finally
{
if(pWSFactory!=null)
Marshal.ReleaseComObject(pWSFactory);
}
}
int count = 0;
private void ExportWRJ(MakeTaskPackageModel model)
{
try
{
IGeometry geometryNow = null;
if (model.Type == "图层组" || model.Layer == null)
return;
int layerIndex = exportDataList.IndexOf(model);
if (layerIndex == -1) return;
IFeatureLayer pFeatureLayer = model.Layer as IFeatureLayer;
if (pFeatureLayer == null || pFeatureLayer.FeatureClass == null)
return;
int featureCount = 0;
Dictionary<string, IGeometry> geoDic = new Dictionary<string, IGeometry>();
if (isCustom)
{
for (int i = 0; i < selectedXzq.Count; i++)
{
string packName = selectedXzq[i];
geometryNow = XzqGeometry(selectedXzq[i], keyField);
if (!geoDic.ContainsKey(packName) && geometryNow != null)
{
geoDic.Add(packName, geometryNow);
IQueryFilter pSpatialFilter = null;
if (geometryNow != null)
{
pSpatialFilter = new SpatialFilterClass() { Geometry = geometryNow, GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName, SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects, WhereClause = (pFeatureLayer as IFeatureLayerDefinition).DefinitionExpression };
featureCount += pFeatureLayer.FeatureClass.FeatureCount(pSpatialFilter);
}
}
}
}
else
{
featureCount = pFeatureLayer.FeatureClass.FeatureCount(null);
}
DateTime dt1 = DateTime.Now;
if (geoDic.Count != 0)
{
foreach (var item in geoDic)
{
OutPutJson(model, pFeatureLayer, item.Value, featureCount, item.Key);
}
}
else
{
OutPutJson(model, pFeatureLayer, null, featureCount);
}
DateTime dt3 = DateTime.Now;
this.exportDataList[layerIndex].Make = "导出完成,共用时" + dt3.Subtract(dt1).TotalSeconds.ToString("0.0") + "秒";
this.exportDataList[layerIndex].FcCount = featureCount;
this.exportDataList[layerIndex].CurrNum = featureCount;
}
catch (Exception ex)
{
LogAPI.Debug("导出无人机任务包失败:" + ex);
}
}
private void OutPutJson(MakeTaskPackageModel model, IFeatureLayer pFeatureLayer, IGeometry geometry, int featureCount,string packName = "")
{
try
{
string newFilePath = exportFolder;
if (!System.IO.Directory.Exists(newFilePath))
{
System.IO.Directory.CreateDirectory(newFilePath);
}
string fileName = "uavTask.uts";
if (geometry != null)
fileName = string.Format("uavTask{0}.uts", packName);
newFilePath = System.IO.Path.Combine(newFilePath, fileName);
if (!System.IO.File.Exists(newFilePath))
{
System.IO.File.Create(newFilePath).Dispose();
}
int layerIndex = exportDataList.IndexOf(model);
if (layerIndex == -1) return;
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
WRJTask wrjTask = new WRJTask();
wrjTask.createTime = DateTime.Now.ToString();
wrjTask.id = "";
wrjTask.taskName = "无人机举证图斑";
wrjTask.taskType = 1;
wrjTask.tblist = new List<GeometryInfo>();
IQueryFilter pSpatialFilter = null;
if (geometry != null)
{
pSpatialFilter = new SpatialFilterClass() { Geometry = geometry, GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName, SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects, WhereClause = "" };
}
IFeatureCursor cursor = pFeatureLayer.FeatureClass.Search(pSpatialFilter, true);
IFeature pFeature = cursor.NextFeature();
GeometryInfo info = null;
DataTable dt = new DataTable();
if (pFeature != null)
{
for (int i = 0; i < pFeature.Fields.FieldCount; i++)
{
if (pFeature.Fields.get_Field(i).Name.ToLower().Contains("shape") || pFeature.Fields.get_Field(i).Name.ToLower() == "objectid")
{
continue;
}
DataColumn col = new DataColumn();
col.ColumnName = pFeature.Fields.get_Field(i).Name;
col.Caption = pFeature.Fields.get_Field(i).AliasName;
dt.Columns.Add(col);
}
}
while (pFeature != null)
{
count++;
DataRow dr = dt.NewRow();
for (int i = 0; i < pFeature.Fields.FieldCount; i++)
{
string strColName = pFeature.Fields.get_Field(i).Name;
if (strColName.ToLower().Contains("shape") || strColName.ToLower() == "objectid")
{
continue;
}
dr[strColName] = pFeature.get_Value(i);
}
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue;
List<Dictionary<string, object>> parentRow = new List<Dictionary<string, object>>();
DataTable newdt = new DataTable();
newdt.Columns.Add("name", typeof(string));
newdt.Columns.Add("alias", typeof(string));
newdt.Columns.Add("value", typeof(string));
foreach (DataColumn col in dt.Columns)
{
DataRow newdr = newdt.NewRow();
newdr["name"] = col.ColumnName;
newdr["alias"] = col.Caption;
newdr["value"] = dr[col.ColumnName];
newdt.Rows.Add(newdr);
}
foreach (DataRow row in newdt.Rows)
{
Dictionary<string, object> childRow = new Dictionary<string, object>();
foreach (DataColumn col in newdt.Columns)
{
childRow.Add(col.ColumnName, row[col]);
}
parentRow.Add(childRow);
}
string arrribute = javaScriptSerializer.Serialize(parentRow);
info = new GeometryInfo();
info.attributes = arrribute;
int bsm = pFeature.Fields.FindField("TBBH");
if (bsm >= 0)
{
info.tbbsm = pFeature.get_Value(bsm).ToString();
}
else
{
bsm = pFeature.Fields.FindField("JCBH");
if (bsm >= 0)
{
info.tbbsm = pFeature.get_Value(bsm).ToString();
}
}
info.taskId = "无人机举证图斑";
IGeometry pgeo = pFeature.ShapeCopy;
IClone pClone = pgeo as IClone;
IGeometry geo = pClone.Clone() as IGeometry;
if (geo.SpatialReference != null && false == geo.SpatialReference.Name.ToUpper().Equals("UNKNOWN"))
{
ISpatialReference spatial = (geo.SpatialReference as IProjectedCoordinateSystem).GeographicCoordinateSystem;
geo.Project(spatial);
}
else
{
ISpatialReference spatial = ((pFeatureLayer.FeatureClass as IGeoDataset).SpatialReference as IProjectedCoordinateSystem).GeographicCoordinateSystem;
geo.Project(spatial);
}
string shapeJson = ConvertWkt(geo);
info.geometry = shapeJson;
wrjTask.tblist.Add(info);
pFeature = cursor.NextFeature();
this.exportDataList[layerIndex].FcCount = featureCount;
this.exportDataList[layerIndex].CurrNum = count;
}
string Json = JsonConvert.SerializeObject(wrjTask);
Json = Json.Insert(0, "[");
Json = Json + "]";
System.IO.File.WriteAllText(newFilePath, Json);
}));
}
catch (Exception ex)
{
LogAPI.Debug("无人机json字符串写入文件失败:" + ex);
MessageHelper.Show("无人机json字符串写入文件失败:" + ex);
}
}
public string ConvertWkt(ESRI.ArcGIS.Geometry.IGeometry geometry)
{
string wkt = string.Empty;
try
{
ESRI.ArcGIS.Geometry.IGeometryFactory3 factory = new ESRI.ArcGIS.Geometry.GeometryEnvironment() as ESRI.ArcGIS.Geometry.IGeometryFactory3;
byte[] b = factory.CreateWkbVariantFromGeometry(geometry) as byte[];
OSGeo.OGR.Geometry gdalGeometry = OSGeo.OGR.Geometry.CreateFromWkb(b);
gdalGeometry.ExportToWkt(out wkt);
}
catch (Exception ex)
{
return wkt;
}
return wkt;
}
private void AddTBMJFieldToKOFDT(KODBFeatureLayer pLayer)
{
if (pLayer == null)
return;
try
{
SQLiteConnection sqlConnection = new SQLiteConnection(@"Data Source=" + pLayer.OutputFileName);
sqlConnection.Open();
SQLiteCommand cmd = new SQLiteCommand(sqlConnection);
SQLiteTransaction pTran = sqlConnection.BeginTransaction();
try
{
//string sqltxt = string.Format("ALTER TABLE KOFDT ADD COLUMN {0} {1};", "TBMJ", "float64");
//cmd.CommandText = sqltxt;
//int res = cmd.ExecuteNonQuery();
OSGeo.OGR.Geometry geo = null;
double TBMJ = 0;
string jcbh = string.Empty;
pLayer.SpatialDataSource.Open();
if (!string.IsNullOrWhiteSpace(pLayer.SpatialDataSource.DataSourcePath))
{
while (!pLayer.SpatialDataSource.EOF)
{
DataRow dr = pLayer.SpatialDataSource.GetNextRecord();
if (dr == null) return;
if (null != dr["Shape"])
{
try
{
geo = OSGeo.OGR.Geometry.CreateFromWkt(dr["Shape"].ToString());
if (dr.Table.Columns.Contains("JCBH"))
{
jcbh = dr["JCBH"].ToString();
TBMJ = geo.GetArea();
string sql = string.Format("update KOFDT set TBMJ = {0} ,JCBH = '{1}' where rtrim(ltrim(JCBH)) ='{1}'", TBMJ, jcbh.Trim());
cmd.CommandText = sql;
int ress = cmd.ExecuteNonQuery();
}
else if (dr.Table.Columns.Contains("TBBH"))
{
jcbh = dr["TBBH"].ToString();
TBMJ = geo.GetArea();
string sql = string.Format("update KOFDT set TBMJ = {0} ,TBBH = '{1}' where rtrim(ltrim(TBBH)) ='{1}'", TBMJ, jcbh.Trim());
cmd.CommandText = sql;
int ress = cmd.ExecuteNonQuery();
}
}
catch (Exception)
{
}
}
}
}
pTran.Commit();
pLayer.SpatialDataSource.Close();
}
catch (Exception)
{
LogAPI.Debug("获取TBMJ失败:" );
pTran.Rollback();
}
finally
{
pTran.Dispose();
}
if (sqlConnection != null)
{
sqlConnection.Close();
sqlConnection.Dispose();
sqlConnection = null;
}
}
catch (Exception ex)
{
LogAPI.Debug("添加TBMJ字段失败:" + ex);
}
}
private void CreateConfig(int wkid)
{
var pConfig = new ParamConfig();
try
{
pConfig.DelX = 0;
pConfig.DelY = 0;
pConfig.DelZ = 0;
pConfig.RX = 0;
pConfig.RY = 0;
pConfig.RZ = 0;
pConfig.K = 0;
pConfig.OX = 0;
pConfig.OY = 0;
pConfig.ValidErrorTimes = 5;
pConfig.IsAutoDeleteData = false;
pConfig.IsDecryptData = true;
pConfig.IsValidLic = true;
pConfig.IsAutoDeleteNotUse = false;
pConfig.IsAutoDeleteLicExpired = false;
pConfig.NoUseDays = 100;
pConfig.WKID = wkid;
}
catch (Exception ex)
{
MessageHelper.Show("参数格式设置不正确!请检查");
LogAPI.Debug("coordparam文件参数格式设置不正确:");
LogAPI.Debug(ex);
return;
}
string sJson = pConfig.ToJSON();
string sEnCode = DES.DESEnCode(sJson, DES.DES_Key);
try
{
string savepath = System.IO.Path.Combine(exportFolder, "Kingoit", "phonemap_wydh", "coordparam.kocfg");
if (outputPathCfg != null && !string.IsNullOrWhiteSpace(outputPathCfg.EncryFileDirectory) && !string.IsNullOrWhiteSpace(outputPathCfg.EncryFileName))
{
savepath = System.IO.Path.Combine(exportFolder, outputPathCfg.EncryFileDirectory, outputPathCfg.EncryFileName);
}
File.WriteAllText(savepath, sEnCode);
}
catch (Exception ex)
{
LogAPI.Debug("导出coordparam.kocf文件失败:");
LogAPI.Debug(ex);
}
}
private ESRI.ArcGIS.Geometry.IGeometry XzqGeometry(string keyValue, string keyName)
{
if (pCustomFC == null) return null;
ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = pCustomFC.Search(new ESRI.ArcGIS.Geodatabase.QueryFilterClass() { WhereClause = string.Format(WhereStr, keyValue) }, false);
if (featureCursor == null) return null;
ESRI.ArcGIS.Geodatabase.IFeature feature = featureCursor.NextFeature();
if (feature == null) return null;
return feature.ShapeCopy;
}
#region 地名数据导入query文件
private void ExportQueryDB()
{
if (string.IsNullOrEmpty(this.txtPlaceNameData.Text) || !System.IO.File.Exists(this.txtPlaceNameData.Text)) return;
string filePath = exportFolder + @"\Kingoit\phonemap_landsurvey\projects";
string packName = "Data";
if (isCustom)
{
for (int i = 0; i < selectedXzq.Count; i++)
{
packName = selectedXzq[i];
string newFilePath = System.IO.Path.Combine(filePath, packName);
if (!System.IO.Directory.Exists(newFilePath))
System.IO.Directory.CreateDirectory(newFilePath);
CreateQueryDB(newFilePath);
}
}
else
{
string newFilePath = System.IO.Path.Combine(filePath, packName);
if (!System.IO.Directory.Exists(newFilePath))
System.IO.Directory.CreateDirectory(newFilePath);
CreateQueryDB(newFilePath);
}
}
private void CreateQueryDB(string querySavePath)
{
try
{
string path = System.IO.Path.Combine(Activator.bundle.Location, "Resources", "query.db");
if (!File.Exists(path))
{
return;
}
querySavePath = System.IO.Path.Combine(querySavePath, "Query.db");
if (File.Exists(querySavePath))
File.Delete(querySavePath);
File.Copy(path, querySavePath, true);
SQLiteConnection sqlConnection = new SQLiteConnection(@"Data Source=" + querySavePath);
sqlConnection.Open();
SQLiteTransaction pTran = sqlConnection.BeginTransaction();
try
{
DataTable dt = ToDataTable(this.txtPlaceNameData.Text);
if (dt == null || dt.Rows.Count < 1) return;
SQLiteCommand cmd = new SQLiteCommand(sqlConnection);
string insertSql = "insert into QUERY(行政区代码,名称,面积,县代码,县名称,R_DisplayField,R_SearchField,R_X,R_Y) values('{0}','{1}',{2},'{3}','{4}','{5}','{6}',{7},{8})";
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
if (GetCellValue(dt.Rows[i][0]) == "行政区代码") continue;
cmd.CommandText = string.Format(insertSql, GetCellValue(dt.Rows[i][0]), GetCellValue(dt.Rows[i][1]), GetCellValue(dt.Rows[i][2]), GetCellValue(dt.Rows[i][3]), GetCellValue(dt.Rows[i][4]), GetCellValue(dt.Rows[i][5]), GetCellValue(dt.Rows[i][6]), GetCellValue(dt.Rows[i][7]), GetCellValue(dt.Rows[i][8]));
cmd.ExecuteNonQuery();
}
pTran.Commit();
}
catch (Exception ex)
{
LogAPI.Debug("地名数据导入失败:" + ex.Message);
pTran.Rollback();
throw;
}
finally
{
if (sqlConnection != null)
{
sqlConnection.Close();
sqlConnection = null;
GC.Collect();
}
}
}
catch (Exception ex)
{
LogAPI.Debug("地名数据导入失败:" + ex);
}
}
private string GetCellValue(object obj)
{
return toTrim(obj);
}
public string toTrim(object obj)
{
if (obj == null)
return string.Empty;
return obj.ToString().Trim();
}
/// <summary>
/// 读取Excel文件到DataSet中
/// </summary>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
public DataTable ToDataTable(string filePath)
{
string connStr = "";
string fileType = System.IO.Path.GetExtension(filePath);
if (string.IsNullOrEmpty(fileType)) return null;
if (fileType == ".xls")
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filePath + ";" + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
else
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + filePath + ";" + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\"";
string sql_F = "Select * FROM [{0}]";
OleDbConnection conn = null;
OleDbDataAdapter da = null;
DataTable dtSheetName = null;
DataSet ds = new DataSet();
try
{
// 初始化连接,并打开
conn = new OleDbConnection(connStr);
conn.Open();
// 获取数据源的表定义元数据
string SheetName = "";
dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
// 初始化适配器
da = new OleDbDataAdapter();
for (int i = 0; i < dtSheetName.Rows.Count; i++)
{
SheetName = (string)dtSheetName.Rows[i]["TABLE_NAME"];
if (SheetName == null || SheetName.ToUpper().Contains("MACRO") || !SheetName.Replace("'", "").EndsWith("$"))
{
continue;
}
da.SelectCommand = new OleDbCommand(String.Format(sql_F, SheetName), conn);
System.Data.DataTable dt = new System.Data.DataTable();
da.Fill(dt);
ds.Tables.Add(dt);
}
return ds.Tables[0];
}
catch (Exception ex)
{
LogAPI.Debug("地名数据Excel转DataTable失败:" + ex.Message);
}
finally
{
// 关闭连接
if (conn.State == ConnectionState.Open)
{
conn.Close();
da.Dispose();
conn.Dispose();
}
}
return null;
}
#endregion
#region ko文件生成kotiles
List<CutTiles> lstCutTiles = new List<CutTiles>();
List<UCMxdMultCut> openCut = new List<UCMxdMultCut>();
int nowMxdIndex = 0;
int mxdIndex = 0;
private void ExportKotilesByKo(MakeTaskPackageModel exportModel, int layerIndex)
{
if (exportModel == null || exportModel.Type == "瓦片") return;
MxdParameters mxdParameters = new MxdParameters()
{
SaveFileName = exportModel.FileName,
MaxScale = 8000
};
exportModel.MxdCutParameters = mxdParameters;
exportModel.LayerSource = MapsManager.Instance.MapService.getAxMapControl().DocumentFilename;
mxdIndex = 0;
Thread threadKotiles = new Thread(new ParameterizedThreadStart(ExportKotilesParame));
threadKotiles.SetApartmentState(ApartmentState.STA);
threadKotiles.IsBackground = true;
threadKotiles.Start(exportModel);
createCount++;
}
private void ExportKotilesParame(object obj)
{
string layerName = string.Empty;
try
{
ESRI.ArcGIS.Geometry.IGeometry geometryNow = null;
MakeTaskPackageModel model = obj as MakeTaskPackageModel;
string newFilePath = System.IO.Path.Combine(exportFolder, model.OutPath);
string packName = "Data";
if (isCustom)
{
packName = selectedXzq[mxdIndex];
if (!Directory.Exists(newFilePath))
Directory.CreateDirectory(newFilePath);
geometryNow = XzqGeometry(selectedXzq[mxdIndex], keyField);
geometryNow = (geometryNow as IClone).Clone() as ESRI.ArcGIS.Geometry.IGeometry;
}
newFilePath = System.IO.Path.Combine(newFilePath, packName, "Source");
layerName = model.FileAliasName;
if (!System.IO.Directory.Exists(newFilePath))
System.IO.Directory.CreateDirectory(newFilePath);
int layerIndex = exportDataList.IndexOf(model);
if (layerIndex == -1) return;
UCMxdMultCut ucMxdCut = new UCMxdMultCut();
ucMxdCut.IsEncrypt = true;
ucMxdCut.UseOutMapControl = true;
ucMxdCut.OutMapControl = MapsManager.Instance.MapService.getAxMapControl();
ucMxdCut.SetMxdPath(model.LayerSource);
ucMxdCut.SetSavePath(newFilePath + "\\" + model.FileName + ".kotiles");
ucMxdCut.CutIndex = layerIndex;
if (geometryNow != null)
{
model.MxdCutParameters.CutType = CUTAreaType.;
}
else
{
model.MxdCutParameters.CutType = CUTAreaType.;
}
ucMxdCut.BindParmas(model.MxdCutParameters);
ucMxdCut.GeometryNow = geometryNow;
ucMxdCut.selectedXzq = this.selectedXzq;
ucMxdCut.pFC = this.pCustomFC;
DateTime dt1 = DateTime.Now;
ucMxdCut.LayerName = model.FileAliasName;
ucMxdCut.CreatDown += (s) =>
{
nowMxdIndex++;
DateTime dt3 = DateTime.Now;
if (!this.IsDisposed)
{
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
this.exportDataList[layerIndex].Make = "完成,共用时" + dt3.Subtract(dt1).TotalSeconds.ToString("0.0") + "秒";
this.exportDataList[layerIndex].FcCount = 100;
this.exportDataList[layerIndex].CurrNum = 100;
this.exportDataList[layerIndex].OutFilePath = System.IO.Path.Combine(model.OutPath, packName, "Source", model.FileName + ".kotiles");
if (isCustom)
{
mxdIndex++;
if (mxdIndex == selectedXzq.Count)
{
createCount--;
if (createCount == 0)
{
FunctionOutXml outxml = new FunctionOutXml();
outxml.SaveConfig(exportDataList, isCustom, exportFolder, selectedXzq);
if (this.exportSuccess == true)
{
MessageHelper.Show("导出成功");
}
else
{
MessageHelper.Show("导出失败:\r\n" + errorMsg);
}
this.btnExport.IsEnabled = true;
}
return;
}
ExportKotilesParame(obj);
}
else
{
createCount--;
if (createCount == 0)
{
FunctionOutXml outxml = new FunctionOutXml();
outxml.SaveConfig(exportDataList, isCustom, exportFolder, selectedXzq);
if (this.exportSuccess == true)
{
MessageHelper.Show("导出成功");
}
else
{
MessageHelper.Show("导出失败:\r\n" + errorMsg);
}
this.btnExport.IsEnabled = true;
}
}
GC.Collect();
}));
}
};
ucMxdCut.Report += (s, c, i) =>
{
if (!this.IsDisposed)
{
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
this.exportDataList[layerIndex].Make = string.Format("{0}/{1}", c, s);
this.exportDataList[layerIndex].CurrNum = c;
this.exportDataList[layerIndex].FcCount = s;
}));
}
};
openCut.Add(ucMxdCut);
ucMxdCut.btnOk_Click(null, null);//.CreateTiles();
}
catch (Exception ex)
{
LogAPI.Debug("MXD切片失败:" + ex);
MessageHelper.Show("MXD切片失败:" + ex);
this.exportSuccess = false;
errorMsg += string.Format("{0}矢量数据导入KO失败:{1}\r\n", layerName, ex.Message);
createCount--;
}
}
private double GetMaxDistance(string filePath)
{
ProcessMXDClass pr = new ProcessMXDClass();
IEnvelope en = pr.GetMapEnvelope(filePath);
IEnvelope extentMax = GetExtentSquare(en);
return extentMax.XMax - extentMax.XMin;
}
/// <summary>
/// 获取指定范围外正方形
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
private IEnvelope GetExtentSquare(IEnvelope e)
{
IEnvelope extent = new EnvelopeClass()
{
XMax = e.XMax,
XMin = e.XMin,
YMax = e.YMax,
YMin = e.YMin
};
double del = (extent.Width - extent.Height) / 2;
if (del > 0)
{
extent.YMax += del;
extent.YMin -= del;
}
else
{
extent.XMax -= del;
extent.XMin += del;
}
extent.XMax += extent.Width / 8;
extent.XMin -= extent.Width / 8;
extent.YMax += extent.Width / 8;
extent.YMin -= extent.Width / 8;
return extent;
}
#endregion
#region img影像切片
List<MultRaster2MBTiles> raster = new List<MultRaster2MBTiles>();
private void CreateKotilesImg(object obj)
{
string layerName = string.Empty;
try
{
MakeTaskPackageModel model = obj as MakeTaskPackageModel;
string newFilePath = System.IO.Path.Combine(exportFolder, model.OutPath);
string packName = "Data";
if (!string.IsNullOrWhiteSpace(model.TaskName))
{
packName = model.TaskName;
}
if (isCustom)
{
packName = model.CustomPackName;
}
newFilePath = System.IO.Path.Combine(newFilePath, packName, "Source");
if (!Directory.Exists(newFilePath))
Directory.CreateDirectory(newFilePath);
layerName = model.FileAliasName;
int layerIndex = exportDataList.IndexOf(model);
if (layerIndex == -1) return;
string strFiles = string.Empty;
//int nThread = 1;
List<IRasterLayer> rasterLayerList = model.Layer as List<IRasterLayer>;
foreach (var item in rasterLayerList)
{
strFiles += string.Format("{0};", item.FilePath);
}
string strLayerPath = string.Format("\"" + strFiles.Substring(0, strFiles.Length - 1) + "\"");
string strFileName = string.Format("\"" + model.FileName + "\"");
string strOutputPath = string.Format("\"" + newFilePath + "\"");
string customLayerPath = string.Format("\"" + this.customLayerPath + "\"");
string customLayerName = string.Format("\"" + this.customLayerName + "\"");
string customstrWhere = string.Format("\"" + this.WhereStr + "\"");
string customKeyValue = string.Format("\"" + packName + "\"");
string strtilesType = string.Format("\"" + this.tilesType.ToString() + "\"");
string strlevel = string.Format("\"" + this.sectionlevel.ToString() + "\"");
string strtiledSize = string.Format("\"" + this.tileSize.ToString() + "\"");
string strthreadNum = string.Format("\"" + this.threadNum.ToString() + "\"");
string strConvertWebMercator = "0";
if (convertWebMercator == true)
strConvertWebMercator = "1";
var psi = new ProcessStartInfo("Kingo.Plugin.RasterToKOTilesApp.exe", string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11}", strLayerPath, strFileName, strOutputPath, customLayerPath, customLayerName, customstrWhere, customKeyValue, strtilesType, strlevel, strtiledSize, strthreadNum, strConvertWebMercator));
string a = psi.Arguments;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
var pes = Process.Start(psi);
var sout = pes.StandardOutput;
while (!sout.EndOfStream)
{
var line = sout.ReadLine();
if (string.IsNullOrEmpty(line)) continue;
if (line.ToString().Contains(";"))
{
string[] strArr = line.ToString().Split(';');
if (strArr.Length == 2)
{
this.exportDataList[layerIndex].CurrNum = Convert.ToInt32(strArr[0]);
this.exportDataList[layerIndex].FcCount = Convert.ToInt32(strArr[1]);
}
else if (strArr.Length == 3)
{
this.exportDataList[layerIndex].Make = strArr[0];
this.exportDataList[layerIndex].CurrNum = Convert.ToInt32(strArr[1]);
this.exportDataList[layerIndex].FcCount = Convert.ToInt32(strArr[2]);
}
else
{
this.exportDataList[layerIndex].FcCount = 100;
this.exportDataList[layerIndex].CurrNum = 100;
}
}
else
{
this.exportDataList[layerIndex].Make = line.ToString();
}
}
pes.WaitForExit();
pes.Close();
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
this.exportDataList[layerIndex].OutFilePath = System.IO.Path.Combine(model.OutPath, packName, "Source", model.FileName + ".kotiles");
createCount--;
if (createCount == 0)
{
FunctionOutXml outxml = new FunctionOutXml();
outxml.SaveConfig(exportDataList, isCustom, exportFolder, selectedXzq);
if (this.exportSuccess == true)
{
List<MakeTaskPackageModel> jzrwModelList = exportDataList.FindAll(x => x.Type.Contains("举证任务") && (x.FileName == "JCTB" || x.FileName == "监测图斑"));
if (jzrwModelList != null && jzrwModelList.Count != 0)
{
IQueryFilter pQuery = new QueryFilterClass();
foreach (MakeTaskPackageModel item in jzrwModelList)
{
if (!item.Make.Contains("完成"))
continue;
IFeatureLayer featureLayer = item.Layer as IFeatureLayer;
if (featureLayer != null && featureLayer.FeatureClass != null && !string.IsNullOrWhiteSpace(item.FilterWhere))
{
pQuery.WhereClause = item.FilterWhere;
IFeatureCursor featureCursor = featureLayer.FeatureClass.Update(pQuery, true);
IFeature feature = null;
int dcztIdx = featureLayer.FeatureClass.FindField("RWDCZT");//任务导出状态,数据导出成功后,更新导出状态为已制作
int wyzzsjIdx = featureLayer.FeatureClass.FindField("WYZZSJ");//外业制作时间
DateTime dateTime = DateTime.Now;
while ((feature = featureCursor.NextFeature()) != null)
{
if (dcztIdx != -1)
feature.Value[dcztIdx] = "已制作";
if (wyzzsjIdx != -1)
feature.Value[wyzzsjIdx] = dateTime;
featureCursor.UpdateFeature(feature);
}
featureCursor.Flush();
Thread.Sleep(3000);
}
}
}
MessageHelper.Show("导出成功");
}
else
{
MessageHelper.Show("导出失败:\r\n" + errorMsg);
}
this.btnExport.IsEnabled = true;
}
}));
}
catch (Exception ex)
{
LogAPI.Debug("导出影像kotiles失败:" + ex);
this.exportSuccess = false;
errorMsg += string.Format("{0}矢量数据导入KO失败:{1}\r\n", layerName, ex.Message);
createCount--;
}
}
private void CreateKotilesImg1(object obj)
{
string layerName = string.Empty;
try
{
MakeTaskPackageModel model = obj as MakeTaskPackageModel;
string newFilePath = System.IO.Path.Combine(exportFolder, model.OutPath);
string packName = "Data";
if (!string.IsNullOrWhiteSpace(model.TaskName))
{
packName = model.TaskName;
}
Raster2KOTiles.Envelope envelopeCut = null;
if (isCustom)
{
packName = geometrys.ElementAt(model.CurrentIndex).Key;
OSGeo.OGR.Geometry geometryValue = geometrys.ElementAt(model.CurrentIndex).Value;
if (geometryValue != null)
{
List<OSGeo.OGR.Geometry> list = new List<OSGeo.OGR.Geometry>() { geometryValue.Clone() };
toplayer = UnionVector.CreateLayer(list, distance);
OSGeo.OGR.Geometry geometry = null;
foreach (OSGeo.OGR.Geometry geo in list)
{
geometry = UnionVector.UnionGeometry(geometry, geo);
}
OSGeo.OGR.Envelope envelope = new OSGeo.OGR.Envelope();
geometry.GetEnvelope(envelope);
envelopeCut = new Raster2KOTiles.Envelope
{
XMax = envelope.MaxX,
XMin = envelope.MinX,
YMax = envelope.MaxY,
YMin = envelope.MinY
};
}
}
newFilePath = System.IO.Path.Combine(newFilePath, packName, "Source");
if (!Directory.Exists(newFilePath))
Directory.CreateDirectory(newFilePath);
layerName = model.FileAliasName;
int layerIndex = exportDataList.IndexOf(model);
if (layerIndex == -1) return;
MultRaster2MBTiles pMergeRaster = new MultRaster2MBTiles();
raster.Add(pMergeRaster);
List<string> files = new List<string>();
int nThread = 1;
try
{
List<IRasterLayer> rasterLayerList = model.Layer as List<IRasterLayer>;
foreach (var item in rasterLayerList)
{
files.Add(item.FilePath);
}
System.Drawing.Imaging.ImageFormat imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
if (this.tilesType.ToString().ToLower() == "png")
{
imgFormat = System.Drawing.Imaging.ImageFormat.Png;
}
pMergeRaster.ImgFormat = imgFormat;
pMergeRaster.Level = this.sectionlevel;// Convert.ToInt32(this.txtSectionlevel.Text);
pMergeRaster.TiledSize = this.tileSize;// Convert.ToInt32(this.txtTilesize.Text);
pMergeRaster.MBTilesPath = newFilePath + "\\" + model.FileName + ".kotiles";
pMergeRaster.Index = layerIndex;
pMergeRaster.SaveType = EnumSaveType.Level;
nThread = this.threadNum;// Convert.ToInt32(this.txtThreadnum.Text);
nThread = nThread <= 0 ? 1 : nThread;
}
catch (Exception ex)
{
this.exportDataList[layerIndex].Make = "制作失败!原因:" + ex.Message;
this.exportDataList[layerIndex].CurrNum = 0;
}
DateTime dt1 = DateTime.Now;
pMergeRaster.CreatDown += (s, e1) =>
{
DateTime dt3 = DateTime.Now;
if (!this.IsDisposed)
{
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
this.exportDataList[layerIndex].Make = "完成,共用时" + dt3.Subtract(dt1).TotalSeconds.ToString("0.0") + "秒";
this.exportDataList[layerIndex].FcCount = 100;
this.exportDataList[layerIndex].CurrNum = 100;
this.exportDataList[layerIndex].OutFilePath = System.IO.Path.Combine(model.OutPath, packName, "Source", model.FileName + ".kotiles");
if (isCustom)
{
model.CurrentIndex = model.CurrentIndex + 1;
if (model.CurrentIndex > selectedXzq.Count) return;
if (model.CurrentIndex == selectedXzq.Count)
{
this.exportDataList[layerIndex].OutFilePath = System.IO.Path.Combine(model.OutPath, packName, "Source", model.FileName + ".kotiles");
createCount--;
if (createCount == 0)
{
FunctionOutXml outxml = new FunctionOutXml();
outxml.SaveConfig(exportDataList, isCustom, exportFolder, selectedXzq);
if (this.exportSuccess == true)
{
MessageHelper.Show("导出成功");
}
else
{
MessageHelper.Show("导出失败:\r\n" + errorMsg);
}
this.btnExport.IsEnabled = true;
}
return;
}
CreateKotilesImg(model);
}
else
{
createCount--;
if (createCount == 0)
{
FunctionOutXml outxml = new FunctionOutXml();
outxml.SaveConfig(exportDataList, isCustom, exportFolder, selectedXzq);
;
if (this.exportSuccess == true)
{
MessageHelper.Show("导出成功");
}
else
{
MessageHelper.Show("导出失败:\r\n" + errorMsg);
}
this.btnExport.IsEnabled = true;
}
}
GC.Collect();
}));
}
};
pMergeRaster.Report += (s, c) =>
{
if (!this.IsDisposed)
{
this.Dispatcher.Invoke(new MethodInvoker(() =>
{
this.exportDataList[layerIndex].Make = string.Format("{0}/{1}", c, s);
this.exportDataList[layerIndex].CurrNum = c;
this.exportDataList[layerIndex].FcCount = s;
}));
}
};
try
{
pMergeRaster.CreateMulFilesKOTiles(files, nThread, convertWebMercator, envelopeCut);
}
catch (Exception ex)
{
this.exportDataList[layerIndex].Make = "制作失败!原因:" + ex.Message;
this.exportDataList[layerIndex].CurrNum = 0;
}
}
catch (Exception ex)
{
LogAPI.Debug("导出影像kotiles失败:" + ex);
this.exportSuccess = false;
errorMsg += string.Format("{0}矢量数据导入KO失败:{1}\r\n", layerName, ex.Message);
createCount--;
}
}
private void GetBestLevelSize(List<IRasterLayer> rasterLayerList)
{
try
{
List<string> files = new List<string>();
foreach (var item in rasterLayerList)
{
if (System.IO.Path.GetExtension(item.FilePath.ToString()) != ".kotiles")
{
files.Add(item.FilePath.ToString());
}
}
if (files.Count == 0)
return;
int level, tileSize;
double resolution = MultRaster2MBTiles.GetBestLevelAndSize(files, out level, out tileSize);
if (level != 0 && tileSize != 0)
{
if (level > Convert.ToInt32(this.txtSectionlevel.Text))
{
this.txtTilesize.Text = tileSize.ToString();
this.txtSectionlevel.Text = level.ToString();
}
//this.txtResolution.Text = resolution.ToString("0.00");
}
}
catch (Exception ex)
{
LogAPI.Debug("获取切片级别失败:" + ex.Message);
}
}
private void GetBestLevelSize(IRasterLayer rasterLayer)
{
try
{
List<string> files = new List<string>();
if (System.IO.Path.GetExtension(rasterLayer.FilePath.ToString()) != ".kotiles")
{
files.Add(rasterLayer.FilePath.ToString());
}
if (files.Count == 0)
return;
int level, tileSize;
double resolution = MultRaster2MBTiles.GetBestLevelAndSize(files, out level, out tileSize);
if (level != 0 && tileSize != 0)
{
if (level > Convert.ToInt32(this.txtSectionlevel.Text))
{
this.txtTilesize.Text = tileSize.ToString();
this.txtSectionlevel.Text = level.ToString();
}
//this.txtResolution.Text = resolution.ToString("0.00");
}
}
catch (Exception ex)
{
LogAPI.Debug("获取切片级别失败:" + ex.Message);
}
}
#endregion
/// <summary>
/// 选择自定义范围
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSelectExtentData_Click(object sender, RoutedEventArgs e)
{
try
{
OpenDataDialog pDialog = new OpenDataDialog();
ISpatialDataObjectFilter pOFilter;
pOFilter = new FilterDatasetsAndLayers();
pDialog.AddFilter(pOFilter, true);
pDialog.Title = "选择矢量图层数据";
pDialog.AllowMultiSelect = false;
pDialog.RestoreLocation = true;
pDialog.StartLocation = pDialog.FinalLocation;
System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog();
if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0)
{
foreach (ISpatialDataObject distObj in pDialog.Selection)
{
if (distObj.DatasetType == ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass)
{
this.txtExtentData.Text = pDialog.FinalLocation;
this.customLayerPath = pDialog.FinalLocation;
this.customLayerName = distObj.DatasetName.Name;
pCustomFC = (distObj.DatasetName as IName).Open() as IFeatureClass;
if (pCustomFC != null)
{
frmXZQSelected = new FrmXZQSelected();
frmXZQSelected.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
frmXZQSelected.Width = 800;
frmXZQSelected.Height = 450;
frmXZQSelected.ImportFeatureClass = pCustomFC;
frmXZQSelected.CustomLayerPath = customLayerPath;
frmXZQSelected.CustomLayerName = customLayerName;
frmXZQSelected.GetCustomXZQInfo = this.GetCustomXZQInfo;
currentIndex = 0;
frmXZQSelected.ShowInMainWindow(true);
}
else
{
MessageHelper.Show("请选择矢量图层!!");
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("选择自定义范围数据失败:" + ex);
}
}
private void GetCustomXZQInfo()
{
if(frmXZQSelected!=null)
selectedXzq = frmXZQSelected.KeyFieldsList;
geometrys = frmXZQSelected.geometrys;
keyField = frmXZQSelected.KeyField;
WhereStr = frmXZQSelected.WhereStr;
}
private void btnSelectExportPath_Click(object sender, RoutedEventArgs e)
{
try
{
KGIS.Framework.Utils.Dialog.FolderBrowserDialog folderBrowserDialog = new KGIS.Framework.Utils.Dialog.FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.txtExportPath.Text = folderBrowserDialog.SelectedPath;
}
}
catch (Exception ex)
{
LogAPI.Debug("选择导出位置失败:" + ex);
}
}
private void FrmMobileDataExport_Loaded(object sender, RoutedEventArgs e)
{
try
{
if (this.rdoWYDHRWB.IsChecked == true)
GetExportDataList();
else
{
GetWRJExportDataList();
}
//设置举证任务过滤条件,默认选中未制作
this.comRWDCZT.Items.Add("已制作");
this.comRWDCZT.Items.Add("未制作");
this.comRWDCZT.Items.Add("全部");
this.comRWDCZT.SelectedIndex = 1;
if (bundle == null)
bundle = Activator.bundle;
if (bundle != null && !string.IsNullOrWhiteSpace(bundle.Location))
{
//string path = @"F:\研发产品\年度变更调查建库软件\Kingo.BuildDB\Apps\Plugins\Kingo.Plugin.MakeTaskPackage";
string projectPath = System.IO.Path.Combine(bundle.Location, "Configs");
if (!System.IO.Directory.Exists(projectPath))
{
MessageHelper.Show(string.Format("{0}目录不存在!", projectPath));
return;
}
string outputCfgPath = System.IO.Path.Combine(projectPath, "TaskPackagePathConfig.xml");
if (!System.IO.File.Exists(outputCfgPath))
{
MessageHelper.Show(string.Format("{0}文件不存在!", outputCfgPath));
return;
}
taskPackagePathConfig = SerializeAPI.DeserializeToObject2<TaskPackagePathConfig>(outputCfgPath);
if (taskPackagePathConfig != null && taskPackagePathConfig.outputPaths != null)
{
this.cobOutputFileCfg.ItemsSource = taskPackagePathConfig.outputPaths.outputPathList;
this.cobOutputFileCfg.SelectedIndex = 0;
}
}
var model = this.exportDataList.Find(x => x.FileName.Contains(".mxd"));
if (model == null)
{
this.txtMaxScale.IsEnabled = false;
this.comMinScale.IsEnabled = false;
}
else
{
this.txtMaxScale.IsEnabled = true;
this.comMinScale.IsEnabled = true;
}
SetExportPath();
}
catch (Exception ex)
{
LogAPI.Debug("绑定地图制作列表数据失败:" + ex);
}
}
private void CobOutputFileCfg_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.cobOutputFileCfg.SelectedItem != null)
{
outputPathCfg = this.cobOutputFileCfg.SelectedItem as OutputPath;
if (this.exportDataList != null && outputPathCfg!=null)
{
foreach (var item in this.exportDataList)
{
item.OutPath = outputPathCfg.RootDirectory;
item.TaskName = outputPathCfg.TaskName;
item.CfgFileName = outputPathCfg.ProfileName;
}
}
}
}
private int _id = 1;
private void GetWRJExportDataList()
{
try
{
exportDataList = new List<MakeTaskPackageModel>();
if (exportDataList != null)
{
ILayer wrjlayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB");
if (wrjlayer != null)
{
string where = string.Empty;
int sfwyIndex = (wrjlayer as IFeatureLayer).FeatureClass.FindField("SFJZ");
int rwdcztIndex = (wrjlayer as IFeatureLayer).FeatureClass.FindField("RWDCZT");
if (sfwyIndex != -1)
{
where = string.Format("SFJZ='1'");
}
if (this.comRWDCZT.SelectedIndex == 0 && rwdcztIndex!=-1)
where = string.Format("{0} and RWDCZT='已制作'", where);
else if (this.comRWDCZT.SelectedIndex == 1 && rwdcztIndex !=-1)
where = string.Format("{0} and (RWDCZT is null or RWDCZT='')", where);
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.FileName = (wrjlayer as IDataset).BrowseName;
mobiledata.FileAliasName = wrjlayer.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = 0;
mobiledata.Layer = wrjlayer;
mobiledata.MapGroupIndex = -1;
mobiledata.Type = "举证任务";
if (outputPathCfg != null)
{
mobiledata.OutPath = outputPathCfg.RootDirectory;
mobiledata.TaskName = outputPathCfg.TaskName;
mobiledata.CfgFileName = outputPathCfg.ProfileName;
}
else
{
mobiledata.TaskName = "无人机举证图斑";
}
mobiledata.MapGroupName = "其他";
mobiledata.ID = _id;
mobiledata.PID = 0;
mobiledata.IsLayerGroup = false;
mobiledata.FilterWhere = where;
_id++;
exportDataList.Add(mobiledata);
}
}
this.rwzzTreeList.ItemsSource = exportDataList;
}
catch (Exception ex)
{
LogAPI.Debug("获取无人机导出列表数据失败:" + ex);
MessageHelper.Show("获取无人机导出列表数据失败:" + ex);
}
}
private void GetExportDataList()
{
try
{
exportDataList = new List<MakeTaskPackageModel>();
rasterDataList = new List<MakeTaskPackageModel>();
if (exportDataList != null)
{
List<ILayer> layerList = GetLayer();
layerList.Reverse();
if (layerList != null && layerList.Count != 0)
{
for (int i = 0; i < layerList.Count; i++)
{
ILayer player = layerList[i];
if (player is IGroupLayer)
{
IGroupLayer grouplayer = player as IGroupLayer;
ILayerGeneralProperties lp = grouplayer as ILayerGeneralProperties;
if (lp.LayerDescription.ToUpper() != "JZRWSJ".ToUpper() && lp.LayerDescription.ToUpper() != "CKSJ".ToUpper())
continue;
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.FileName = grouplayer.Name;
mobiledata.FileAliasName = grouplayer.Name;
mobiledata.Type = "图层组";
mobiledata.Layer = grouplayer;
mobiledata.ExcState = ExcStateEnum.NoImport;
mobiledata.ID = _id;
mobiledata.PID = 0;
mobiledata.IsLayerGroup = true;
_id++;
exportDataList.Add(mobiledata);
GetVertorData(player, i, mobiledata.ID);
}
}
}
ILayer bglayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB");
if (bglayer != null)
{
string where = string.Empty;
int sfwyIndex = (bglayer as IFeatureLayer).FeatureClass.FindField("SFJZ");
int rwdcztIndex = (bglayer as IFeatureLayer).FeatureClass.FindField("RWDCZT");
if (sfwyIndex != -1)
{
where = string.Format("SFJZ='1'");
}
if (this.comRWDCZT.SelectedIndex == 0 && rwdcztIndex!=-1)
where = string.Format("{0} and RWDCZT='已制作'", where);
else if (this.comRWDCZT.SelectedIndex == 1 && rwdcztIndex!=-1)
where = string.Format("{0} and (RWDCZT is null or RWDCZT='')", where);
GetOtherData(bglayer, layerList.Count, where);
}
exportDataList.Reverse();
//获取影像数据分组下的影像数据
List<IGroupLayer> tilesList = MapsManager.Instance.MapService.GetAllRasterGroupLayerInMap<IRasterLayer>();
foreach (var item in tilesList)
{
ILayerGeneralProperties grouplp = item as ILayerGeneralProperties;
if (grouplp.LayerDescription.ToLower().Contains(".mxd") || grouplp.LayerDescription.ToUpper() == "MXD_Group".ToUpper())
continue;
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.FileName = item.Name;
mobiledata.FileAliasName = item.Name;
mobiledata.Type = "图层组";
mobiledata.Layer = item;
// mobiledata.ExcState = ExcStateEnum.NoImport;
mobiledata.ID = _id;
mobiledata.PID = 0;
mobiledata.IsLayerGroup = true;
_id++;
exportDataList.Add(mobiledata);
List<IRasterLayer> groupRasterLayerList = null;
ICompositeLayer pComLayer = item as ICompositeLayer;
//for (int i = pComLayer.Count - 1; i >= 0; i--)
int layerIndex = pComLayer.Count;
for (int i = 0; i < pComLayer.Count; i++)
{
layerIndex--;
ILayer layer = pComLayer.Layer[i];
if (layer is IRasterLayer)
{
groupRasterLayerList = GetAllLayerInThisGroupLayer<IRasterLayer>(pComLayer);
//groupRasterLayerList.Add(layer as IRasterLayer);
List<IRasterLayer> rasterLayerList = new List<IRasterLayer>();
rasterLayerList.Add(layer as IRasterLayer);
GetBestLevelSize(rasterLayerList);
GetRasterData(rasterLayerList, item.Name, 0, layerIndex, mobiledata.ID);
}
else if (layer is IGroupLayer)
{
List<IGroupLayer> groupList = new List<IGroupLayer>();
groupList.Add(layer as IGroupLayer);
if (groupList != null && groupList.Count != 0)
{
GetGroupRasterData(groupList, null, mobiledata.FileName, mobiledata.MapGroupIndex, layerIndex, mobiledata.ID);
}
}
}
if (groupRasterLayerList!=null && groupRasterLayerList.Count != 0)
{
mobiledata.Type = "瓦片";
mobiledata.Make = "未制作";
mobiledata.Layer = groupRasterLayerList;
mobiledata.LayerIndex = pComLayer.Count;
GetBestLevelSize(groupRasterLayerList);
}
else
{
mobiledata.ExcState = ExcStateEnum.NoImport;
}
}
if (exportDataList.Count != 0)
{
List<MakeTaskPackageModel> exportDataListShow = new List<MakeTaskPackageModel>();
string isaddstr = "";
for (int i = 0; i < exportDataList.Count; i++)
{
if (!isaddstr.Contains("-" + exportDataList[i].FileName))
{
MakeTaskPackageModel model = new MakeTaskPackageModel();
model = exportDataList[i];
exportDataListShow.Add(model);
isaddstr += "-" + exportDataList[i].FileName;
}
}
exportDataList = exportDataListShow;
}
this.rwzzTreeList.ItemsSource = exportDataList;
}
}
catch (Exception ex)
{
LogAPI.Debug("获取列表数据失败:" + ex);
MessageHelper.ShowError("获取列表数据失败:" + ex);
}
}
private void GetGroupRasterData(List<IGroupLayer> tilesList, List<ILayer> layerList, string groupName, int groupIndex, int layerIndex, int pid)
{
try
{
foreach (var item in tilesList)
{
// layerIndex++;
ILayerGeneralProperties grouplp = item as ILayerGeneralProperties;
if (grouplp.LayerDescription.ToLower().Contains(".mxd") || grouplp.LayerDescription.ToUpper() == "MXD_Group".ToUpper())
continue;
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.Type = "瓦片";
mobiledata.FileName = item.Name;
mobiledata.FileAliasName = item.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = layerIndex;
if (layerList != null)
mobiledata.MapGroupIndex = layerList.IndexOf(item);
else
mobiledata.MapGroupIndex = groupIndex;
if (string.IsNullOrWhiteSpace(groupName))
mobiledata.MapGroupName = item.Name;
else
mobiledata.MapGroupName = groupName;
ICompositeLayer pComLayer = item as ICompositeLayer;
mobiledata.Layer = GetAllLayerInThisGroupLayer<IRasterLayer>(pComLayer);
mobiledata.OutPath = @"Kingoit\phonemap_landsurvey\projects";
List<IRasterLayer> rasterList = mobiledata.Layer as List<IRasterLayer>;
GetBestLevelSize(rasterList);
mobiledata.ID = _id;
mobiledata.PID = pid;
mobiledata.IsLayerGroup = true;
_id++;
exportDataList.Add(mobiledata);
//rasterDataList.Add(mobiledata);
//for (int i = pComLayer.Count-1; i >=0; i--)
int index = pComLayer.Count;
for (int i = 0; i < pComLayer.Count; i++)
{
index--;
ILayer layer = pComLayer.Layer[i];
if (layer is IRasterLayer)
{
List<IRasterLayer> rasterLayerList = new List<IRasterLayer>();
rasterLayerList.Add(layer as IRasterLayer);
GetBestLevelSize(rasterLayerList);
GetRasterData(rasterLayerList, item.Name, 0, index, mobiledata.ID);
}
else if (layer is IGroupLayer)
{
List<IGroupLayer> groupList = new List<IGroupLayer>();
groupList.Add(layer as IGroupLayer);
if (groupList != null && groupList.Count != 0)
{
GetGroupRasterData(groupList, null, mobiledata.FileName, mobiledata.MapGroupIndex, index, mobiledata.ID);
}
}
}
//List<IGroupLayer> groupList = GetAllLayerInThisGroupLayer<IGroupLayer>(pComLayer);
//if (groupList != null && groupList.Count != 0)
//{
// index = groupList.Count;
// groupList.Reverse();
// GetGroupRasterData(groupList, null, mobiledata.MapGroupName, mobiledata.MapGroupIndex, mobiledata.LayerIndex, mobiledata.ID);
//}
//List<IRasterLayer> rasterLayerList = GetAllLayerInThisGroupLayer<IRasterLayer>(pComLayer);
//GetBestLevelSize(rasterLayerList);
//rasterLayerList.Reverse();
//GetRasterData(rasterLayerList, item.Name, 0, index, mobiledata.ID);
}
}
catch (Exception ex)
{
LogAPI.Debug("获取影像数据失败:" + ex);
}
}
private void GetRasterData(List<IRasterLayer> rasterList, string groupName, int groupIndex, int layerIndex, int pid)
{
try
{
foreach (var item in rasterList)
{
//layerIndex++;
ILayerGeneralProperties grouplp = item as ILayerGeneralProperties;
if (grouplp.LayerDescription.ToLower().Contains(".mxd") || grouplp.LayerDescription.ToUpper() == "MXD_Group".ToUpper())
continue;
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.Type = "瓦片";
mobiledata.FileName = item.Name;
mobiledata.FileAliasName = item.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = layerIndex;
mobiledata.MapGroupIndex = groupIndex;
if (string.IsNullOrWhiteSpace(groupName))
mobiledata.MapGroupName = item.Name;
else
mobiledata.MapGroupName = groupName;
List<IRasterLayer> imgsList = new List<IRasterLayer>();
imgsList.Add(item);
mobiledata.Layer = imgsList;
if (outputPathCfg != null)
{
mobiledata.OutPath = outputPathCfg.RootDirectory;
mobiledata.TaskName = outputPathCfg.TaskName;
}
else
{
mobiledata.OutPath = @"Kingoit\phonemap_landsurvey\projects";
mobiledata.TaskName = "县级数据";
}
mobiledata.ID = _id;
mobiledata.PID = pid;
mobiledata.IsLayerGroup = false;
_id++;
exportDataList.Add(mobiledata);
//rasterDataList.Add(mobiledata);
}
}
catch (Exception ex)
{
LogAPI.Debug("获取影像数据失败:" + ex);
}
}
private void GetVertorData(ILayer player, int mapGroupIndex, int pid)
{
try
{
if (player is IGroupLayer)
{
IGroupLayer grouplayer = player as IGroupLayer;
ILayerGeneralProperties lp = grouplayer as ILayerGeneralProperties;
if (lp.LayerDescription.ToUpper() != "JZRWSJ".ToUpper() && lp.LayerDescription.ToUpper() != "CKSJ".ToUpper() && lp.LayerDescription.ToUpper() != "SGYX".ToUpper())
return;
List<IFeatureLayer> layers = GetSubLayer<IFeatureLayer>(grouplayer as ICompositeLayer);
layers.Reverse();
foreach (var layer in layers)
{
IFeatureLayer pFeatureLayer = layer as IFeatureLayer;
string fullPath = GetLayerPathByLayer(pFeatureLayer);
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.FileName = (layer as IDataset).BrowseName;
mobiledata.FileAliasName = layer.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = layers.IndexOf(layer);
mobiledata.Layer = layer;
mobiledata.MapGroupIndex = mapGroupIndex;
mobiledata.Type = "矢量";
mobiledata.OutPath = @"Kingoit\phonemap_wydh\projects";
mobiledata.TaskName = "县级数据";
mobiledata.CfgFileName = "layerConfig.xml";
mobiledata.MapGroupName = grouplayer.Name;
mobiledata.ID = _id;
mobiledata.PID = pid;
mobiledata.IsLayerGroup = false;
if (!string.IsNullOrWhiteSpace(fullPath))
mobiledata.LayerSource = fullPath;
_id++;
exportDataList.Add(mobiledata);
}
List<IGroupLayer> grouplayers = GetGroupListByIGroupLayer(grouplayer);
grouplayers.Reverse();
foreach (var layer in grouplayers)
{
ILayerGeneralProperties grouplp = layer as ILayerGeneralProperties;
if (grouplp.LayerDescription.ToLower().Contains(".mxd") && !grouplp.LayerDescription.ToLower().Contains("mxd:"))
{
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.FileName = layer.Name;
mobiledata.FileAliasName = layer.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = grouplayers.IndexOf(layer);
mobiledata.Layer = layer;
mobiledata.MapGroupIndex = mapGroupIndex;
mobiledata.Type = "瓦片";
mobiledata.OutPath = @"Kingoit\phonemap_wydh\projects";
mobiledata.TaskName = "县级数据";
mobiledata.CfgFileName = "layerConfig.xml";
mobiledata.MapGroupName = grouplayer.Name;
mobiledata.LayerSource = grouplp.LayerDescription;
mobiledata.ID = _id;
mobiledata.PID = pid;
mobiledata.IsLayerGroup = false;
_id++;
exportDataList.Add(mobiledata);
}
else
{
if (layer is IGroupLayer)
{
IGroupLayer newgrouplayer = layer as IGroupLayer;
ILayerGeneralProperties newlp = newgrouplayer as ILayerGeneralProperties;
if (newlp.LayerDescription.ToUpper() != "MXD_Group".ToUpper())
{
List<IFeatureLayer> sublayers = GetSubLayer<IFeatureLayer>(newgrouplayer as ICompositeLayer);
sublayers.Reverse();
foreach (var newlayer in sublayers)
{
IFeatureLayer pFeatureLayer = layer as IFeatureLayer;
string fullPath = GetLayerPathByLayer(pFeatureLayer);
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.FileName = (newlayer as IDataset).BrowseName;
mobiledata.FileAliasName = newlayer.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = sublayers.IndexOf(newlayer);
mobiledata.Layer = newlayer;
mobiledata.MapGroupIndex = mapGroupIndex;
mobiledata.Type = "矢量";
mobiledata.OutPath = @"Kingoit\phonemap_wydh\projects";
mobiledata.TaskName = "县级数据";
mobiledata.CfgFileName = "layerConfig.xml";
mobiledata.MapGroupName = newgrouplayer.Name;
mobiledata.ID = _id;
mobiledata.PID = pid;
mobiledata.IsLayerGroup = false;
if (!string.IsNullOrWhiteSpace(fullPath))
mobiledata.LayerSource = fullPath;
_id++;
exportDataList.Add(mobiledata);
}
}
}
else
{
IFeatureLayer pFeatureLayer = layer as IFeatureLayer;
string fullPath = GetLayerPathByLayer(pFeatureLayer);
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.FileName = (layer as IDataset).BrowseName;
mobiledata.FileAliasName = layer.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = mapGroupIndex;
mobiledata.Layer = layer;
mobiledata.MapGroupIndex = -1;
mobiledata.Type = "矢量";
mobiledata.OutPath = @"Kingoit\phonemap_wydh\projects";
mobiledata.TaskName = "县级数据";
mobiledata.CfgFileName = "layerConfig.xml";
mobiledata.MapGroupName = "其他";
mobiledata.ID = _id;
mobiledata.PID = pid;
mobiledata.IsLayerGroup = false;
if (!string.IsNullOrWhiteSpace(fullPath))
mobiledata.LayerSource = fullPath;
_id++;
exportDataList.Add(mobiledata);
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("获取列表矢量数据失败:" + ex);
}
}
private void GetOtherData(ILayer layer,int mapGroupIndex,string filterWhere)
{
try
{
IFeatureLayer pFeatureLayer = layer as IFeatureLayer;
string fullPath = GetLayerPathByLayer(pFeatureLayer);
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.FileName = (layer as IDataset).BrowseName;
mobiledata.FileAliasName = layer.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = mapGroupIndex;
mobiledata.Layer = layer;
mobiledata.MapGroupIndex = -1;
mobiledata.Type = "举证任务";
if (outputPathCfg != null)
{
mobiledata.OutPath = outputPathCfg.RootDirectory;
mobiledata.TaskName = outputPathCfg.TaskName;
mobiledata.CfgFileName = outputPathCfg.ProfileName;
}
else
{
mobiledata.OutPath = @"Kingoit\phonemap_wydh\projects";
mobiledata.TaskName = "县级数据";
mobiledata.CfgFileName = "layerConfig.xml";
}
mobiledata.MapGroupName = "举证任务";
mobiledata.ID = _id;
mobiledata.PID = 0;
mobiledata.IsLayerGroup = false;
mobiledata.FilterWhere = filterWhere;
if (!string.IsNullOrWhiteSpace(fullPath))
mobiledata.LayerSource = fullPath;
_id++;
exportDataList.Add(mobiledata);
}
catch (Exception ex)
{
LogAPI.Debug(string.Format("{0}添加导出列表失败:" + ex));
MessageHelper.Show(string.Format("{0}添加导出列表失败:" + ex));
}
}
private void GetPiecsData(int mapGroupIndex, int pid, List<ILayer> layerList)
{
try
{
int tileIndex = -1;
List<IRasterLayer> rasterList = new List<IRasterLayer>();
List<IGroupLayer> tilesList = MapsManager.Instance.MapService.GetAllRasterGroupLayerInMap<IRasterLayer>();
foreach (var item in tilesList)
{
ILayerGeneralProperties grouplp = item as ILayerGeneralProperties;
if (grouplp.LayerDescription.ToLower().Contains(".mxd") || grouplp.LayerDescription.ToUpper() == "MXD_Group".ToUpper())
continue;
tileIndex = layerList.IndexOf(item);
MakeTaskPackageModel mobiledata = new MakeTaskPackageModel();
mobiledata.IsCheck = true;
mobiledata.IsSlice = false;
mobiledata.Type = "瓦片";
mobiledata.FileName = item.Name;
mobiledata.FileAliasName = item.Name;
mobiledata.Make = "未制作";
mobiledata.LayerIndex = 1;
mobiledata.MapGroupIndex = tileIndex;
mobiledata.MapGroupName = item.Name;
mobiledata.ID = _id;
mobiledata.PID = pid;
_id++;
ICompositeLayer pComLayer = item as ICompositeLayer;
mobiledata.Layer = GetAllLayerInGroupLayer<IRasterLayer>(pComLayer);
mobiledata.OutPath = @"Kingoit\phonemap_landsurvey\projects";
rasterList = mobiledata.Layer as List<IRasterLayer>;
GetBestLevelSize(rasterList);
exportDataList.Add(mobiledata);
}
}
catch (Exception ex)
{
LogAPI.Debug("获取列表瓦片数据失败:" + ex);
}
}
private string GetLayerPathByLayer(IFeatureLayer pFeatureLayer)
{
string fullPath = string.Empty;
try
{
if (pFeatureLayer != null && pFeatureLayer.FeatureClass != null)
{
string dataType = (pFeatureLayer.FeatureClass as FeatureClass).Category.Trim();
string pathName = (pFeatureLayer.FeatureClass as FeatureClass).Workspace.PathName;
string layerName = (pFeatureLayer.FeatureClass as FeatureClass).Name;
string dataSetName = string.Empty;
if (pFeatureLayer.FeatureClass.FeatureDataset != null)
{
dataSetName = pFeatureLayer.FeatureClass.FeatureDataset.Name;
}
if (dataType == "Shapefile 要素类")
{
fullPath = System.IO.Path.Combine(pathName, layerName + ".shp");
}
else
{
fullPath = System.IO.Path.Combine(pathName, dataSetName, layerName);
}
}
}
catch (Exception ex)
{
LogAPI.Debug("获取图层所在文件路径失败:" + ex);
}
return fullPath;
}
private void SetExportPath()
{
try
{
IWorkCatalog workCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IWorkCatalog>();
string code = (MapsManager.Instance.CurrProjectInfo as ProjectInfo).CODE;
string xzqmc = GetXZQMC(code);
string xzqDir = string.Format("{0}({1})", xzqmc, code);
if (workCatalog != null && !string.IsNullOrWhiteSpace(code))
{
string dirName = "外业调绘成果";
if (this.rdoWRJRWB.IsChecked == true)
dirName = "无人机举证成果";
string projectPath = System.IO.Path.Combine(workCatalog.SaveWorkSapcePath, xzqDir, dirName);
if (!System.IO.Directory.Exists(projectPath))
{
System.IO.Directory.CreateDirectory(projectPath);
}
this.txtExportPath.Text = projectPath;//设置默认的输出路径
}
}
catch (Exception ex)
{
LogAPI.Debug("设置输出路径失败:" + ex);
}
}
//获取行政区名称
private string GetXZQMC(string xzqdm)
{
string xzqmc = string.Empty;
KGIS.Framework.DBOperator.IRDBHelper rdbHelper = null;
try
{
string systemPath = SysAppPath.GetDataBasePath() + "System.mdb";
if (File.Exists(systemPath))
{
string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection");
connStr = string.Format(connStr, systemPath);
rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess);
string strSQL = string.Format("select OBJECTID AS ID, XZQ AS CODE,XZQMC AS NAME from XZQ Where XZQ = '{0}'", xzqdm);
//string strSQL = string.Format("select OBJECTID AS ID, XZQ AS CODE,XZQMC AS NAME from XZQ Where XZQ like '{0}%'", xzqdm);
DataTable dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true);
if (dt != null)
{
List<DataDicTionary> xzqCoderesult = TBToList.ToList<DataDicTionary>(dt);
foreach (var item in xzqCoderesult)
{
if (dt.Rows.Count == 1)
xzqmc = item.NAME;
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
//MessageHelper.Show("获取行政区名称失败:" + ex);
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
return xzqmc;
}
private List<IGroupLayer> GetGroupLayer(ref List<ILayer> NoGroupLayer)
{
List<IGroupLayer> result = new List<IGroupLayer>();
IMap map = MapsManager.Instance.MapService.getAxMapControl().Map;
IEnumLayer enumlayer = map.Layers;
ILayer layer = null;
while ((layer = enumlayer.Next()) != null)
{
if (!(layer is IGroupLayer))
{
if (NoGroupLayer == null)
NoGroupLayer = new List<ILayer>();
NoGroupLayer.Add(layer);
continue;
}
result.Add(layer as IGroupLayer);
}
return result;
}
private List<IGroupLayer> GetGroupListByIGroupLayer(IGroupLayer grouplayer)
{
List<IGroupLayer> grouplayerList = new List<IGroupLayer>();
ICompositeLayer pComLayer = grouplayer as ICompositeLayer;
for (int j = 0; j < pComLayer.Count; j++)
{
ILayer newLayer = pComLayer.get_Layer(j);
if (newLayer is IGroupLayer)
{
grouplayerList.Add(newLayer as IGroupLayer);
}
}
return grouplayerList;
}
private List<ILayer> GetLayer()
{
List<ILayer> result = new List<ILayer>();
ILayer jzrwlayer = MapsManager.Instance.MapService.GetGroupLayer("JZRWSJ");
if (jzrwlayer is IGroupLayer)
result.Add(jzrwlayer);
IMap map = MapsManager.Instance.MapService.getAxMapControl().Map;
for (int i = 0; i < map.LayerCount; i++)
{
ILayer layer = MapsManager.Instance.MapService.getAxMapControl().Map.get_Layer(i);
if (layer is IGroupLayer)
result.Add(layer);
}
return result;
}
public List<T> GetSubLayer<T>(ICompositeLayer group)
{
List<T> result = new List<T>();
for (int i = 0; i < group.Count; i++)
{
var item = group.Layer[i];
if (item is ICompositeLayer)
{
ILayerGeneralProperties lp = item as ILayerGeneralProperties;
if (lp.LayerDescription.ToLower().Contains(".mxd"))
continue;
result.AddRange(GetSubLayer<T>(item as ICompositeLayer));
}
else if (item is T)
{
result.Add((T)item);
}
}
return result;
}
public List<T> GetAllLayerInGroupLayer<T>(ICompositeLayer groupLayer)
{
List<T> allLayers = new List<T>();
if (groupLayer != null && groupLayer.Count > 0)
{
for (int i = 0; i < groupLayer.Count; i++)
{
ILayer layer = groupLayer.get_Layer(i);
if (layer is ICompositeLayer && !(layer is ESRI.ArcGIS.Carto.IAnnotationLayer))
{
List<T> list = GetAllLayerInGroupLayer<T>(layer as ICompositeLayer);
allLayers.AddRange(list);
}
else
{
if (layer is T)
{
allLayers.Add((T)layer);
}
}
}
}
return allLayers;
}
public List<T> GetAllLayerInThisGroupLayer<T>(ICompositeLayer groupLayer)
{
List<T> allLayers = new List<T>();
if (groupLayer != null && groupLayer.Count > 0)
{
for (int i = 0; i < groupLayer.Count; i++)
{
ILayer layer = groupLayer.get_Layer(i);
if (layer is T)
{
allLayers.Add((T)layer);
}
}
}
return allLayers;
}
private void RdoWYDHRWB_Click(object sender, RoutedEventArgs e)
{
try
{
GetExportDataList();
SetExportPath();
this.btnAddLayer.IsEnabled = true;
this.btnAddLayerGroup.IsEnabled = true;
this.btnExport.IsEnabled = true;
}
catch (Exception ex)
{
LogAPI.Debug("选择外业调绘任务包失败:" + ex);
MessageHelper.Show("选择外业调绘任务包失败:" + ex);
}
}
private void RdoWRJRWB_Click(object sender, RoutedEventArgs e)
{
try
{
GetWRJExportDataList();
SetExportPath();
List<MakeTaskPackageModel> modelList = this.exportDataList.FindAll(x => x.FileName == "JCTB" && x.Type == "举证任务");
if (modelList != null && modelList.Count != 0)
this.btnAddLayer.IsEnabled = false;
else
this.btnAddLayer.IsEnabled = true;
this.btnAddLayerGroup.IsEnabled = false;
this.btnExport.IsEnabled = true;
}
catch (Exception ex)
{
LogAPI.Debug("选择无人机任务包失败:" + ex);
MessageHelper.Show("选择无人机任务包失败:" + ex);
}
}
private string CheckFieldValue()
{
string msg = string.Empty;
try
{
List<MakeTaskPackageModel> modelList = this.exportDataList.FindAll(x => x.FileName == "JCTB" && x.FileAliasName == "监测图斑" && x.IsCheck == true);
if (modelList != null && modelList.Count != 0)
{
Dictionary<string, string> fieldsDic = new Dictionary<string, string>();
fieldsDic.Add("BSM", "标识码");
fieldsDic.Add("TBLX", "地块类型");
fieldsDic.Add("XZQDM", "县级行政区代码");
fieldsDic.Add("XMC", "县级行政区名称");
fieldsDic.Add("TBBH", "地块编号");
fieldsDic.Add("TBMJ", "地块面积");
fieldsDic.Add("XZB", "X坐标");
fieldsDic.Add("YZB", "Y坐标");
fieldsDic.Add("TBFW", "地块范围");
ILayer jctblayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB");
if (jctblayer != null)
{
IQueryFilter pQueryFilter = new QueryFilterClass();
IFeatureLayer pjctbFeatureLayer = jctblayer as IFeatureLayer;
foreach (var item in fieldsDic)
{
int fieldIndex = pjctbFeatureLayer.FeatureClass.FindField(item.Key);
if (fieldIndex > -1)
{
IField field = pjctbFeatureLayer.FeatureClass.Fields.Field[fieldIndex];
if (field.Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString)
{
pQueryFilter.WhereClause = string.Format("{0} is null or {0}=''", item.Key);
}
else if (field.Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble)
{
pQueryFilter.WhereClause = string.Format("{0} is null or {0}=0 or {0}=0.00", item.Key);
}
}
if (!string.IsNullOrWhiteSpace(pQueryFilter.WhereClause))
{
int count = pjctbFeatureLayer.FeatureClass.FeatureCount(pQueryFilter);
if (count > 0)
msg += string.Format("[{0}]字段存在空值\r\n", item.Value);
}
}
if (!string.IsNullOrWhiteSpace(msg))
msg = string.Format("请检查{0}:\r\n{1}", pjctbFeatureLayer.Name, msg);
}
}
}
catch (Exception ex)
{
LogAPI.Debug("验证监测图斑必填字段失败:" + ex);
MessageHelper.Show("验证监测图斑必填字段失败:" + ex);
return null;
}
return msg;
}
private void txtMaxScale_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
if (string.IsNullOrEmpty(txtMaxScale.Text))
return;
if (this.comMinScale == null)
return;
int MaxScale = 0;
int.TryParse(txtMaxScale.Text, out MaxScale);
this.comMinScale.Items.Clear();
var model = this.exportDataList.Find(x => x.FileName.Contains(".mxd"));
if (model != null)
{
this.maxDis = GetMaxDistance(model.LayerSource);
}
GetAllScale(MaxScale, maxDis);
}
catch
{
}
}
/// <summary>
/// 生成比例尺
/// </summary>
/// <param name="maxScale">最大比例尺</param>
/// <param name="maxDistance">最大距离</param>
/// <returns></returns>
private List<int> GetAllScale(int maxScale, double maxDistance)
{
List<int> lstScale = new List<int>();
double distance = 0;
int scaleNow = maxScale;
int minScale = (int)(maxDistance * 96 / (256 * 0.0254));
distance = scaleNow * 256 * 0.0254 / 96;
if (minScale <= scaleNow)
{
lstScale.Add(scaleNow);
this.comMinScale.Items.Add(scaleNow);
return lstScale;
}
lstScale.Add(maxScale);
while (minScale > scaleNow)
{
scaleNow = scaleNow * 2;
//distance = scaleNow * 256 * 0.0254 / 96;//计算实际距离
lstScale.Add(scaleNow);
this.comMinScale.Items.Add(scaleNow);
}
this.comMinScale.SelectedIndex = this.comMinScale.Items.Count - 1;
//lstScale.Add(minScale);
return lstScale;
}
/// <summary>
/// 全选/反选
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void checkAll_Click(object sender, RoutedEventArgs e)
{
if (this.exportDataList == null || this.exportDataList.Count <= 0) return;
for (int i = 0; i < this.exportDataList.Count; i++)
{
if (this.checkAll.IsChecked == true)
this.exportDataList[i].IsCheck = true;
else
this.exportDataList[i].IsCheck = false;
}
}
/// <summary>
/// 选择地数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSelectPlaceNameData_Click(object sender, RoutedEventArgs e)
{
try
{
KGIS.Framework.Utils.Dialog.OpenFileDialog dialog = new KGIS.Framework.Utils.Dialog.OpenFileDialog();
dialog.DefaultExt = ".xls";
dialog.Title = "请选择地名数据";
dialog.Filter = "Excel文件(*.xls)|*.xls|Excel文件(*.xlsx)|*.xlsx";
dialog.RestoreDirectory = true;
if (dialog.ShowDialog())
{
this.txtPlaceNameData.Text = dialog.FileName;
}
}
catch (Exception ex)
{
LogAPI.Debug("选择地名数据失败:" + ex);
}
}
/// <summary>
/// 下载地名模板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSelectPlaceNameTemplate_Click(object sender, RoutedEventArgs e)
{
var saveFileDialog = new Microsoft.Win32.SaveFileDialog()
{
Filter = "Excel Files(*.xls)|*.xls"
};
var result = saveFileDialog.ShowDialog();
if (result.Value)
{
var excelfileurl = saveFileDialog.FileName;
var sourcesfile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "工作空间", "模板", "地名数据模板", "地名数据.xls");
if (System.IO.File.Exists(sourcesfile))
{
try
{
System.IO.File.Copy(sourcesfile, excelfileurl, true);
if (MessageHelper.ShowYesNoAndTips("地名数据模板下载成功,是否打开?") == System.Windows.Forms.DialogResult.Yes)
{
Process.Start(excelfileurl);
}
}
catch (Exception ex)
{
LogAPI.Debug("下载地名数据模板失败,错误信息:" + ex);
MessageHelper.ShowError("下载地名数据模板失败,错误信息:" + ex);
}
}
else
{
MessageHelper.ShowError("地名数据模板文件不存在,导出失败!");
}
}
}
private void btnAddLayerGroup_Click(object sender, RoutedEventArgs e)
{
try
{
FrmAddListLayerGroup frm = new FrmAddListLayerGroup();
frm.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
frm.Width = 450;
frm.Height = 150;
frm.Refresh = RefreshExportList;
frm.exportDataList =this.exportDataList;
frm.ShowInMainWindow(true);
}
catch (Exception ex)
{
LogAPI.Debug("添加图层组名称失败:" + ex);
}
}
/// <summary>
/// 添加图层
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddLayer_Click(object sender, RoutedEventArgs e)
{
try
{
FrmAddListLayer frm = new FrmAddListLayer();
frm.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
frm.Width = 550;
frm.Height = 300;
if (this.rdoWRJRWB.IsChecked == true)
{
frm.isWRJRWB = true;
}
else
{
frm.isWRJRWB = false;
}
frm.Refresh = RefreshExportList;
frm.exportDataList = exportDataList;
frm.selectedRWDCZTInx = this.comRWDCZT.SelectedIndex;
frm.outPutPathCfg = outputPathCfg;
frm.ShowInMainWindow(true);
}
catch (Exception ex)
{
LogAPI.Debug("添加图层失败:" + ex);
MessageHelper.Show("添加图层失败:" + ex);
}
}
private void RefreshExportList()
{
try
{
this.rwzzTreeList.ItemsSource = null;
this.rwzzTreeList.ItemsSource =this.exportDataList;
if (this.rdoWRJRWB.IsChecked == true)
{
this.btnAddLayerGroup.IsEnabled = false;
this.btnAddLayer.IsEnabled = false;
}
else
{
this.btnAddLayerGroup.IsEnabled = true;
this.btnAddLayer.IsEnabled = true;
}
}
catch (Exception ex)
{
LogAPI.Debug("刷新列表数据失败:" + ex);
MessageHelper.Show("刷新列表数据失败:" + ex);
}
}
/// <summary>
/// 删除选中列表的数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDelLayer_Click(object sender, RoutedEventArgs e)
{
try
{
if (this.rwzzTreeList.ItemsSource == null)
{
MessageHelper.Show("列表数据为空,无法进行数据删除");
return;
}
if (this.rwzzTreeList.SelectedItem == null)
{
MessageHelper.Show("未选中需要删除的数据");
return;
}
delModelList = new List<MakeTaskPackageModel>();
MakeTaskPackageModel selectModel = this.rwzzTreeList.SelectedItem as MakeTaskPackageModel;
List<MakeTaskPackageModel> modelList = this.rwzzTreeList.ItemsSource as List<MakeTaskPackageModel>;
if (selectModel != null)
{
delModelList.Add(selectModel);
GetDelData(modelList, selectModel.ID);
if (delModelList.Count != 0)
{
foreach (var item in delModelList)
{
modelList.Remove(item);
}
}
this.rwzzTreeList.RefreshData();
}
if (this.rdoWRJRWB.IsChecked == true)
{
List<MakeTaskPackageModel> jzrwModelList = this.exportDataList.FindAll(x => x.Type == "举证任务");
if (jzrwModelList != null && jzrwModelList.Count != 0)
this.btnAddLayer.IsEnabled = false;
else
this.btnAddLayer.IsEnabled = true;
}
// List<MakeTaskPackageModel> delModelList = new List<MakeTaskPackageModel>();
// List<MakeTaskPackageModel> modelList = this.rwzzTreeList.ItemsSource as List<MakeTaskPackageModel>;
// if (modelList != null && modelList.Count != 0)
// {
// foreach (var item in modelList)
// {
// if (item.IsCheck == true)
// delModelList.Add(item);
// }
// }
// if (delModelList.Count != 0)
// {
// foreach (var item in delModelList)
// {
// modelList.Remove(item);
// }
// }
// this.rwzzTreeList.ItemsSource = modelList;
// this.exportDataList = modelList;
}
catch (Exception ex)
{
LogAPI.Debug("删除列表图层数据失败:" + ex);
MessageHelper.ShowError("删除列表图层数据失败:" + ex);
}
}
private void GetDelData(List<MakeTaskPackageModel> modelList, int id)
{
try
{
List<MakeTaskPackageModel> subModelList = modelList.FindAll(x => x.PID == id);
if (subModelList != null && subModelList.Count != 0)
{
string tableName = string.Empty;
foreach (var item in subModelList)
{
delModelList.Add(item);
GetDelData(modelList, item.ID);
}
}
}
catch (Exception ex)
{
LogAPI.Debug("获取删除数据失败:" + ex);
MessageHelper.ShowError("获取删除数据失败:" + ex);
}
}
/// <summary>
/// 举证任务图层选项发生改变时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void JzrwView_NodeCheckStateChanged(object sender, DevExpress.Xpf.Grid.TreeList.TreeListNodeEventArgs e)
{
try
{
if (e.Row != null)
{
MakeTaskPackageModel model = e.Row as MakeTaskPackageModel;
if (model.IsLayerGroup && model.Type == "图层组")
{
List<MakeTaskPackageModel> modelList = this.exportDataList.FindAll(x => x.PID == model.ID);
if (modelList != null && modelList.Count != 0)
{
foreach (MakeTaskPackageModel item in modelList)
{
item.IsCheck = model.IsCheck;
}
}
}
else if( model.Type != "瓦片")
{
List<MakeTaskPackageModel> parentModelList = this.exportDataList.FindAll(x => x.ID == model.PID);
if (parentModelList != null && parentModelList.Count != 0)
{
MakeTaskPackageModel parentModel = parentModelList[0];
if(parentModel.IsCheck!=model.IsCheck)
{
List<MakeTaskPackageModel> modelList = this.exportDataList.FindAll(x => x.PID == model.PID);
List<MakeTaskPackageModel> checkModelList = this.exportDataList.FindAll(x => x.PID == model.PID && x.IsCheck == true);
if (modelList.Count == checkModelList.Count)
parentModel.IsCheck = model.IsCheck;
else
{
parentModel.IsCheck = false;
foreach (MakeTaskPackageModel item in checkModelList)
{
item.IsCheck = true;
}
}
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("改变举证任务图层选项失败:" + ex);
MessageHelper.Show("改变举证任务图层选项失败:" + ex);
}
}
/// <summary>
/// 关闭窗体结束所有正在导出kotoles、ko文件的进程
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmMobileDataExport_Closing(object sender, CancelEventArgs e)
{
///获取影像生成kotiles的exe运行程序
Process[] rasterPros = Process.GetProcessesByName("Kingo.Plugin.RasterToKOTilesApp");
if (rasterPros != null && rasterPros.Count() != 0)
{
foreach (Process pro in rasterPros)
{
pro.Kill();
}
}
///获取shape生成ko的exe运行程序
Process[] shapePros = Process.GetProcessesByName("Kingo.Plugin.ShapeToKOApp");
if (shapePros != null && shapePros.Count() != 0)
{
foreach (Process pro in shapePros)
{
pro.Kill();
}
}
}
public class ParamConfig
{
//[DataMember]
public int WKID { get; set; }
//[DataMember]
public double DelX { get; set; }
//[DataMember]
public double DelY { get; set; }
//[DataMember]
public double DelZ { get; set; }
//[DataMember]
public double RX { get; set; }
//[DataMember]
public double RY { get; set; }
//[DataMember]
public double RZ { get; set; }
//[DataMember]
public double K { get; set; }
//[DataMember]
public double OX { get; set; }
//[DataMember]
public double OY { get; set; }
//[DataMember]
public bool IsValidLic { get; set; }
//[DataMember]
public bool IsAutoDeleteData { get; set; }
//[DataMember]
public bool IsDecryptData { get; set; }
//[DataMember]
public int ValidErrorTimes { get; set; }
//[DataMember]
public bool IsAutoDeleteNotUse { get; set; }
//[DataMember]
public int NoUseDays { get; set; }
//[DataMember]
public bool IsAutoDeleteLicExpired { get; set; }
public string ToJSON()
{
Newtonsoft.Json.JsonSerializerSettings pJsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings();
string json = Newtonsoft.Json.JsonConvert.SerializeObject(this, pJsonSerializerSettings);
return json;
}
public static ParamConfig FormJSON(string jsonString)
{
return (ParamConfig)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString, typeof(ParamConfig));
}
}
}
}