OutGIS.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using Sunny.UI;
  12. using WeifenLuo.WinFormsUI.Docking;
  13. using SuperMap.Mapping;
  14. using WWPipeLine.MapBasic;
  15. using SuperMap.Data.Conversion;
  16. using SuperMap.Data;
  17. namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
  18. {
  19. public partial class OutGIS : ConditionPanel
  20. {
  21. private LayerWithDataListPanel LayerPanel;
  22. private string fileName = string.Empty;
  23. private string fileType = string.Empty;
  24. private string dviName = string.Empty;
  25. public OutGIS()
  26. {
  27. this.ConditionPanelName = "地图输出GIS数据文件";
  28. InitializeComponent();
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. LayerPanel = new LayerWithDataListPanel();
  33. LayerPanel.LoadToVector(true);
  34. uiGBlayer.Controls.Add(LayerPanel);
  35. }
  36. private void uiButton1_Click(object sender, EventArgs e)
  37. {
  38. SaveFileDialog sfd = new SaveFileDialog();
  39. sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
  40. sfd.Title = "请选择要保存的文件路径";
  41. sfd.Filter = "所有文件|*.*";
  42. sfd.RestoreDirectory = true;
  43. if (sfd.ShowDialog() == DialogResult.OK)
  44. {
  45. fileName = sfd.FileName;
  46. uiTextBox1.Text = fileName;
  47. }
  48. }
  49. public override object Do(DockPanel dockPanel = null)
  50. {
  51. this.IsShowResultWindow = false;
  52. if (string.IsNullOrEmpty(fileName))
  53. { UIMessageTip.ShowError("请选择要保存文件的路径"); return false; }
  54. if (LayerPanel.SelectLayers.Count == 0)
  55. { UIMessageTip.ShowError("请选择要保存文件的图层"); return false; }
  56. FileType outFileType = FileType.None;
  57. DataExport ex = new DataExport();
  58. if (uiRadioButtonCSV.Checked)//ExportSettingCSV
  59. {
  60. outFileType = FileType.CSV;
  61. }
  62. if (uiRadioButtonGDB.Checked)//ExportSettingFileGDBVector
  63. {
  64. outFileType = FileType.FileGDBVector;
  65. }
  66. if (uiRadioButtonSHP.Checked)//ExportSettingSHP
  67. {
  68. outFileType = FileType.SHP;
  69. }
  70. if (uiRadioButtonSimpleJson.Checked)//ExportSettingPersonalGDBVector
  71. {
  72. outFileType = FileType.SimpleJson;
  73. }
  74. foreach (Layer lyr in LayerPanel.SelectLayers)
  75. {
  76. ExportSetting es = new ExportSetting();
  77. es.TargetFileType = outFileType;
  78. es.TargetFilePath = fileName + "-" + DateTime.Now.Ticks.ToString();
  79. System.Threading.Thread.Sleep(2);
  80. es.SourceData = lyr.Dataset as DatasetVector;
  81. ex.ExportSettings.Add(es);
  82. }
  83. ExportResult exResult = ex.Run();
  84. if (ex.ExportSettings.Count == exResult.SucceedSettings.Length)
  85. ComsStatic.ShowOKLog(string.Format("地图导出GIS数据" + outFileType.ToString() + ",应导出{0}条,共导出{1}条", ex.ExportSettings.Count, exResult.SucceedSettings.Length));
  86. else
  87. ComsStatic.ShowErrorLog(string.Format("地图导出GIS数据" + outFileType.ToString() + ",应导出{0}条,失败导出{1}条", ex.ExportSettings.Count, exResult.FailedSettings.Length));
  88. if (ComsStatic.Datasource.Datasets.Contains(dviName))
  89. ComsStatic.Datasource.Datasets.Delete(dviName);
  90. return true;
  91. }
  92. }
  93. }