Esempio n. 1
0
        public static int GetIcon(ILayerSource source)
        {
            if (source == null)
            {
                return(GetIcon());
            }

            var gt = LayerSourceHelper.GetGeometryType(source);

            return(GetIcon(source.LayerType, gt));
        }
Esempio n. 2
0
        public static IDatasource Open(string filename, OpenStrategy openStrategy = OpenStrategy.AutoDetect)
        {
            var result = TryOpenAsDatabaseLayer(filename);

            if (result != null)
            {
                return(result);
            }

            var source = _manager.Open(filename, (tkFileOpenStrategy)openStrategy);

            return(LayerSourceHelper.Convert(source));
        }
Esempio n. 3
0
        private bool SaveDatasource(IDatasource ds, string filename)
        {
            if (!GeoSource.Remove(filename))
            {
                return(HandleOverwriteFailure());
            }

            if (LayerSourceHelper.Save(ds, filename))
            {
                Logger.Current.Info("Layer ({0}) is created.", filename);
                return(true);
            }

            Logger.Current.Error("Failed to save datasource: " + ds.LastError);
            return(false);
        }
Esempio n. 4
0
        private static IDatasource TryOpenAsDatabaseLayer(string filename)
        {
            // the expected format is: "OgrConnection|<connection>|<query_or_layer_name>"
            if (filename == null || !filename.ToLower().StartsWith("ogrconnection"))
            {
                return(null);
            }

            var parts = filename.Split('|');

            if (parts.Length == 3)
            {
                var source = _manager.OpenFromDatabase(parts[1], parts[2]);
                return(LayerSourceHelper.Convert(source));
            }

            return(null);
        }
Esempio n. 5
0
        /// <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();
            }
        }