Skip to content

Commit

Permalink
Merge pull request #20 from pierotofy/memtile
Browse files Browse the repository at this point in the history
In-memory tile generation
  • Loading branch information
pierotofy authored Oct 8, 2021
2 parents 9b72732 + 30355ea commit 02a57ec
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
13 changes: 10 additions & 3 deletions DDB.Bindings/DDB.Bindings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
<SignAssembly>false</SignAssembly>
<PackageLicenseExpression>MPL-2.0</PackageLicenseExpression>
<Description>DroneDB native bindings</Description>
<AssemblyVersion>1.0.20.0</AssemblyVersion>
<FileVersion>1.0.20.0</FileVersion>
<Version>1.0.20</Version>
<AssemblyVersion>1.0.21.0</AssemblyVersion>
<FileVersion>1.0.21.0</FileVersion>
<Version>1.0.21</Version>
<RepositoryUrl>https://github.com/DroneDB/DDB.Bindings</RepositoryUrl>
<PackageProjectUrl>https://github.com/DroneDB/DDB.Bindings</PackageProjectUrl>
<ApplicationIcon />
<OutputType>Exe</OutputType>
<StartupObject />
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
43 changes: 38 additions & 5 deletions DDB.Bindings/DroneDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,18 @@ public static byte[] GenerateThumbnail(string filePath, int size)

[DllImport("ddb", EntryPoint = "DDBTile")]
static extern DDBError _GenerateTile(
[MarshalAs(UnmanagedType.LPStr)] string geotiffPath, int tz, int tx, int ty, out IntPtr outputTilePath, int tileSize, bool tms, bool forceRecreate);
[MarshalAs(UnmanagedType.LPStr)] string inputPath, int tz, int tx, int ty, out IntPtr outputTilePath, int tileSize, bool tms, bool forceRecreate);

public static string GenerateTile(string filePath, int tz, int tx, int ty, int tileSize, bool tms, bool forceRecreate = false)
public static string GenerateTile(string inputPath, int tz, int tx, int ty, int tileSize, bool tms, bool forceRecreate = false)
{

if (filePath == null)
throw new ArgumentException("filePath is null");
if (inputPath == null)
throw new ArgumentException("inputPath is null");

try
{

if (_GenerateTile(filePath, tz, tx, ty, out var output, tileSize, tms, forceRecreate) !=
if (_GenerateTile(inputPath, tz, tx, ty, out var output, tileSize, tms, forceRecreate) !=
DDBError.DDBERR_NONE) throw new DDBException(GetLastError());

var res = Marshal.PtrToStringAnsi(output);
Expand All @@ -422,6 +422,39 @@ public static string GenerateTile(string filePath, int tz, int tx, int ty, int t

}

[DllImport("ddb", EntryPoint = "DDBMemoryTile")]
static extern DDBError _GenerateMemoryTile(
[MarshalAs(UnmanagedType.LPStr)] string inputPath, int tz, int tx, int ty, out IntPtr outBuffer, out int outBufferSize, int tileSize, bool tms, bool forceRecreate, [MarshalAs(UnmanagedType.LPStr)] string inputPathHash);
public static byte[] GenerateMemoryTile(string inputPath, int tz, int tx, int ty, int tileSize, bool tms, bool forceRecreate = false, string inputPathHash = "")
{
if (inputPath == null)
throw new ArgumentException("inputPath is null");

try
{
Console.WriteLine(inputPath);
if (_GenerateMemoryTile(inputPath, tz, tx, ty, out var outBuffer, out var outBufferSize, tileSize, tms, forceRecreate, inputPathHash) !=
DDBError.DDBERR_NONE) throw new DDBException(GetLastError());

var destBuf = new byte[outBufferSize];
Marshal.Copy(outBuffer, destBuf, 0, outBufferSize);

_DDBVSIFree(outBuffer);

return destBuf;

}
catch (EntryPointNotFoundException ex)
{
throw new DDBException($"Error in calling ddb lib: incompatible versions ({ex.Message})", ex);
}
catch (Exception ex)
{
throw new DDBException($"Error in calling ddb lib. Last error: \"{GetLastError()}\", check inner exception for details", ex);
}

}

[DllImport("ddb", EntryPoint = "DDBSetTag")]
static extern DDBError _SetTag([MarshalAs(UnmanagedType.LPStr)] string ddbPath, [MarshalAs(UnmanagedType.LPStr)] string newTag);

Expand Down
9 changes: 9 additions & 0 deletions DDB.Tests/DroneDBTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ public void GenerateTile_HappyPath_Ok()
}
}

[Test]
public void GenerateMemoryTile_HappyPath_Ok()
{
using var tempFile = new TempFile(TestGeoTiffUrl, BaseTestFolder);

var buffer = DroneDB.GenerateMemoryTile(tempFile.FilePath, 18, 64083, 92370, 256, true);
buffer.Length.Should().BeGreaterThan(0);
}

[Test]
public void Tag_HappyPath_Ok()
{
Expand Down

0 comments on commit 02a57ec

Please sign in to comment.