public static bool Translate(Dataset dataset, string outputFile, GDALTranslateOptions translateOptions, Gdal.GDALProgressFuncDelegate progressFuncDelegate) { bool result = false; Dataset newDs = null; try { Gdal.PushErrorHandler(new Gdal.GDALErrorHandlerDelegate(GdalHandlers.ErrorHandler)); newDs = Gdal.wrapper_GDALTranslate(outputFile, dataset, translateOptions, progressFuncDelegate, null); Gdal.PopErrorHandler(); } catch (Exception ex) { //LoggerManager.WriteErrorLog(ex.Message); } finally { if (newDs != null) { newDs.FlushCache(); newDs.Dispose(); result = true; } } return(result); }
public static bool EcwToTiff(string inputFile, string outputFile, GDALTranslateOptions translateOptions, Gdal.GDALProgressFuncDelegate progressFuncDelegate) { bool result = false; Dataset dataset = null; try { Gdal.PushErrorHandler(new Gdal.GDALErrorHandlerDelegate(GdalHandlers.ErrorHandler)); dataset = Gdal.Open(inputFile, Access.GA_ReadOnly); Gdal.PopErrorHandler(); if (dataset != null) { result = Translate(dataset, outputFile, translateOptions, progressFuncDelegate); } } catch (Exception ex) { //LoggerManager.WriteErrorLog(ex.Message); } finally { if (dataset != null) { dataset.FlushCache(); dataset.Dispose(); } } return(result); }
public static bool CreateOverviews(OverviewCreateInfo info, string inputFilePath, Gdal.GDALProgressFuncDelegate progressFuncDelegate) { bool result = false; Dataset dataset = null; try { Access access = OverviewOptionEnum.OverviewForamt.External == info.OverviewFormat ? Access.GA_ReadOnly : Access.GA_Update; Gdal.PushErrorHandler(GdalConfig.GdalHandlers.ErrorHandler); dataset = Gdal.Open(inputFilePath, access); Gdal.PopErrorHandler(); if (dataset == null) { return(result); } List <int> levels = info.LevelList; if (info.IsNeedCalcLevel) { levels = CalculateOverViewLevels(dataset); } if (levels.Count < 1) { return(result); } if (OverviewOptionEnum.OverviewForamt.External == info.OverviewFormat) { DeleteExternalOverviews(inputFilePath); } Gdal.PushErrorHandler(GdalConfig.GdalHandlers.ErrorHandler); if (dataset.BuildOverviews(info.OverviewResamplingOption.ToString(), levels.ToArray(), progressFuncDelegate, null) == (int)CPLErr.CE_None) { result = true; } Gdal.PopErrorHandler(); } catch (Exception ex) { //LoggerManager.WriteErrorLog(ex.Message); } finally { if (dataset != null) { dataset.FlushCache(); dataset.Dispose(); } } return(result); }