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.
1013 lines
46 KiB
1013 lines
46 KiB
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.AE.Enum; |
|
using KGIS.Framework.AE.GaussCalculate; |
|
using KGIS.Framework.AE.GPHelper; |
|
using KGIS.Framework.DBOperator; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.OpenData.Control; |
|
using KGIS.Framework.OpenData.Filter; |
|
using KGIS.Framework.OpenData.InterFace; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Utils.Interface; |
|
using Kingo.Plugin.DTBYCL.Helper; |
|
using Kingo.Plugin.General.Helper; |
|
using Kingo.PluginServiceInterface; |
|
using Kingo.PluginServiceInterface.Model; |
|
using KUI.Windows; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Data; |
|
using System.Linq; |
|
using System.Windows; |
|
using IRDBHelper = KGIS.Framework.DBOperator.IRDBHelper; |
|
|
|
namespace Kingo.Plugin.DTBYCL.View |
|
{ |
|
/// <summary> |
|
/// UCYSResultExport.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class UCYSResultExport : BaseWindow |
|
{ |
|
private ProjectInfo ProjectInfo { get; set; } |
|
private List<string> lstFileName { get; set; } |
|
private USBFlashDiskHelper uSBFlashDiskHelper { get; set; } |
|
|
|
private UCSelectUSB uCSelectUSB = null; |
|
|
|
public UCYSResultExport(bool taskMultExport = false) |
|
{ |
|
InitializeComponent(); |
|
if (taskMultExport) |
|
{ |
|
this.btnExport.Visibility = Visibility.Collapsed; |
|
this.btnExportRW.Visibility = Visibility.Visible; |
|
this.btnImportCG.Visibility = Visibility.Visible; |
|
} |
|
else |
|
{ |
|
this.btnExport.Visibility = Visibility.Visible; |
|
this.btnExportRW.Visibility = Visibility.Collapsed; |
|
this.btnImportCG.Visibility = Visibility.Collapsed; |
|
} |
|
BindData(); |
|
} |
|
|
|
private void BindData() |
|
{ |
|
ProjectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (ProjectInfo == null) |
|
{ |
|
MessageHelper.ShowError("未检测到打开预审工程!"); |
|
return; |
|
} |
|
if (ProjectInfo.ListTaskPackage == null || ProjectInfo.ListTaskPackage.Count == 0) |
|
{ |
|
MessageHelper.Show("请先使用“任务目录设置或新建任务包”功能加载或创建外业任务包!"); |
|
return; |
|
} |
|
//List<TaskPackage> listDeletePackage = new List<TaskPackage>(); |
|
int i = 1; |
|
foreach (var item in ProjectInfo.ListTaskPackage) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
string dbPath = string.Empty; |
|
if (!string.IsNullOrWhiteSpace(item.PackageTempPath) && System.IO.File.Exists(item.PackageTempPath)) |
|
{ |
|
dbPath = item.PackageTempPath; |
|
} |
|
//else if (!string.IsNullOrWhiteSpace(item.PackagePath) && System.IO.File.Exists(item.PackagePath)) |
|
//{ |
|
// dbPath = item.PackagePath; |
|
//} |
|
else |
|
{ |
|
item.State = "未完成"; |
|
//listDeletePackage.Add(item); |
|
continue; |
|
} |
|
item.XH = i++; |
|
rdbHelper = RDBFactory.CreateDbHelper($"{dbPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
long count = (long)rdbHelper.ExecuteScalar("select count(*) from wyrw as a left join nyysresult as b on a.tbbsm=b.tbbsm where a.cdtb<>1 and b.tbbsm is null", CommandType.Text); |
|
if (count > 0) |
|
{ |
|
item.State = "未完成"; |
|
} |
|
else if (!item.State.Equals("已输出")) |
|
{ |
|
item.State = "完成"; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
//if (listDeletePackage.Count > 0) |
|
//{ |
|
// foreach (var item in listDeletePackage) |
|
// { |
|
// ProjectInfo.ListTaskPackage.Remove(item); |
|
// } |
|
//} |
|
if (!ProjectInfo.Save()) |
|
{ |
|
LogAPI.Debug("预审成果导出时工程保存失败!"); |
|
} |
|
gridPackage.ItemsSource = null; |
|
gridPackage.ItemsSource = ProjectInfo.ListTaskPackage; |
|
} |
|
|
|
/// <summary> |
|
/// 导出预处理成果 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void btnExport_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
if (ProjectInfo == null) |
|
{ |
|
MessageHelper.ShowError("未检测到打开预审工程!"); |
|
return; |
|
} |
|
if (string.IsNullOrWhiteSpace(EncryptionHelper.GetDogKey(1, ProjectInfo.CODE))) |
|
{ |
|
MessageHelper.Show("请插入加密狗!"); |
|
return; |
|
} |
|
lstFileName = new List<string>(); |
|
List<TaskPackage> listPackage = this.gridPackage.ItemsSource as List<TaskPackage>; |
|
if (listPackage.Where(x => x.State == "完成" || x.State.Equals("已输出")).Count() <= 0) |
|
{ |
|
MessageHelper.Show("当前没有可导出的预处理任务包!"); |
|
return; |
|
} |
|
if (this.gridPackage.SelectedItems == null || this.gridPackage.SelectedItems.Count <= 0) |
|
{ |
|
if (MessageHelper.ShowYesNoAndTips("是否导出全部“完成”的预处理成果?") != System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
return; |
|
} |
|
} |
|
else |
|
{ |
|
if (MessageHelper.ShowYesNoAndTips("是否导出选中“完成”的预处理成果?") != System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
return; |
|
} |
|
listPackage = new List<TaskPackage>(); |
|
foreach (TaskPackage item in this.gridPackage.SelectedItems) |
|
{ |
|
if (item.State == "完成" || item.State.Equals("已输出")) |
|
{ |
|
listPackage.Add(item); |
|
} |
|
} |
|
if (listPackage.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("所选数据没有“完成”的预处理任务包!"); |
|
return; |
|
} |
|
} |
|
System.Windows.Forms.DialogResult dialogResult = MessageHelper.ShowYesNoAndTips($"共选择{listPackage.Count}个任务包,是否确认输出?"); |
|
if (dialogResult != System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
return; |
|
} |
|
this.ShowLoading("正在导出预处理成果......", 0, 0); |
|
string tempPath = KGIS.Framework.Utils.SysAppPath.GetTempPath(); |
|
try |
|
{ |
|
//清空临时文件夹输出的临时成果包 |
|
if (!string.IsNullOrWhiteSpace(tempPath) && System.IO.Directory.Exists(tempPath)) |
|
{ |
|
string[] files = System.IO.Directory.GetFiles(tempPath, "*.ExportTemp"); |
|
if (files != null) |
|
{ |
|
foreach (var item in files) |
|
{ |
|
System.IO.File.Delete(item); |
|
} |
|
} |
|
} |
|
} |
|
catch |
|
{ |
|
} |
|
string ouputPath = System.IO.Path.Combine(ProjectInfo.TaskPath, "已输出"); |
|
if (!System.IO.Directory.Exists(ouputPath)) |
|
{ |
|
System.IO.Directory.CreateDirectory(ouputPath); |
|
} |
|
string message = string.Empty; |
|
foreach (var item in listPackage) |
|
{ |
|
if (string.IsNullOrWhiteSpace(item.PackageTempPath) || !System.IO.File.Exists(item.PackageTempPath)) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.Show(item.BID + "未打开初始化,请先“打开任务包”初始化!"); |
|
continue; |
|
} |
|
string savePackagePath = System.IO.Path.Combine(tempPath, item.BID + ".ExportTemp"); |
|
System.IO.File.Copy(item.PackageTempPath, savePackagePath, true); |
|
//if (!KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43")) |
|
//{ |
|
// this.UpdateMsg("正在进行重叠检查......"); |
|
// List<RuleEntity> lstResult = RuleCheckOpertion.StartYCLCheck(savePackagePath); |
|
// if (lstResult != null && lstResult.Count > 0) |
|
// { |
|
// this.CloseLoading(); |
|
// MessageHelper.Show(item.PackageTempPath + "质检不通过:" + lstResult[0].ErrorTip); |
|
// return; |
|
// } |
|
//} |
|
item.State = "已输出"; |
|
string fileName = DBLoadHelper.ExportDB(savePackagePath, ouputPath); |
|
lstFileName.Add(fileName); |
|
this.ProjectInfo.Save(); |
|
} |
|
if (!string.IsNullOrWhiteSpace(message)) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.Show(message); |
|
return; |
|
} |
|
//通知主任务树刷新批次列表 |
|
//KGIS.Framework.Platform.Platform.Instance.SendMsg(new Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "AfterLoadRefreshTreeData", Content = null }); |
|
this.BindData(); |
|
this.CloseLoading(); |
|
if (uSBFlashDiskHelper == null) |
|
{ |
|
uSBFlashDiskHelper = new USBFlashDiskHelper(); |
|
} |
|
uSBFlashDiskHelper.LoadUSB(); |
|
if (uSBFlashDiskHelper.lstUSB != null && uSBFlashDiskHelper.lstUSB.Count > 0 && MessageHelper.ShowYesNoAndTips("是否同时输出成果到移动存储中?") == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
if (uSBFlashDiskHelper.lstUSB.Count > 1) |
|
{ |
|
if (uCSelectUSB == null || uCSelectUSB.IsVisible == false) |
|
{ |
|
uCSelectUSB = new UCSelectUSB(); |
|
uCSelectUSB.Title = "选择将成果输出到移动存储?"; |
|
uCSelectUSB.WindowStartupLocation = WindowStartupLocation.CenterOwner; |
|
uCSelectUSB.RefreshTree = SyncUSBTask; |
|
uCSelectUSB.Topmost = true; |
|
uCSelectUSB.Show(); |
|
} |
|
uCSelectUSB.InitData(uSBFlashDiskHelper.lstUSB); |
|
} |
|
else |
|
{ |
|
if (uCSelectUSB != null) |
|
{ |
|
uCSelectUSB.Close(); |
|
uCSelectUSB = null; |
|
} |
|
SyncUSBTask(uSBFlashDiskHelper.lstUSB[0].Split('(')[0].Trim()); |
|
} |
|
} |
|
else |
|
{ |
|
if (System.IO.Directory.Exists(ouputPath)) |
|
{ |
|
if (MessageHelper.ShowYesNoAndTips("导出成功,是否查看结果?") == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
System.Diagnostics.Process.Start("explorer.exe", ouputPath); |
|
} |
|
} |
|
else |
|
{ |
|
MessageHelper.Show("导出成功!"); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
this.CloseLoading(); |
|
MessageHelper.ShowError("预审成果导出异常," + ex.Message); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
} |
|
} |
|
|
|
private void SyncUSBTask(string path) |
|
{ |
|
try |
|
{ |
|
if (lstFileName == null || lstFileName.Count <= 0 || !System.IO.Directory.Exists(path)) |
|
{ |
|
return; |
|
} |
|
string savePath = System.IO.Path.Combine(path, KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("UsbFolderName"), "2-预处理成果"); |
|
this.ShowLoading($"正在输出成果到:{savePath}......", 0, 0); |
|
if (!System.IO.Directory.Exists(savePath)) |
|
{ |
|
System.IO.Directory.CreateDirectory(savePath); |
|
} |
|
foreach (var fileName in lstFileName) |
|
{ |
|
if (!System.IO.File.Exists(fileName)) |
|
{ |
|
continue; |
|
} |
|
System.IO.File.Copy(fileName, System.IO.Path.Combine(savePath, System.IO.Path.GetFileName(fileName))); |
|
string signFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(fileName), System.IO.Path.GetFileNameWithoutExtension(fileName) + ".sign"); |
|
if (!string.IsNullOrWhiteSpace(signFileName) && System.IO.File.Exists(signFileName)) |
|
{ |
|
System.IO.File.Copy(signFileName, System.IO.Path.Combine(savePath, System.IO.Path.GetFileName(signFileName)), true); |
|
} |
|
} |
|
this.CloseLoading(); |
|
if (System.IO.Directory.Exists(savePath)) |
|
{ |
|
if (MessageHelper.ShowYesNoAndTips("导出成功,是否查看结果?") == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
System.Diagnostics.Process.Start("explorer.exe", savePath); |
|
} |
|
} |
|
else |
|
{ |
|
MessageHelper.Show("导出成功!"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.ShowError("输出成果拷贝移动存储异常:" + ex.Message); |
|
} |
|
} |
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e) |
|
{ |
|
this.Close(); |
|
} |
|
|
|
private void BtnRefresh_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
this.ShowLoading("正在刷新数据......", 0, 0); |
|
this.BindData(); |
|
this.CloseLoading(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 导出批量任务 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void BtnExportRW_Click(object sender, RoutedEventArgs e) |
|
{ |
|
System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = null; |
|
try |
|
{ |
|
if (ProjectInfo == null) |
|
{ |
|
MessageHelper.ShowError("未检测到打开预审工程!"); |
|
return; |
|
} |
|
if (this.gridPackage.SelectedItems.Count <= 0) |
|
{ |
|
MessageHelper.Show("请选择需要导出的预处理任务包!"); |
|
return; |
|
} |
|
Dictionary<string, string> dicPath = new Dictionary<string, string>(); |
|
foreach (TaskPackage item in this.gridPackage.SelectedItems) |
|
{ |
|
if (!string.IsNullOrWhiteSpace(item.PackageTempPath) && System.IO.File.Exists(item.PackageTempPath)) |
|
{ |
|
dicPath.Add(item.PackageName, item.PackageTempPath); |
|
} |
|
else if (System.IO.File.Exists(item.PackagePath)) |
|
{ |
|
dicPath.Add(item.PackageName, item.PackagePath); |
|
} |
|
else |
|
{ |
|
LogAPI.Debug("未找到任务包:" + item.PackagePath); |
|
continue; |
|
} |
|
} |
|
if (dicPath.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("所选任务包均未找到原始任务包路径!"); |
|
return; |
|
} |
|
folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); |
|
System.Windows.Forms.DialogResult dialogResult = folderBrowserDialog.ShowDialog(); |
|
if (dialogResult != System.Windows.Forms.DialogResult.OK) |
|
{ |
|
return; |
|
} |
|
this.ShowLoading("正在导出批量任务......", 0, 0); |
|
int wkid = ProjectInfo.GetCurentProjectedCoordinate().FactoryCode; |
|
if (wkid <= 0) |
|
{ |
|
CoordinateReferenceMapping coordinateReferenceMapping = CoordinateHelper.ListCoordinateReference.FirstOrDefault(x => (ProjectInfo.ZYJD > x.MinX && ProjectInfo.ZYJD < x.MaxX) || x.Central_Meridian.Equals(ProjectInfo.ZYJD)); |
|
if (coordinateReferenceMapping != null) |
|
{ |
|
wkid = coordinateReferenceMapping.WKID; |
|
} |
|
} |
|
string gdbPath = System.IO.Path.Combine(folderBrowserDialog.SelectedPath, "YSRW" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".gdb"); |
|
DecompressionDB decompressionDB = new DecompressionDB(); |
|
decompressionDB.MultDBToGDB(dicPath, gdbPath, wkid, EncryptionHelper.GetDogKey(1, this.ProjectInfo.CODE)); |
|
if (System.IO.Directory.Exists(gdbPath)) |
|
{ |
|
this.CloseLoading(); |
|
if (MessageHelper.ShowYesNoAndTips("导出成功,是否查看结果?") == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
System.Diagnostics.Process.Start("explorer.exe", folderBrowserDialog.SelectedPath); |
|
} |
|
} |
|
else |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.Show("导出成功!"); |
|
} |
|
this.Close(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
if (folderBrowserDialog != null) |
|
{ |
|
folderBrowserDialog.Dispose(); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 导入任务 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void BtnImportCG_Click(object sender, RoutedEventArgs e) |
|
{ |
|
IFeatureClass featureClass = null; |
|
try |
|
{ |
|
if (ProjectInfo == null) |
|
{ |
|
MessageHelper.ShowError("未检测到打开预审工程!"); |
|
return; |
|
} |
|
if (ProjectInfo.ListTaskPackage == null || ProjectInfo.ListTaskPackage.Count == 0) |
|
{ |
|
MessageHelper.Show("请先使用“任务目录设置或新建任务包”功能加载或创建预处理任务包!"); |
|
return; |
|
} |
|
if (this.gridPackage.SelectedItems == null || this.gridPackage.SelectedItems.Count <= 0) |
|
{ |
|
MessageHelper.Show("请从列表中勾选需要导入的图斑!"); |
|
return; |
|
} |
|
List<TaskPackage> lstPackages = new List<TaskPackage>(); |
|
foreach (TaskPackage item in this.gridPackage.SelectedItems) |
|
{ |
|
lstPackages.Add(item); |
|
} |
|
Dictionary<string, string> dicPath = new Dictionary<string, string>(); |
|
foreach (TaskPackage item in lstPackages) |
|
{ |
|
if (dicPath.ContainsKey(item.PackageName)) |
|
{ |
|
continue; |
|
} |
|
if (!string.IsNullOrWhiteSpace(item.PackageTempPath) && System.IO.File.Exists(item.PackageTempPath)) |
|
{ |
|
dicPath.Add(item.PackageName, item.PackageTempPath); |
|
} |
|
else if (System.IO.File.Exists(item.PackagePath)) |
|
{ |
|
dicPath.Add(item.PackageName, item.PackagePath); |
|
} |
|
else |
|
{ |
|
LogAPI.Debug("未找到任务包:" + item.PackagePath); |
|
continue; |
|
} |
|
} |
|
if (dicPath.Count <= 0) |
|
{ |
|
MessageHelper.ShowTips("所选任务包均未找到原始任务包路径!"); |
|
return; |
|
} |
|
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 == esriDatasetType.esriDTFeatureClass) |
|
{ |
|
featureClass = (distObj.DatasetName as ESRI.ArcGIS.esriSystem.IName).Open() as IFeatureClass; |
|
} |
|
} |
|
} |
|
if (featureClass == null) |
|
{ |
|
MessageHelper.Show("请选择矢量成果图层!"); |
|
return; |
|
} |
|
dialogResult = MessageHelper.ShowYesNoCancelAndTips("导入前是否清空已有自主图斑?选择“Yes”则清空,选择“No”则追加,选择“Cancel”终止导入"); |
|
if (dialogResult == System.Windows.Forms.DialogResult.Cancel) |
|
{ |
|
MessageHelper.Show("终止导入!"); |
|
return; |
|
} |
|
bool isConvert = false; |
|
if (dialogResult == System.Windows.Forms.DialogResult.Yes) |
|
{ |
|
isConvert = true; |
|
} |
|
this.ShowLoading("正在获取当前地图坐标参考......", 0, 0); |
|
int wkid = ProjectInfo.GetCurentProjectedCoordinate().FactoryCode; |
|
if (wkid <= 0) |
|
{ |
|
CoordinateReferenceMapping coordinateReferenceMapping = CoordinateHelper.ListCoordinateReference.FirstOrDefault(x => (ProjectInfo.ZYJD > x.MinX && ProjectInfo.ZYJD < x.MaxX) || x.Central_Meridian.Equals(ProjectInfo.ZYJD)); |
|
if (coordinateReferenceMapping != null) |
|
{ |
|
wkid = coordinateReferenceMapping.WKID; |
|
} |
|
} |
|
int importCount = 0; |
|
this.UpdateMsg("正在对选择图层进行自相交拓扑检查......"); |
|
CheckFeatureClass(featureClass, wkid); |
|
this.UpdateMsg("正在导入批量预处理数据......"); |
|
string message = string.Empty; |
|
ImportFeatureClass(dicPath, featureClass, ref importCount, ref message, isConvert); |
|
this.CloseLoading(); |
|
Platform.Instance.SendMsg(new NotifyMsgPackage() { MsgType = "AfterLoadRefreshTreeData" }); |
|
if (string.IsNullOrWhiteSpace(message)) |
|
{ |
|
message = $"成功导入{importCount}个图斑!"; |
|
} |
|
else |
|
{ |
|
message = $"成功导入{importCount}个图斑,ObjectID={message.TrimEnd(',')}的图斑面积小于50,不予导入!"; |
|
} |
|
MessageHelper.Show(message); |
|
this.Close(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.CloseLoading(); |
|
LogAPI.Debug("导入失败:" + ex.Message); |
|
LogAPI.Debug("导入失败:" + ex.StackTrace); |
|
MessageHelper.ShowError("导入失败:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
if (featureClass != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass); |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 检查图层坐标参考、自相交 |
|
/// </summary> |
|
/// <param name="featureClass"></param> |
|
/// <param name="wkid"></param> |
|
private void CheckFeatureClass(IFeatureClass featureClass, int wkid) |
|
{ |
|
ITable table = null; |
|
ICursor cursor = null; |
|
IRow row = null; |
|
try |
|
{ |
|
if (!KGIS.Framework.AE.GeoDBAPI.SpatialReferenceCompareByWkid(wkid, (featureClass as IGeoDataset).SpatialReference)) |
|
{ |
|
throw new Exception("选择矢量数据坐标参考与当前任务包不一致,无法导入!"); |
|
} |
|
if (featureClass.FindField("PackName") == -1) |
|
{ |
|
throw new Exception("选择图层不存在PackName字段,无法映射导入对应的任务包!"); |
|
} |
|
string OutFeatureClassPath = System.IO.Path.GetPathRoot(SysAppPath.GetTempPath()) + "UsersKingo"; |
|
if (System.IO.Directory.Exists(OutFeatureClassPath)) |
|
System.IO.Directory.Delete(OutFeatureClassPath, true); |
|
System.IO.Directory.CreateDirectory(OutFeatureClassPath); |
|
GPParamClass gPParamClass = new KGIS.Framework.AE.GPHelper.GPParamClass() |
|
{ |
|
ListInFeatureClassPath = new List<string>() { System.IO.Path.Combine((featureClass as FeatureClass).Workspace.PathName, (featureClass as FeatureClass).BrowseName) }, |
|
OutFeatureClassPath = System.IO.Path.Combine(OutFeatureClassPath, "Check" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 5)), |
|
IsGetOutPutFeature = true |
|
}; |
|
//GPParamClass gPParamClass = new GPParamClass() |
|
//{ |
|
// ListInFeatureClassPath = new List<string>() { System.IO.Path.Combine((featureClass as FeatureClass).Workspace.PathName, (featureClass as FeatureClass).BrowseName) }, |
|
// OutFeatureClassPath = System.IO.Path.Combine(SysAppPath.GetTempPath(), "Check" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 5)), |
|
// IsGetOutPutFeature = true |
|
//}; |
|
GeoprocessorHelper.CheckGeometry(gPParamClass, ref table); |
|
if (table != null) |
|
{ |
|
cursor = table.Search(null, true); |
|
int fieldOIDIndex = table.FindField("FEATURE_ID"); |
|
int fieldProblemIndex = table.FindField("PROBLEM"); |
|
string message = string.Empty; |
|
while ((row = cursor.NextRow()) != null) |
|
{ |
|
if (fieldOIDIndex > -1) |
|
{ |
|
message += "OBJECTID=" + row.get_Value(fieldOIDIndex); |
|
} |
|
if (fieldProblemIndex > -1) |
|
{ |
|
message += row.get_Value(fieldProblemIndex) + ";"; |
|
} |
|
} |
|
if (!string.IsNullOrWhiteSpace(message)) |
|
{ |
|
LogAPI.Debug("图斑存在质检问题:" + message); |
|
//throw new Exception("图斑存在质检问题,问题图斑请查看日志信息,修改后重试!"); |
|
throw new Exception(message); |
|
} |
|
} |
|
if (OverlapCheck(featureClass, (featureClass as IGeoDataset).SpatialReference as IProjectedCoordinateSystem)) |
|
{ |
|
throw new Exception("所选图层面存在重叠,无法导入!"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (row != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(row); |
|
} |
|
if (table != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(table); |
|
} |
|
} |
|
} |
|
|
|
#region 检查图层内面是否重叠 |
|
/// <summary> |
|
/// 图层内面重叠检查 |
|
/// </summary> |
|
/// <returns></returns> |
|
private bool OverlapCheck(IFeatureClass featureClassDLTB, IProjectedCoordinateSystem spatialReference) |
|
{ |
|
IFeatureDataset featureDataset = null; |
|
IWorkspaceAPI workspaceAPI = null; |
|
IFeatureClassAPI featureClassAPI = null; |
|
try |
|
{ |
|
string tempMdb = GetTempMDB(Guid.NewGuid().ToString().Replace("-", "") + ".mdb"); |
|
workspaceAPI = new WorkspaceAPI(tempMdb, WorkspaceTypeEnum.MDBFile); |
|
featureDataset = CreateFeatureDataset(workspaceAPI.CurrentWorkspace, "TDBZSJJ", spatialReference); |
|
double tolerance = 0.0001; |
|
SetGeoDatasetSpatialReference(workspaceAPI.CurrentWorkspace, spatialReference, tolerance); |
|
//设置坐标参考精度XYUnits 为二万分之一 |
|
try |
|
{ |
|
workspaceAPI.CurrentWorkspace.ExecuteSQL(string.Format("UPDATE GDB_SpatialRefs SET XYUnits = 20000 ,XYTolerance = {0}", tolerance)); |
|
} |
|
catch |
|
{ |
|
} |
|
string featureClassName = (featureClassDLTB as FeatureClass).BrowseName; |
|
GeoprocessorHelper.FeatureClassToFeatureClass(featureClassDLTB, System.IO.Path.Combine(tempMdb, "TDBZSJJ"), featureClassName); |
|
featureClassAPI = workspaceAPI.OpenFeatureClass(featureClassName); |
|
// 创建拓扑规则 |
|
List<ITopologyRule> lstRule = new List<ITopologyRule>(); |
|
ITopologyRule topologyRule = new TopologyRuleClass(); |
|
topologyRule.TopologyRuleType = esriTopologyRuleType.esriTRTAreaNoOverlap;//面要素间无重叠 |
|
topologyRule.Name = "esriTRTAreaNoOverlap";//面要素间无重叠 |
|
topologyRule.OriginClassID = featureClassAPI.FeatureClass.FeatureClassID; |
|
topologyRule.AllOriginSubtypes = true; |
|
topologyRule.OriginSubtype = 1; |
|
lstRule.Add(topologyRule); |
|
return PluginServiceInterface.Helper.DataCheckTopologyHelper.CreateTopology(lstRule, workspaceAPI.CurrentWorkspace, new List<string>() { featureClassName }); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("检查图层内面是否重叠异常:" + ex.Message); |
|
LogAPI.Debug("检查图层内面是否重叠异常:" + ex); |
|
LogAPI.Debug("检查图层内面是否重叠异常:" + ex.StackTrace); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (featureDataset != null) |
|
{ |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureDataset); |
|
} |
|
if (featureClassAPI != null) |
|
{ |
|
featureClassAPI.CloseFeatureClass(); |
|
} |
|
if (workspaceAPI != null) |
|
{ |
|
workspaceAPI.CloseWorkspace(); |
|
} |
|
} |
|
} |
|
/// <summary> |
|
/// 获取临时TempMdb |
|
/// </summary> |
|
/// <returns>返回路径字符串,末尾包括斜杠</returns> |
|
public static string GetTempMDB(string tempMDBName = "") |
|
{ |
|
string templetePath = SysAppPath.GetCurrentAppPath() + @"工作空间DTBJK\DatabaseTemplate\TempMDB.mdb"; |
|
if (!System.IO.File.Exists(templetePath)) |
|
{ |
|
throw new Exception("未找到模板:" + templetePath); |
|
} |
|
string tempMDBPath = System.IO.Path.Combine(GetTempPath(), string.IsNullOrWhiteSpace(tempMDBName) ? "TempMDB.mdb" : tempMDBName); |
|
if (!System.IO.File.Exists(tempMDBPath)) |
|
{ |
|
System.IO.File.Copy(templetePath, tempMDBPath, true); |
|
} |
|
return tempMDBPath; |
|
} |
|
|
|
/// <summary> |
|
/// 获取当前程序下的临时temp目录。支持BS和CS的程序,都是获取到app\Temp目录下,如果没有则创建该路径 |
|
/// </summary> |
|
/// <returns>返回路径字符串,末尾包括斜杠</returns> |
|
public static string GetTempPath() |
|
{ |
|
string strPath = SysAppPath.GetCurrentAppPath(); |
|
strPath += @"Temp\"; |
|
if (System.IO.Directory.Exists(strPath) == false) |
|
{ |
|
System.IO.Directory.CreateDirectory(strPath); |
|
} |
|
return strPath; |
|
} |
|
/// <summary> |
|
/// 给指定工作空间中的对象设置空间参考 |
|
/// </summary> |
|
/// <param name="pWS">工作空间</param> |
|
/// <param name="pSR">空间参考对象</param> |
|
/// <param name="pTolerance">数据库容差</param> |
|
private void SetGeoDatasetSpatialReference(IWorkspace pWS, ISpatialReference pSR, double pTolerance) |
|
{ |
|
try |
|
{ |
|
if (pSR != null) |
|
{ |
|
ISpatialReferenceTolerance tolerance = pSR as ISpatialReferenceTolerance; |
|
if (tolerance != null) |
|
{ |
|
tolerance.XYTolerance = pTolerance; |
|
tolerance.ZTolerance = pTolerance; |
|
tolerance.MTolerance = pTolerance; |
|
} |
|
} |
|
IEnumDataset pEnumDataset = pWS.Datasets[esriDatasetType.esriDTFeatureDataset]; |
|
IDataset ds = null; |
|
if (pEnumDataset != null) |
|
{ |
|
while ((ds = pEnumDataset.Next()) != null) |
|
{ |
|
if (ds is IGeoDataset) |
|
{ |
|
if ((ds as IGeoDataset).SpatialReference != pSR) |
|
(ds as IGeoDatasetSchemaEdit).AlterSpatialReference(pSR); |
|
|
|
} |
|
} |
|
} |
|
pEnumDataset = pWS.Datasets[esriDatasetType.esriDTFeatureClass]; |
|
if (pEnumDataset == null) |
|
{ |
|
return; |
|
} |
|
while ((ds = pEnumDataset.Next()) != null) |
|
{ |
|
if (ds is IGeoDataset) |
|
{ |
|
if ((ds as IGeoDataset).SpatialReference != pSR) |
|
(ds as IGeoDatasetSchemaEdit).AlterSpatialReference(pSR); |
|
} |
|
} |
|
//设置坐标参考精度XYUnits 为二万分之一 |
|
try |
|
{ |
|
pWS.ExecuteSQL(string.Format("UPDATE GDB_SpatialRefs SET XYUnits = 20000 ,XYTolerance = {0}", pTolerance)); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw new Exception("设置坐标参考坐标精度和容差异常:" + ex.Message); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 创建要素数据集 |
|
/// </summary> |
|
/// <param name="workspace"></param> |
|
/// <param name="code"></param> |
|
/// <param name="datasetName"></param> |
|
/// <returns></returns> |
|
private IFeatureDataset CreateFeatureDataset(IWorkspace workspace, string datasetName, IProjectedCoordinateSystem spatialReference) |
|
{ |
|
try |
|
{ |
|
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; |
|
//确定是否支持高精度存储空间 |
|
Boolean supportsHighPrecision = false; |
|
IWorkspaceProperties workspaceProperties = (IWorkspaceProperties)workspace; |
|
IWorkspaceProperty workspaceProperty = workspaceProperties.get_Property |
|
(esriWorkspacePropertyGroupType.esriWorkspacePropertyGroup, |
|
(int)esriWorkspacePropertyType.esriWorkspacePropSupportsHighPrecisionStorage); |
|
if (workspaceProperty.IsSupported) |
|
{ |
|
supportsHighPrecision = Convert.ToBoolean(workspaceProperty.PropertyValue); |
|
} |
|
//设置投影精度 |
|
IControlPrecision2 controlPrecision = (IControlPrecision2)spatialReference; |
|
controlPrecision.IsHighPrecision = supportsHighPrecision; |
|
//设置容差 |
|
ISpatialReferenceResolution spatialRefResolution = (ISpatialReferenceResolution)spatialReference; |
|
spatialRefResolution.ConstructFromHorizon(); |
|
spatialRefResolution.SetDefaultXYResolution(); |
|
ISpatialReferenceTolerance spatialRefTolerance = (ISpatialReferenceTolerance)spatialReference; |
|
spatialRefTolerance.SetDefaultXYTolerance(); |
|
//创建要素集 |
|
IFeatureDataset featureDataset = featureWorkspace.CreateFeatureDataset(datasetName, spatialReference); |
|
return featureDataset; |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
#endregion |
|
/// <summary> |
|
/// 导入任务包 |
|
/// </summary> |
|
/// <param name="dicPath"></param> |
|
/// <param name="featureClass">要导入的矢量图层</param> |
|
/// <param name="importCount">成功导入的图斑个数</param> |
|
/// <param name="isConvert">是否覆盖原有任务包中的自主变更图斑</param> |
|
private void ImportFeatureClass(Dictionary<string, string> dicPath, IFeatureClass featureClass, ref int importCount, ref string message, bool isConvert = false) |
|
{ |
|
IFeatureCursor featureCursor = null; |
|
IFeature feature = null; |
|
try |
|
{ |
|
string fields = "XZQDM,XZDM,CJDM,JCBH,TBLX,CDTB"; |
|
foreach (var item in dicPath) |
|
{ |
|
IRDBHelper rdbHelper = null; |
|
try |
|
{ |
|
rdbHelper = RDBFactory.CreateDbHelper($"{item.Value}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); |
|
rdbHelper.BeginTransaction(); |
|
if (isConvert) |
|
{ |
|
rdbHelper.ExecuteNonQueryWithException("delete from wyrw where sjly='ZZBG'", CommandType.Text); |
|
} |
|
IQueryFilter queryFilter = new QueryFilterClass() |
|
{ |
|
WhereClause = $"PackName='{item.Key }' AND SJLY='ZZBG'" |
|
}; |
|
string excuteSQL = "insert into wyrw(TBBSM,SJLY,TBMJ,Geometry,EGeometry,ZXDX,ZXDY,MAXX,MAXY,MINX,MINY,CDTB,{0})values({1})"; |
|
featureCursor = featureClass.Search(queryFilter, true); |
|
while ((feature = featureCursor.NextFeature()) != null) |
|
{ |
|
//double jcmj = ATEllipseArea.GetPolygonArea(feature.ShapeCopy as ESRI.ArcGIS.Geometry.IPolygon); |
|
double jcmj = 0; |
|
ESRI.ArcGIS.Geometry.IArea area = feature.ShapeCopy as ESRI.ArcGIS.Geometry.IArea; |
|
if (area.Area < 50) |
|
{ |
|
message += feature.OID + ","; |
|
continue; |
|
} |
|
ESRI.ArcGIS.esriSystem.IClone clone = feature.ShapeCopy as ESRI.ArcGIS.esriSystem.IClone; |
|
ESRI.ArcGIS.Geometry.IGeometry cloneGeometry = clone.Clone() as ESRI.ArcGIS.Geometry.IGeometry; |
|
string egeometry = GeometryConvertHelper.ConverIGometryToJson(cloneGeometry); |
|
|
|
ESRI.ArcGIS.Geometry.IEnvelope envelope = cloneGeometry.Envelope; |
|
area = cloneGeometry as ESRI.ArcGIS.Geometry.IArea; |
|
string valueString = $"'{Guid.NewGuid().ToString()}','ZZBG',{jcmj},'{egeometry}','{egeometry}',{area.Centroid.X},{area.Centroid.Y},{envelope.XMax},{envelope.YMax},{envelope.XMin},{envelope.YMin},'0'"; |
|
foreach (var fieldName in fields.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) |
|
{ |
|
int fieldIndex = feature.Fields.FindField(fieldName); |
|
if (fieldIndex == -1) |
|
{ |
|
valueString += ",null"; |
|
continue; |
|
} |
|
IField field = feature.Fields.Field[fieldIndex]; |
|
object obj = feature.get_Value(fieldIndex); |
|
switch (field.Type) |
|
{ |
|
case esriFieldType.esriFieldTypeSmallInteger: |
|
case esriFieldType.esriFieldTypeInteger: |
|
case esriFieldType.esriFieldTypeSingle: |
|
if (obj is DBNull || obj == null) |
|
{ |
|
valueString += ",0"; |
|
} |
|
else |
|
{ |
|
valueString += "," + int.Parse(obj.ToString()); |
|
} |
|
break; |
|
case esriFieldType.esriFieldTypeDouble: |
|
if (obj is DBNull || obj == null) |
|
{ |
|
valueString += ",0"; |
|
} |
|
else |
|
{ |
|
valueString += "," + double.Parse(obj.ToString()); |
|
} |
|
break; |
|
default: |
|
if (obj is DBNull || obj == null) |
|
{ |
|
valueString += ",null"; |
|
} |
|
else |
|
{ |
|
valueString += ",'" + obj.ToString().Trim() + "'"; |
|
} |
|
break; |
|
} |
|
} |
|
rdbHelper.ExecuteNonQueryWithException(string.Format(excuteSQL, fields, valueString), CommandType.Text); |
|
importCount++; |
|
} |
|
rdbHelper.Commit(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.Rollback(); |
|
} |
|
LogAPI.Debug("UCYSResultExport.ImportFeatureClass 写入矢量数据失败:" + ex.Message); |
|
LogAPI.Debug("UCYSResultExport.ImportFeatureClass 写入矢量数据失败:" + ex.StackTrace); |
|
throw ex; |
|
} |
|
finally |
|
{ |
|
if (rdbHelper != null) |
|
{ |
|
rdbHelper.DisConnect(); |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("UCYSResultExport.ImportFeatureClass 失败:" + ex.Message); |
|
LogAPI.Debug("UCYSResultExport.ImportFeatureClass 失败:" + ex.StackTrace); |
|
throw ex; |
|
} |
|
} |
|
} |
|
}
|
|
|