using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WWPipeLine.MapBasic.Conditions; using Sunny.UI; using WeifenLuo.WinFormsUI.Docking; using SuperMap.Mapping; using WWPipeLine.MapBasic; using SuperMap.Data.Conversion; using SuperMap.Data; namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi { public partial class OutGIS : ConditionPanel { private LayerWithDataListPanel LayerPanel; private string fileName = string.Empty; public bool isGeo = false; private GeoRegion geo = null; public OutGIS() { this.ConditionPanelName = "地图输出GIS数据文件"; this.IsShowResultWindow = false; InitializeComponent(); } protected override void OnLoad(EventArgs e) { LayerPanel = new LayerWithDataListPanel(); LayerPanel.LoadToVector(true, true, true); uiGBlayer.Controls.Add(LayerPanel); if (isGeo) { MapControl.Action = SuperMap.UI.Action.CreatePolygon; MapControl.Tracked += ComsStatic.MapControl_Tracked_TrackingName; } } private void uiButton1_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory); sfd.Title = "请选择要保存的文件路径"; sfd.Filter = "所有文件|*.*"; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { fileName = sfd.FileName; uiTextBox1.Text = fileName; } } public override object Do(DockPanel dockPanel = null) { if (isGeo) { int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName); if (index == -1) { Sunny.UI.UIMessageTip.ShowError("请先绘制统区域"); return false; } geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion; } if (string.IsNullOrEmpty(fileName)) { UIMessageTip.ShowError("请选择要保存文件的路径"); return false; } if (LayerPanel.SelectLayers.Count == 0) { UIMessageTip.ShowError("请选择要保存文件的图层"); return false; } FileType outFileType = FileType.None; if (uiRadioButtonCSV.Checked) outFileType = FileType.CSV; if (uiRadioButtonGDB.Checked) outFileType = FileType.FileGDBVector; if (uiRadioButtonSHP.Checked) outFileType = FileType.SHP; if (uiRadioButtonSimpleJson.Checked) outFileType = FileType.SimpleJson; if (uiRadioButtonMDB.Checked) outFileType = FileType.PersonalGDBVector; DataExport ex = new DataExport(); if (isGeo) { foreach (Layer lyr in LayerPanel.SelectLayers) { ExportSetting es = new ExportSetting(); es.TargetFileType = outFileType; es.TargetFilePath = fileName + "-" + lyr.Caption; string dviName = ComsStatic.DatasourceMemory.Datasets.GetAvailableDatasetName("OutGIS_dvName"); DatasetVector dv = lyr.Dataset as DatasetVector; DatasetVector dvFinal = ComsStatic.DatasourceMemory.Datasets.Create(new DatasetVectorInfo() { Name = dviName, Type = dv.Type }); dvFinal.AppendFields(dv, "SmUserID", "smuserid", ComsStatic.GetFieldInfos(dv)); dvFinal.Append(dv.Query(geo, 0, CursorType.Static)); es.SourceData = dvFinal; ex.ExportSettings.Add(es); } } else { if (outFileType == FileType.CSV) { foreach (Layer lyr in LayerPanel.SelectLayers) { ExportSettingCSV es = new ExportSettingCSV(); es.IsExportFieldName = true; es.IgnoreFieldNames = ComsStatic.HideEnableTag.ToLower().Trim(',').Split(",");//.Replace("x,", "").Replace("y,", "") es.TargetFileCharset = Charset.GB18030; es.TargetFileType = outFileType; es.TargetFilePath = fileName + "-" + lyr.Caption; es.SourceData = lyr.Dataset as DatasetVector; ex.ExportSettings.Add(es); } } else { foreach (Layer lyr in LayerPanel.SelectLayers) { ExportSetting es = new ExportSetting(); es.TargetFileType = outFileType; es.TargetFilePath = fileName + "-" + lyr.Caption; es.SourceData = lyr.Dataset as DatasetVector; ex.ExportSettings.Add(es); } } } ExportResult exResult = ex.Run(); if (ex.ExportSettings.Count == exResult.SucceedSettings.Length) ComsStatic.ShowOKLog(string.Format("地图导出GIS数据" + outFileType.ToString() + ",应导出{0}条,共导出{1}条", ex.ExportSettings.Count, exResult.SucceedSettings.Length)); else ComsStatic.ShowErrorLog(string.Format("地图导出GIS数据" + outFileType.ToString() + ",应导出{0}条,失败导出{1}条", ex.ExportSettings.Count, exResult.FailedSettings.Length)); return true; } } }