/// <summary> /// Does the reprojection work /// </summary> private void DoReprojection(IEnumerable <string> filenames, ISpatialReference projection, bool inPlace) { var report = new TesterReportForm(); report.InitProgress(projection); var files = new List <string>(); int count = 0; // number of successfully reprojected shapefiles foreach (string filename in filenames) { var layer = GeoSource.Open(filename) as ILayerSource; if (layer == null) { continue; } ILayerSource layerNew = null; if (projection.IsSame(layer.Projection)) { report.AddFile(layer.Filename, projection.Name, ProjectionOperaion.SameProjection, ""); files.Add(layer.Filename); } else { TestingResult result = _reprojectingService.Reproject(layer, out layerNew, projection, report); if (result == TestingResult.Ok || result == TestingResult.Substituted) { var 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 { var 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 = _context.Layers.Select(l => l.Filename).ToList(); names = files.Except(names); if (count == 0) { MessageService.Current.Info("No files to add to the map."); return; } if (!projection.IsSame(_context.Map.Projection)) { MessageService.Current.Info( "Chosen projection is different from the project one. The layers can't be added to map."); return; } if (!names.Any()) { MessageService.Current.Info("No files to add to the map."); return; } if (MessageService.Current.Ask("Do you want to add layers to the project?")) { //_context.Layers.StartAddingSession(); foreach (string filename in names) { var ds = GeoSource.Open(filename); var layer = LayerSourceHelper.ConvertToLayer(ds); _context.Layers.Add(layer); } //_context.Layers.StopAddingSession(); } }