예제 #1
0
        public void ConvertGeoTiffToTargetSystemNullProgress()
        {
            Assert.DoesNotThrowAsync(async() =>
            {
                await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, _outPath, Cs3857).ConfigureAwait(false);

                CheckHelper.CheckFile(_outPath);
            });

            File.Delete(_outPath);
        }
예제 #2
0
        public void ConvertGeoTiffToTargetSystemExistingOutput()
        {
            FileStream fs = File.Create(_outPath);

            // Must dispose explicitly to delete correctly
            fs.Dispose();

            Assert.ThrowsAsync <FileException>(async() => await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, _outPath, Cs3857, _progress).ConfigureAwait(false));

            File.Delete(_outPath);
        }
예제 #3
0
 public void ConvertGeoTiffToTargetSystemOtherCs() => Assert.ThrowsAsync <NotSupportedException>(async() =>
                                                                                                 await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, _outPath, CsOther, _progress).ConfigureAwait(false));
예제 #4
0
 public void ConvertGeoTiffToTargetSystemNullOutput() => Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                                                                    await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, null, Cs3857, _progress).ConfigureAwait(false));
예제 #5
0
 public void ConvertGeoTiffToTargetSystemNonExistingInput() => Assert.ThrowsAsync <FileNotFoundException>(async() =>
                                                                                                          await GdalWorker.ConvertGeoTiffToTargetSystemAsync(ShouldFail, _outPath, Cs3857, _progress).ConfigureAwait(false));
예제 #6
0
        private static async Task Main(string[] args)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            try
            {
                Parser.Default.ParseArguments <Options>(args).WithParsed(ParseConsoleOptions)
                .WithNotParsed(error => IsParsingErrors = true);
            }
            catch (Exception exception)
            {
                // Catch some uncaught parsing errors
                Helpers.ErrorHelper.PrintException(exception);

                return;
            }

            if (IsParsingErrors)
            {
                Helpers.ErrorHelper.PrintError(Strings.ParsingError);

                return;
            }

            // Create progress-reporter
            Progress <double> consoleProgress = IsProgress ? new Progress <double>(System.Console.WriteLine) : null;
            Action <string>   printTimeAction = IsTime ? new Action <string>(System.Console.WriteLine) : null;

            // Create temp directory object
            TempDirectoryPath = Path.Combine(TempDirectoryPath,
                                             DateTime.Now.ToString(DateTimePatterns.LongWithMs, CultureInfo.InvariantCulture));

            // Run tiling asynchroniously
            try
            {
                // Check for errors
                if (!await CheckHelper.CheckInputFileAsync(InputFilePath, TargetCoordinateSystem).ConfigureAwait(false))
                {
                    string tempFilePath = Path.Combine(TempDirectoryPath, GdalWorker.TempFileName);

                    await GdalWorker.ConvertGeoTiffToTargetSystemAsync(InputFilePath, tempFilePath, TargetCoordinateSystem,
                                                                       consoleProgress).ConfigureAwait(false);

                    InputFilePath = tempFilePath;
                }

                await using Raster image = new Raster(InputFilePath, TargetCoordinateSystem, MemCache);

                // Generate tiles
                await image.WriteTilesToDirectoryAsync(OutputDirectoryPath, MinZ, MaxZ, TmsCompatible,
                                                       TileSize, TileExtension, TargetInterpolation, BandsCount,
                                                       TileCacheCount, ThreadsCount, consoleProgress, printTimeAction)
                .ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                Helpers.ErrorHelper.PrintException(exception);

                return;
            }

            System.Console.WriteLine(Strings.Done, Environment.NewLine, stopwatch.Elapsed.Days, stopwatch.Elapsed.Hours,
                                     stopwatch.Elapsed.Minutes, stopwatch.Elapsed.Seconds,
                                     stopwatch.Elapsed.Milliseconds);
        }