OutGIS.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. public bool isGeo = false;
  24. private GeoRegion geo = null;
  25. public OutGIS()
  26. {
  27. this.ConditionPanelName = "地图输出GIS数据文件";
  28. this.IsShowResultWindow = false;
  29. InitializeComponent();
  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. if (isGeo)
  37. {
  38. MapControl.Action = SuperMap.UI.Action.CreatePolygon;
  39. MapControl.Tracked += ComsStatic.MapControl_Tracked_TrackingName;
  40. }
  41. }
  42. private void uiButton1_Click(object sender, EventArgs e)
  43. {
  44. SaveFileDialog sfd = new SaveFileDialog();
  45. sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
  46. sfd.Title = "请选择要保存的文件路径";
  47. sfd.Filter = "所有文件|*.*";
  48. sfd.RestoreDirectory = true;
  49. if (sfd.ShowDialog() == DialogResult.OK)
  50. {
  51. fileName = sfd.FileName;
  52. uiTextBox1.Text = fileName;
  53. }
  54. }
  55. public override object Do(DockPanel dockPanel = null)
  56. {
  57. if (isGeo)
  58. {
  59. int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName);
  60. if (index == -1)
  61. {
  62. Sunny.UI.UIMessageTip.ShowError("请先绘制统区域"); return false;
  63. }
  64. geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion;
  65. }
  66. if (string.IsNullOrEmpty(fileName))
  67. { UIMessageTip.ShowError("请选择要保存文件的路径"); return false; }
  68. if (LayerPanel.SelectLayers.Count == 0)
  69. { UIMessageTip.ShowError("请选择要保存文件的图层"); return false; }
  70. FileType outFileType = FileType.None;
  71. if (uiRadioButtonCSV.Checked) outFileType = FileType.CSV;
  72. if (uiRadioButtonGDB.Checked) outFileType = FileType.FileGDBVector;
  73. if (uiRadioButtonSHP.Checked) outFileType = FileType.SHP;
  74. if (uiRadioButtonSimpleJson.Checked) outFileType = FileType.SimpleJson;
  75. if (uiRadioButtonMDB.Checked) outFileType = FileType.PersonalGDBVector;
  76. DataExport ex = new DataExport();
  77. if (isGeo)
  78. {
  79. foreach (Layer lyr in LayerPanel.SelectLayers)
  80. {
  81. ExportSetting es = new ExportSetting();
  82. es.TargetFileType = outFileType;
  83. es.TargetFilePath = fileName + "-" + lyr.Caption;
  84. string dviName = ComsStatic.DatasourceMemory.Datasets.GetAvailableDatasetName("OutGIS_dvName");
  85. DatasetVector dv = lyr.Dataset as DatasetVector;
  86. DatasetVector dvFinal = ComsStatic.DatasourceMemory.Datasets.Create(new DatasetVectorInfo() { Name = dviName, Type = dv.Type });
  87. dvFinal.AppendFields(dv, "SmUserID", "smuserid", ComsStatic.GetFieldInfos(dv));
  88. dvFinal.Append(dv.Query(geo, 0, CursorType.Static));
  89. es.SourceData = dvFinal;
  90. ex.ExportSettings.Add(es);
  91. }
  92. }
  93. else
  94. {
  95. if (outFileType == FileType.CSV)
  96. {
  97. foreach (Layer lyr in LayerPanel.SelectLayers)
  98. {
  99. ExportSettingCSV es = new ExportSettingCSV();
  100. es.IsExportFieldName = true;
  101. es.IgnoreFieldNames = ComsStatic.HideEnableTag.ToLower().Trim(',').Split(",");//.Replace("x,", "").Replace("y,", "")
  102. es.TargetFileCharset = Charset.GB18030;
  103. es.TargetFileType = outFileType;
  104. es.TargetFilePath = fileName + "-" + lyr.Caption;
  105. es.SourceData = lyr.Dataset as DatasetVector;
  106. ex.ExportSettings.Add(es);
  107. }
  108. }
  109. else
  110. {
  111. foreach (Layer lyr in LayerPanel.SelectLayers)
  112. {
  113. ExportSetting es = new ExportSetting();
  114. es.TargetFileType = outFileType;
  115. es.TargetFilePath = fileName + "-" + lyr.Caption;
  116. es.SourceData = lyr.Dataset as DatasetVector;
  117. ex.ExportSettings.Add(es);
  118. }
  119. }
  120. }
  121. ExportResult exResult = ex.Run();
  122. if (ex.ExportSettings.Count == exResult.SucceedSettings.Length)
  123. ComsStatic.ShowOKLog(string.Format("地图导出GIS数据" + outFileType.ToString() + ",应导出{0}条,共导出{1}条", ex.ExportSettings.Count, exResult.SucceedSettings.Length));
  124. else
  125. ComsStatic.ShowErrorLog(string.Format("地图导出GIS数据" + outFileType.ToString() + ",应导出{0}条,失败导出{1}条", ex.ExportSettings.Count, exResult.FailedSettings.Length));
  126. return true;
  127. }
  128. }
  129. }