OutGIS.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. this.SetSize(500, 435);
  30. }
  31. protected override void OnLoad(EventArgs e)
  32. {
  33. LayerPanel = new LayerWithDataListPanel();
  34. LayerPanel.LoadToVector(true, true, true);
  35. uiGBlayer.Controls.Add(LayerPanel);
  36. }
  37. private void uiButton1_Click(object sender, EventArgs e)
  38. {
  39. SaveFileDialog sfd = new SaveFileDialog();
  40. sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
  41. sfd.Title = "请选择要保存的文件路径";
  42. sfd.Filter = "所有文件|*.*";
  43. sfd.RestoreDirectory = true;
  44. if (sfd.ShowDialog() == DialogResult.OK)
  45. {
  46. fileName = sfd.FileName;
  47. uiTextBox1.Text = fileName;
  48. }
  49. }
  50. public override object Do(DockPanel dockPanel = null)
  51. {
  52. this.IsShowResultWindow = false;
  53. if (string.IsNullOrEmpty(fileName))
  54. { UIMessageTip.ShowError("请选择要保存文件的路径"); return false; }
  55. if (LayerPanel.SelectLayers.Count == 0)
  56. { UIMessageTip.ShowError("请选择要保存文件的图层"); return false; }
  57. FileType outFileType = FileType.None;
  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)
  71. {
  72. outFileType = FileType.SimpleJson;
  73. }
  74. if (uiRadioButtonMDB.Checked)//ExportSettingPersonalGDBVector
  75. {
  76. outFileType = FileType.PersonalGDBVector;
  77. }
  78. DataExport ex = new DataExport();
  79. if (outFileType == FileType.CSV)
  80. {
  81. foreach (Layer lyr in LayerPanel.SelectLayers)
  82. {
  83. ExportSettingCSV es = new ExportSettingCSV();
  84. es.IsExportFieldName = true;
  85. es.IgnoreFieldNames = ComsStatic.HideEnableTag.ToLower().Trim(',').Split(",");//.Replace("x,", "").Replace("y,", "")
  86. es.TargetFileCharset = Charset.GB18030;
  87. es.TargetFileType = outFileType;
  88. es.TargetFilePath = fileName + "-" + lyr.Caption;
  89. System.Threading.Thread.Sleep(2);
  90. es.SourceData = lyr.Dataset as DatasetVector;
  91. ex.ExportSettings.Add(es);
  92. }
  93. }
  94. else
  95. {
  96. foreach (Layer lyr in LayerPanel.SelectLayers)
  97. {
  98. ExportSetting es = new ExportSetting();
  99. es.TargetFileType = outFileType;
  100. es.TargetFilePath = fileName + "-" + lyr.Caption;
  101. System.Threading.Thread.Sleep(2);
  102. es.SourceData = lyr.Dataset as DatasetVector;
  103. ex.ExportSettings.Add(es);
  104. }
  105. }
  106. ExportResult exResult = ex.Run();
  107. if (ex.ExportSettings.Count == exResult.SucceedSettings.Length)
  108. ComsStatic.ShowOKLog(string.Format("地图导出GIS数据" + outFileType.ToString() + ",应导出{0}条,共导出{1}条", ex.ExportSettings.Count, exResult.SucceedSettings.Length));
  109. else
  110. ComsStatic.ShowErrorLog(string.Format("地图导出GIS数据" + outFileType.ToString() + ",应导出{0}条,失败导出{1}条", ex.ExportSettings.Count, exResult.FailedSettings.Length));
  111. if (ComsStatic.Datasource.Datasets.Contains(dviName))
  112. ComsStatic.Datasource.Datasets.Delete(dviName);
  113. return true;
  114. }
  115. }
  116. }