コード例 #1
0
        public void GetCoordinateSystem()
        {
            string           proj;
            CoordinateSystem cs = CoordinateSystem.Other;

            Assert.DoesNotThrowAsync(async() =>
            {
                proj = await GdalWorker.GetProjStringAsync(_in4326).ConfigureAwait(false);
                cs   = GdalWorker.GetCoordinateSystem(proj);
            });
            Assert.True(cs == Cs4326);

            Assert.DoesNotThrowAsync(async() =>
            {
                proj = await GdalWorker.GetProjStringAsync(_in3785).ConfigureAwait(false);
                cs   = GdalWorker.GetCoordinateSystem(proj);
            });
            Assert.True(cs == Cs3857);

            Assert.DoesNotThrowAsync(async() =>
            {
                proj = await GdalWorker.GetProjStringAsync(_in3395).ConfigureAwait(false);
                cs   = GdalWorker.GetCoordinateSystem(proj);
            });
            Assert.True(cs == CsOther);
        }
コード例 #2
0
        public void GetImageBordersNullSize()
        {
            string           proj = GdalWorker.GetProjString(_in4326);
            CoordinateSystem cs   = GdalWorker.GetCoordinateSystem(proj);

            Assert.Throws <ArgumentNullException>(() => GdalWorker.GetImageBorders(_in4326, null, cs));
        }
コード例 #3
0
        public void GetGeoTransformNormal()
        {
            double[] gt = null;

            Assert.DoesNotThrow(() => gt = GdalWorker.GetGeoTransform(_in4326));
            Assert.True(gt?.Any());
        }
コード例 #4
0
        public void GetImageBordersOtherCs()
        {
            using Image image = Image.NewFromFile(_in4326);
            Size size = new Size(image.Width, image.Height);

            Assert.Throws <NotSupportedException>(() => GdalWorker.GetImageBorders(_in4326, size, CsOther));
        }
コード例 #5
0
        public void WarpNullOutput()
        {
            _gdalWarpOptions.AddRange(GdalWorker.SrsEpsg3857);

            Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                       await GdalWorker.WarpAsync(_in4326, null, _gdalWarpOptions.ToArray(), _progress).ConfigureAwait(false));
        }
コード例 #6
0
        public void WarpNonExistingInput()
        {
            _gdalWarpOptions.AddRange(GdalWorker.SrsEpsg3857);

            Assert.ThrowsAsync <FileNotFoundException>(async() =>
                                                       await GdalWorker.WarpAsync(ShouldFail, _outPath, _gdalWarpOptions.ToArray(), _progress).ConfigureAwait(false));
        }
コード例 #7
0
        public void GetProjStringNormal()
        {
            string proj = null;

            Assert.DoesNotThrowAsync(async() => proj = await GdalWorker.GetProjStringAsync(_in4326).ConfigureAwait(false));

            Assert.False(string.IsNullOrWhiteSpace(proj));
        }
コード例 #8
0
        public void InfoNormal()
        {
            string gdalInfo = null;

            Assert.DoesNotThrowAsync(async() => gdalInfo = await GdalWorker.InfoAsync(_in4326).ConfigureAwait(false));

            Assert.False(string.IsNullOrWhiteSpace(gdalInfo));
        }
コード例 #9
0
        public void GetImageBordersNullPath()
        {
            using Image image = Image.NewFromFile(_in4326);
            Size             size = new Size(image.Width, image.Height);
            string           proj = GdalWorker.GetProjString(_in4326);
            CoordinateSystem cs   = GdalWorker.GetCoordinateSystem(proj);

            Assert.Throws <ArgumentNullException>(() => GdalWorker.GetImageBorders(null, size, cs));
        }
コード例 #10
0
        public void GetImageBordersNonExistingPath()
        {
            using Image image = Image.NewFromFile(_in4326);
            Size             size = new Size(image.Width, image.Height);
            string           proj = GdalWorker.GetProjString(_in4326);
            CoordinateSystem cs   = GdalWorker.GetCoordinateSystem(proj);

            Assert.Throws <FileNotFoundException>(() => GdalWorker.GetImageBorders(ShouldFail, size, cs));
        }
コード例 #11
0
        public void ConvertGeoTiffToTargetSystemNullProgress()
        {
            Assert.DoesNotThrowAsync(async() =>
            {
                await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, _outPath, Cs3857).ConfigureAwait(false);

                CheckHelper.CheckFile(_outPath);
            });

            File.Delete(_outPath);
        }
コード例 #12
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);
        }
コード例 #13
0
        public void Warp4326To3857()
        {
            _gdalWarpOptions.AddRange(GdalWorker.SrsEpsg3857);

            Assert.DoesNotThrowAsync(async() =>
            {
                await GdalWorker.WarpAsync(_in4326, _outPath, _gdalWarpOptions.ToArray(), _progress).ConfigureAwait(false);

                CheckHelper.CheckFile(_outPath);
            });

            File.Delete(_outPath);
        }
コード例 #14
0
        public void GetImageBordersNormal()
        {
            using Image image = Image.NewFromFile(_in4326);
            Size             size = new Size(image.Width, image.Height);
            string           proj = GdalWorker.GetProjString(_in4326);
            CoordinateSystem cs   = GdalWorker.GetCoordinateSystem(proj);

            GeoCoordinate minCoordinate = null;
            GeoCoordinate maxCoordinate = null;

            Assert.DoesNotThrow(() => (minCoordinate, maxCoordinate) = GdalWorker.GetImageBorders(_in4326, size, cs));
            Assert.True(minCoordinate is GeodeticCoordinate && maxCoordinate is GeodeticCoordinate);
        }
コード例 #15
0
        public void WarpExistingOutput()
        {
            FileStream fs = File.Create(_outPath);

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

            _gdalWarpOptions.AddRange(GdalWorker.SrsEpsg3857);

            Assert.ThrowsAsync <FileException>(async() =>
                                               await GdalWorker.WarpAsync(_in4326, _outPath, _gdalWarpOptions.ToArray(), _progress).ConfigureAwait(false));

            File.Delete(_outPath);
        }
コード例 #16
0
ファイル: CheckHelper.cs プロジェクト: wangpei421/GTiff2Tiles
        public static async ValueTask <bool> CheckInputFileAsync(string inputFilePath, CoordinateSystem targetSystem)
        {
            // File's path checked in other methods, so checking it here is not necessary

            // Get proj and gdalInfo strings
            string projString = await GdalWorker.GetProjStringAsync(inputFilePath).ConfigureAwait(false);

            CoordinateSystem inputSystem    = GdalWorker.GetCoordinateSystem(projString);
            string           gdalInfoString = await GdalWorker.InfoAsync(inputFilePath).ConfigureAwait(false);

            // Check if input image is ready for cropping
            return(inputSystem == targetSystem &&
                   gdalInfoString.Contains(GdalWorker.Byte, StringComparison.InvariantCulture));
        }
コード例 #17
0
        public void GetImageBordersWrongCs2()
        {
            using Image image = Image.NewFromFile(_in3785);
            Size size = new Size(image.Width, image.Height);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                (GeoCoordinate minCoordinate, GeoCoordinate maxCoordinate) = GdalWorker.GetImageBorders(_in3785, size, Cs4326);

                // Pass the tests too
                if (!(minCoordinate is MercatorCoordinate && maxCoordinate is MercatorCoordinate))
                {
                    throw new ArgumentOutOfRangeException();
                }
            });
        }
コード例 #18
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);
        }
コード例 #19
0
 public void WarpNullOptions() => Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                                             await GdalWorker.WarpAsync(_in4326, _outPath, null, _progress).ConfigureAwait(false));
コード例 #20
0
 public void InfoNullPath() => Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                                          await GdalWorker.InfoAsync(null).ConfigureAwait(false));
コード例 #21
0
 public void GetProjStringNullPath() => Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                                                   await GdalWorker.GetProjStringAsync(null).ConfigureAwait(false));
コード例 #22
0
 public void GetGeoTransformNonExistantPath() => Assert.Throws <FileNotFoundException>(() =>
                                                                                       GdalWorker.GetGeoTransform(ShouldFail));
コード例 #23
0
 public void GetGeoTransformNullPath() => Assert.Throws <ArgumentNullException>(() =>
                                                                                GdalWorker.GetGeoTransform(null));
コード例 #24
0
 public void GetProjStringNonExistantPath() => Assert.ThrowsAsync <FileNotFoundException>(async() =>
                                                                                          await GdalWorker.GetProjStringAsync(ShouldFail).ConfigureAwait(false));
コード例 #25
0
 public void ConvertGeoTiffToTargetSystemNonExistingInput() => Assert.ThrowsAsync <FileNotFoundException>(async() =>
                                                                                                          await GdalWorker.ConvertGeoTiffToTargetSystemAsync(ShouldFail, _outPath, Cs3857, _progress).ConfigureAwait(false));
コード例 #26
0
 public void ConvertGeoTiffToTargetSystemNullOutput() => Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                                                                    await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, null, Cs3857, _progress).ConfigureAwait(false));
コード例 #27
0
 public void ConvertGeoTiffToTargetSystemOtherCs() => Assert.ThrowsAsync <NotSupportedException>(async() =>
                                                                                                 await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, _outPath, CsOther, _progress).ConfigureAwait(false));