/// <summary> /// Runs the operation /// </summary> private void btnOk_Click(object sender, EventArgs e) { CoordinateSystem cs = this.ProjectionTreeView1.SelectedCoordinateSystem; if (cs == null) { MessageBox.Show("No projection is selected", m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (this.LayersControl1.Filenames.Count() == 0) { MessageBox.Show("No files are selected", m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MapWinGIS.GeoProjection projection = new MapWinGIS.GeoProjection(); if (projection.ImportFromEPSG(cs.Code)) { frmTesterReport report = new frmTesterReport(); int count = 0; // number of successfully processed files foreach (string name in this.LayersControl1.Filenames) { LayerSource layer = new LayerSource(name); string projName = layer.Projection != null ? layer.Projection.Name : ""; if (layer.Type != LayerSourceType.Undefined) { layer.Projection = projection; count++; } else { report.AddFile(name, projName, ProjectionOperaion.Skipped, ""); } } if (count > 0) { MessageBox.Show(string.Format("The projection was successfully assigned to the files: {0}", count), m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } if (report.MismatchedCount > 0) { report.ShowReport(projection, "The following files were not processed:", ReportType.Assignment); } this.LayersControl1.UpdateProjections(); } else { MessageBox.Show("Failed to initialize the selected projection", m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
/// <summary> /// 显示报告 /// </summary> /// <param name="proj">投影的目标工程</param> public void ShowReport(MapWinGIS.GeoProjection proj) { m_report.ShowReport(proj, "", ReportType.Loading); }
/// <summary> /// Does the reprojection work /// </summary> private void DoReprojection(IEnumerable <string> filenames, MapWinGIS.GeoProjection projection, bool inPlace) { frmTesterReport report = new frmTesterReport(); report.InitProgress(projection); List <string> files = new List <string>(); int count = 0; // number of successfully reprojected shapefiles foreach (string filename in filenames) { LayerSource layer = new LayerSource(filename); LayerSource layerNew = null; if (projection.get_IsSame(layer.Projection)) { report.AddFile(layer.Filename, projection.Name, ProjectionOperaion.SameProjection, ""); files.Add(layer.Filename); } else { TestingResult result = CoordinateTransformation.ReprojectLayer(layer, out layerNew, projection, report); if (result == TestingResult.Ok || result == TestingResult.Substituted) { ProjectionOperaion oper = result == TestingResult.Ok ? ProjectionOperaion.Reprojected : ProjectionOperaion.Substituted; string newName = layerNew == null ? "" : layerNew.Filename; report.AddFile(layer.Filename, layer.Projection.Name, oper, newName); files.Add(newName == "" ? layer.Filename : newName); count++; } else { ProjectionOperaion operation = result == TestingResult.Error ? ProjectionOperaion.FailedToReproject : ProjectionOperaion.Skipped; report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Skipped, ""); } } layer.Close(); if (layerNew != null) { layerNew.Close(); } } report.ShowReport(projection, "Reprojection results:", ReportType.Loading); IEnumerable <string> names = m_mapWin.Layers.Select(l => l.FileName); names = files.Except(names); if (count > 0) { if (projection.get_IsSame(m_mapWin.Project.GeoProjection)) { if (names.Count() > 0) { if (MessageBox.Show("Do you want to add layers to the project?", m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { m_mapWin.Layers.StartAddingSession(); foreach (string filename in names) { m_mapWin.Layers.Add(filename); } m_mapWin.Layers.StopAddingSession(); } } else { MessageBox.Show("No files to add to the map.", m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Chosen projection is different from the project one. The layers can't be added to map.", m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("No files to add to the map.", m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } }