Пример #1
0
        /// <summary>
        /// Clones the input datasource, saves it to the disk and starts append mode.
        /// </summary>
        public bool SaveAppendModeFeatureSet(IFeatureSet fs, OutputLayerInfo output, IToolLogger log)
        {
            if (File.Exists(output.Filename))
            {
                if (output.Overwrite)
                {
                    if (!GeoSource.Remove(output.Filename))
                    {
                        log.Info("Failed to overwrite.");
                        return(false);
                    }
                }
                else
                {
                    log.Info("Overwrite options isn't selected.");
                    return(false);
                }
            }

            if (!fs.SaveAsEx(output.Filename, true))
            {
                log.Info("Failed to save resulting datasource: " + fs.LastError);
                return(false);
            }

            fs.StartAppendMode();

            return(true);
        }
Пример #2
0
        private void RemoveFile()
        {
            var item = GetSelectedItem <IFileItem>();

            if (item == null)
            {
                MessageService.Current.Info("No filename is selected.");
                return;
            }

            if (_context.Layers.Select(l => l.Identity).Contains(item.Identity))
            {
                MessageService.Current.Info("Can't remove datasource currently opened by the program.");
                return;
            }

            if (
                MessageService.Current.Ask("Do you want to remove the datasource: " + Environment.NewLine +
                                           item.Filename + "?"))
            {
                try
                {
                    var folder = item.Folder;
                    GeoSource.Remove(item.Filename);
                    RefreshItem(folder);
                }
                catch (Exception ex)
                {
                    MessageService.Current.Warn("Failed to remove file: " + ex.Message);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Runs the tool.
        /// </summary>
        public override bool Run(ITaskHandle task)
        {
            // ReSharper disable once InvertIf
            if (Output.Overwrite && !GeoSource.Remove(Output.Filename))
            {
                Log.Warn("Failed to remove file: " + Output.Filename, null);
                return(false);
            }

            return(GisUtils.Instance.Polygonize(GridFilename, Output.Filename, BandIndex, false, null, GdalFormats.Shapefile));
        }
Пример #4
0
        public bool DeleteOutputs(IParametrizedTool tool)
        {
            foreach (var output in tool.GetOutputs())
            {
                if (File.Exists(output.Filename) && output.Overwrite)
                {
                    if (!GeoSource.Remove(output.Filename))
                    {
                        MessageService.Current.Info("Failed to remove datasource: " + output.Filename);
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Runs the tool.
        /// </summary>
        public override bool Run(ITaskHandle task)
        {
            var poly = GetPolygon();

            if (poly == null)
            {
                Log.Warn("Failed to extract the clip polygon.", null);
                return(false);
            }

            // ReSharper disable once InvertIf
            if (Output.Overwrite && !GeoSource.Remove(Output.Filename))
            {
                Log.Warn("Failed to remove file: " + Output.Filename, null);
                return(false);
            }

            return(GisUtils.Instance.ClipGridWithPolygon(Input.Datasource.Filename, poly, Output.Filename, KeepExtents));
        }
Пример #7
0
        /// <summary>
        /// Removes output layers generated by the execution of the tool. Layers are removed both from map and from the disk.
        /// </summary>
        public static bool RemoveOutputs(this IParametrizedTool tool, IAppContext context, ILayerService layerService)
        {
            foreach (var output in tool.GetOutputs())
            {
                var cache = output.DatasourcePointer;

                if (cache == null)
                {
                    // it's normal in case tool execution failed or was interrupted
                    continue;
                }

                if (cache.LayerHandle != -1)
                {
                    // it's only in-memory, so it's enough to remove it from map
                    if (!layerService.RemoveLayer(cache.LayerHandle))
                    {
                        MessageService.Current.Warn("Failed to remove output layer from the map.");
                        return(false);
                    }
                }
                else if (cache.LayerIdentity != null)
                {
                    if (context.Layers.Any(l => l.Identity == cache.LayerIdentity))
                    {
                        if (!layerService.RemoveLayer(cache.LayerIdentity))
                        {
                            MessageService.Current.Warn("Failed to remove output layer from the map.");
                            return(false);
                        }
                    }

                    if (!GeoSource.Remove(cache.LayerIdentity.Filename))
                    {
                        MessageService.Current.Warn("Failed to remove output layer from disk.");
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #8
0
        private static bool AddTempDataSource(
            IAppContext context,
            ILayerService layerService,
            string filename,
            OutputLayerInfo outputInfo)
        {
            var fs = FeatureSet.OpenAsInMemoryDatasource(filename);

            if (fs != null)
            {
                // output info name
                if (layerService.AddDatasource(fs))
                {
                    var layer = context.Layers.ItemByHandle(layerService.LastLayerHandle);
                    layer.Name = outputInfo.Name;

                    GeoSource.Remove(filename);
                    return(true);
                }
            }

            return(false);
        }