/// <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); }
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); } } }
/// <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)); }
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); }
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); }
/// <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)); }
/// <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); }
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); }