Skip to content

Commit

Permalink
Added auto-convertion for non-8 bit input images
Browse files Browse the repository at this point in the history
Slightly updated unit tests
  • Loading branch information
Gigas002 committed Jul 6, 2019
1 parent acd13ae commit f08f690
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 72 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Changes since 1.2.0:
- Moved all strings to **Strings.resx** file in **Localization** directory;
- Added support for Russian language;
- *New feature:* Option to create non-tms tiles (*WIP*);
- *New feature:* Now **GTiff2Tiles** is able to process non-8 bit images (see []());

## Core

Expand All @@ -23,7 +24,11 @@ Changes since 1.2.0:
**Breaking changes:**

- `Image.Tile.GetTileNumbersFromCoords` method now also takes `bool tmsCompatible` parameter;
- `Image.Tile.TileBounds` method now takes `bool tmsCompatible` parameter, instead of `bool isFlipY = true)`, which was working the opposite. So, set the `tmsCompatible` value to `true` if you want to have the previous behaviour (creation of `tms` tiles).
- `Image.Tile.TileBounds` method now takes `bool tmsCompatible` parameter, instead of `bool isFlipY = true)`, which was working the opposite. So, set the `tmsCompatible` value to `true` if you want to have the previous behaviour (creation of `tms` tiles);
- `Enums.Image.Gdal.Block` property has been removed;
- `Enums.Image.Gdal.Byte` property value has been changed to `Type=Byte` for more correct checks from `Image.Gdal.Info`;
- `Enums.Image.Gdal.RepairTifOptions` array now also has options `“-of”, “GTiff”` and `“-ot”, “Byte”` for processing non-8 bit images;
- Option `“-co”, “TILED=YES”` was removed from `Enums.Image.Gdal.RepairTifOptions` array. You should explicitly add this option to your array if you want to convert input image to `TILED` image;

## GUI

Expand All @@ -42,7 +47,7 @@ Changes since 1.2.0:
- Added more zoom levels to test (from 0 to 18);
- Updated **NUnit** to 3.12.0;
- Added **NUnit3TestAdapter** package;
- Improved code coverage (*WIP*);
- Slightly improved code coverage;

# 27.02.2019 – Released 1.2.0

Expand Down Expand Up @@ -86,7 +91,7 @@ Changes since beta:

- Changed solution architecture: previous project split upon GTiff2Tiles library and GTiff2Tiles. Test console application for running tests;
- Fixed typo;
- Updated GDAL and GDAL.Native from 2.3.2 to 2.3.3;
- Updated **GDAL** and **GDAL.Native** from 2.3.2 to 2.3.3;
- Moved from packages.config to PackageReference;
- Updated README;
- `GTiff2Tiles` class is no longer static and implements `IDisposable`;
Expand Down
4 changes: 2 additions & 2 deletions GTiff2Tiles.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.140")]
[assembly: AssemblyFileVersion("1.2.0.140")]
[assembly: AssemblyVersion("1.2.0.143")]
[assembly: AssemblyFileVersion("1.2.0.143")]
13 changes: 5 additions & 8 deletions GTiff2Tiles.Core/Enums/Image/Gdal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ public static class Gdal
#region GdalInfo

/// <summary>
/// Input image is tiled.
/// Type=Byte
/// </summary>
public const string Block = "Block";

/// <summary>
/// Check type.
/// </summary>
public const string Byte = "Byte";
public const string Byte = "Type=Byte";

#endregion

Expand All @@ -40,7 +35,9 @@ public static class Gdal
/// </summary>
public static readonly string[] RepairTifOptions =
{
"-overwrite", "-t_srs", "EPSG:4326", "-co", "TILED=YES", "-multi", "-srcnodata", "0",
"-overwrite", "-t_srs", "EPSG:4326", "-multi", "-srcnodata", "0",
"-of", "GTiff", "-ot", "Byte"
//"-co", "TILED=YES",
};

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion GTiff2Tiles.Core/Helpers/CheckHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static bool CheckTifInfo(string gdalInfoString, string proj4String)
return false;

//Other checks.
return gdalInfoString.Contains(Enums.Image.Gdal.Block) && gdalInfoString.Contains(Enums.Image.Gdal.Byte);
return gdalInfoString.Contains(Enums.Image.Gdal.Byte);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion GTiff2Tiles.Core/Image/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ private void WriteTile(int zoom, int tileX, int tileY, NetVips.Image inputImage)
//Check if tile was created successfuly.
CheckHelper.CheckFile(outputTileFileInfo, true);

outputImage.Dispose();
tileImage.Dispose();
outputImage.Dispose();
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions GTiff2Tiles.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.133")]
[assembly: AssemblyFileVersion("1.2.0.133")]
[assembly: AssemblyVersion("1.2.0.137")]
[assembly: AssemblyFileVersion("1.2.0.137")]
4 changes: 2 additions & 2 deletions GTiff2Tiles.GUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.208")]
[assembly: AssemblyFileVersion("1.2.0.208")]
[assembly: AssemblyVersion("1.2.0.212")]
[assembly: AssemblyFileVersion("1.2.0.212")]
7 changes: 5 additions & 2 deletions GTiff2Tiles.Tests/GTiff2Tiles.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@
<Compile Include="Enums\Multithreading.cs" />
<Compile Include="Enums\Zooms.cs" />
<Compile Include="Helpers\TestHelper.cs" />
<Compile Include="Image\GdalTests.cs" />
<Compile Include="Image\ImageTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tests\EnumsTests.cs" />
<Compile Include="Tests\ExceptionsTests.cs" />
<Compile Include="Tests\HelpersTests.cs" />
<Compile Include="Tests\Image\GdalTests.cs" />
<Compile Include="Tests\Image\ImageTests.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GDAL.Native">
Expand Down
4 changes: 2 additions & 2 deletions GTiff2Tiles.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

[assembly: Guid("d395133d-7823-42fd-91a9-b52592e6c18a")]

[assembly: AssemblyVersion("1.2.0.135")]
[assembly: AssemblyFileVersion("1.2.0.135")]
[assembly: AssemblyVersion("1.2.0.138")]
[assembly: AssemblyFileVersion("1.2.0.138")]
68 changes: 68 additions & 0 deletions GTiff2Tiles.Tests/Tests/EnumsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using NUnit.Framework;

// ReSharper disable UnusedVariable
#pragma warning disable 219

namespace GTiff2Tiles.Tests.Tests
{
public class EnumsTests
{
[SetUp]
public void Setup() { }

[Test]
public void ImageGdal()
{
try
{
string lonLat = Core.Enums.Image.Gdal.LongLat;
string wgs84 = Core.Enums.Image.Gdal.Wgs84;
string typeByte = Core.Enums.Image.Gdal.Byte;
string[] repairTifOptions = Core.Enums.Image.Gdal.RepairTifOptions;
string tempFileName = Core.Enums.Image.Gdal.TempFileName;
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}

[Test]
public void Algorithms()
{
try
{
string crop = Core.Enums.Algorithms.Crop;
string join = Core.Enums.Algorithms.Join;
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}

[Test]
public void DateTimePatterns()
{
try
{
string longWithMs = Core.Enums.DateTimePatterns.LongWithMs;
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}

[Test]
public void Extensions()
{
try
{
string png = Core.Enums.Extensions.Png;
string tif = Core.Enums.Extensions.Tif;
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}
}
}
54 changes: 54 additions & 0 deletions GTiff2Tiles.Tests/Tests/ExceptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using GTiff2Tiles.Core.Exceptions.Image;
using GTiff2Tiles.Core.Exceptions.Tile;
using NUnit.Framework;

// ReSharper disable UnusedVariable

namespace GTiff2Tiles.Tests.Tests
{
public class ExceptionsTests
{
[SetUp]
public void Setup() { }

[Test]
public void ImageGdalException()
{
try
{
GdalException gdalException = new GdalException(string.Empty);
GdalException gdalException2 = new GdalException(string.Empty, null);
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}

[Test]
public void ImageImageException()
{
try
{
ImageException imageException = new ImageException(string.Empty);
ImageException imageException2 = new ImageException(string.Empty, null);
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}

[Test]
public void TileTileException()
{
try
{
TileException tileException = new TileException(string.Empty);
TileException tileException2 = new TileException(string.Empty, null);
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}
}
}
31 changes: 31 additions & 0 deletions GTiff2Tiles.Tests/Tests/HelpersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.IO;
using GTiff2Tiles.Core.Helpers;
using NUnit.Framework;

namespace GTiff2Tiles.Tests.Tests
{
public class HelpersTests
{
[SetUp]
public void SetUp() { }

[Test]
public void CheckHelperTests()
{
try
{
DirectoryInfo examplesDirectoryInfo = Helpers.TestHelper.GetExamplesDirectoryInfo();
string inputFilePath = Path.Combine(examplesDirectoryInfo.FullName,
Enums.FileSystemEntries.InputDirectoryName,
$"{Enums.FileSystemEntries.Input4326}{Core.Enums.Extensions.Tif}");
FileInfo inputFileInfo = new FileInfo(inputFilePath);
CheckHelper.CheckDirectory(examplesDirectoryInfo, false);
CheckHelper.CheckInputFile(inputFileInfo);
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@
using System.Threading.Tasks;
using NUnit.Framework;

namespace GTiff2Tiles.Tests.Image
namespace GTiff2Tiles.Tests.Tests.Image
{
public class GdalTests
{
[SetUp]
public void Setup()
{

}
public void Setup() { }

[Test]
public async Task CheckAndRepair3785()
{
DirectoryInfo examplesDirectoryInfo = Helpers.TestHelper.GetExamplesDirectoryInfo();

DirectoryInfo tempDirectoryInfo =
new DirectoryInfo(Path.Combine(Helpers.TestHelper.GetExamplesDirectoryInfo().FullName,
Enums.FileSystemEntries.Temp,
DateTime.Now.ToString(Core.Enums.DateTimePatterns.LongWithMs)));
DirectoryInfo tempDirectoryInfo = new DirectoryInfo(
Path.Combine(Helpers.TestHelper.GetExamplesDirectoryInfo().FullName,
Enums.FileSystemEntries.Temp,
DateTime.Now.ToString(Core.Enums.DateTimePatterns.LongWithMs)));

string inputFilePath = Path.Combine(examplesDirectoryInfo.FullName, Enums.FileSystemEntries.InputDirectoryName,
string inputFilePath = Path.Combine(examplesDirectoryInfo.FullName,
Enums.FileSystemEntries.InputDirectoryName,
$"{Enums.FileSystemEntries.Input3785}{Core.Enums.Extensions.Tif}");
FileInfo inputFileInfo = new FileInfo(inputFilePath);

Expand All @@ -33,22 +31,21 @@ public async Task CheckAndRepair3785()
//Check and repair.
if (!Core.Helpers.CheckHelper.CheckInputFile(inputFileInfo))
{
string tempFilePath = Path.Combine(tempDirectoryInfo.FullName, $"{Core.Enums.Image.Gdal.TempFileName}{Core.Enums.Extensions.Tif}");
string tempFilePath = Path.Combine(tempDirectoryInfo.FullName,
$"{Core.Enums.Image.Gdal.TempFileName}{Core.Enums.Extensions.Tif}");
FileInfo tempFileInfo = new FileInfo(tempFilePath);

await Core.Image.Gdal.Warp(inputFileInfo, tempFileInfo, Core.Enums.Image.Gdal.RepairTifOptions);
}

//Check if temp file was created successfuly.
if (!tempDirectoryInfo.EnumerateFiles().Any())
Assert.Fail("Temp file wasn't created.");

//Delete temp directory.
tempDirectoryInfo.Delete(true);
}
catch (Exception exception)
{
Assert.Fail(exception.Message);
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}
Expand All @@ -58,12 +55,13 @@ public async Task CheckAndRepair3395()
{
DirectoryInfo examplesDirectoryInfo = Helpers.TestHelper.GetExamplesDirectoryInfo();

DirectoryInfo tempDirectoryInfo =
new DirectoryInfo(Path.Combine(Helpers.TestHelper.GetExamplesDirectoryInfo().FullName,
Enums.FileSystemEntries.Temp,
DateTime.Now.ToString(Core.Enums.DateTimePatterns.LongWithMs)));
DirectoryInfo tempDirectoryInfo = new DirectoryInfo(
Path.Combine(Helpers.TestHelper.GetExamplesDirectoryInfo().FullName,
Enums.FileSystemEntries.Temp,
DateTime.Now.ToString(Core.Enums.DateTimePatterns.LongWithMs)));

string inputFilePath = Path.Combine(examplesDirectoryInfo.FullName, Enums.FileSystemEntries.InputDirectoryName,
string inputFilePath = Path.Combine(examplesDirectoryInfo.FullName,
Enums.FileSystemEntries.InputDirectoryName,
$"{Enums.FileSystemEntries.Input3395}{Core.Enums.Extensions.Tif}");
FileInfo inputFileInfo = new FileInfo(inputFilePath);

Expand All @@ -72,22 +70,21 @@ public async Task CheckAndRepair3395()
//Check and repair.
if (!Core.Helpers.CheckHelper.CheckInputFile(inputFileInfo))
{
string tempFilePath = Path.Combine(tempDirectoryInfo.FullName, $"{Core.Enums.Image.Gdal.TempFileName}{Core.Enums.Extensions.Tif}");
string tempFilePath = Path.Combine(tempDirectoryInfo.FullName,
$"{Core.Enums.Image.Gdal.TempFileName}{Core.Enums.Extensions.Tif}");
FileInfo tempFileInfo = new FileInfo(tempFilePath);

await Core.Image.Gdal.Warp(inputFileInfo, tempFileInfo, Core.Enums.Image.Gdal.RepairTifOptions);
}

//Check if temp file was created successfuly.
if (!tempDirectoryInfo.EnumerateFiles().Any())
Assert.Fail("Temp file wasn't created.");

//Delete temp directory.
tempDirectoryInfo.Delete(true);
}
catch (Exception exception)
{
Assert.Fail(exception.Message);
}
catch (Exception exception) { Assert.Fail(exception.Message); }

Assert.Pass();
}
Expand Down
Loading

0 comments on commit f08f690

Please sign in to comment.