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); }
public void GetImageBordersNullSize() { string proj = GdalWorker.GetProjString(_in4326); CoordinateSystem cs = GdalWorker.GetCoordinateSystem(proj); Assert.Throws <ArgumentNullException>(() => GdalWorker.GetImageBorders(_in4326, null, cs)); }
public void GetGeoTransformNormal() { double[] gt = null; Assert.DoesNotThrow(() => gt = GdalWorker.GetGeoTransform(_in4326)); Assert.True(gt?.Any()); }
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)); }
public void WarpNullOutput() { _gdalWarpOptions.AddRange(GdalWorker.SrsEpsg3857); Assert.ThrowsAsync <ArgumentNullException>(async() => await GdalWorker.WarpAsync(_in4326, null, _gdalWarpOptions.ToArray(), _progress).ConfigureAwait(false)); }
public void WarpNonExistingInput() { _gdalWarpOptions.AddRange(GdalWorker.SrsEpsg3857); Assert.ThrowsAsync <FileNotFoundException>(async() => await GdalWorker.WarpAsync(ShouldFail, _outPath, _gdalWarpOptions.ToArray(), _progress).ConfigureAwait(false)); }
public void GetProjStringNormal() { string proj = null; Assert.DoesNotThrowAsync(async() => proj = await GdalWorker.GetProjStringAsync(_in4326).ConfigureAwait(false)); Assert.False(string.IsNullOrWhiteSpace(proj)); }
public void InfoNormal() { string gdalInfo = null; Assert.DoesNotThrowAsync(async() => gdalInfo = await GdalWorker.InfoAsync(_in4326).ConfigureAwait(false)); Assert.False(string.IsNullOrWhiteSpace(gdalInfo)); }
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)); }
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)); }
public void ConvertGeoTiffToTargetSystemNullProgress() { Assert.DoesNotThrowAsync(async() => { await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, _outPath, Cs3857).ConfigureAwait(false); CheckHelper.CheckFile(_outPath); }); File.Delete(_outPath); }
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); }
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); }
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); }
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); }
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)); }
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(); } }); }
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); }
public void WarpNullOptions() => Assert.ThrowsAsync <ArgumentNullException>(async() => await GdalWorker.WarpAsync(_in4326, _outPath, null, _progress).ConfigureAwait(false));
public void InfoNullPath() => Assert.ThrowsAsync <ArgumentNullException>(async() => await GdalWorker.InfoAsync(null).ConfigureAwait(false));
public void GetProjStringNullPath() => Assert.ThrowsAsync <ArgumentNullException>(async() => await GdalWorker.GetProjStringAsync(null).ConfigureAwait(false));
public void GetGeoTransformNonExistantPath() => Assert.Throws <FileNotFoundException>(() => GdalWorker.GetGeoTransform(ShouldFail));
public void GetGeoTransformNullPath() => Assert.Throws <ArgumentNullException>(() => GdalWorker.GetGeoTransform(null));
public void GetProjStringNonExistantPath() => Assert.ThrowsAsync <FileNotFoundException>(async() => await GdalWorker.GetProjStringAsync(ShouldFail).ConfigureAwait(false));
public void ConvertGeoTiffToTargetSystemNonExistingInput() => Assert.ThrowsAsync <FileNotFoundException>(async() => await GdalWorker.ConvertGeoTiffToTargetSystemAsync(ShouldFail, _outPath, Cs3857, _progress).ConfigureAwait(false));
public void ConvertGeoTiffToTargetSystemNullOutput() => Assert.ThrowsAsync <ArgumentNullException>(async() => await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, null, Cs3857, _progress).ConfigureAwait(false));
public void ConvertGeoTiffToTargetSystemOtherCs() => Assert.ThrowsAsync <NotSupportedException>(async() => await GdalWorker.ConvertGeoTiffToTargetSystemAsync(_in4326, _outPath, CsOther, _progress).ConfigureAwait(false));