[gdal-dev] How to use wrapper_GDALWarpDestName in C#
Paul Meems
bontepaarden at gmail.com
Mon Feb 13 04:49:31 PST 2017
Hi List,
I'm now trying to use GDALWarp with the C# bindings.
I'm using GDAL v2.
Together with a colleague we came up with this snippet:
using (var ds = Gdal.Open(input, Access.GA_ReadOnly))
{
if (ds == null)
{
throw new Exception("Can't open GDAL dataset: " + input);
}
var gdalOptions = new GDALWarpAppOptions(options);
var ptr = new[] { Dataset.getCPtr(ds).Handle };
var gcHandle = GCHandle.Alloc(ptr, GCHandleType.Pinned);
try
{
var dss = new
SWIGTYPE_p_p_GDALDatasetShadow(gcHandle.AddrOfPinnedObject(), false, null);
var newDs = Gdal.wrapper_GDALWarpDestName(output, 1, dss,
gdalOptions, null, null);
if (newDs == null)
{
throw new Exception("GdalWarp failed: " +
Gdal.GetLastErrorMsg());
}
}
finally
{
if (gcHandle.IsAllocated)
gcHandle.Free();
}
return true;
}
It seems to work, but the SWIGTYPE_p_p_GDALDatasetShadow and gcHandle feel
a bit hacky.
Is this the recommended flow?
And the second parameter is object_list_count. We now put in 1, but what
should this be?
Thanks,
Paul
*Paul Meems *
Release manager, configuration manager
and forum moderator of MapWindow GIS.
www.mapwindow.org
Owner of MapWindow.nl - Support for
Dutch speaking users.
www.mapwindow.nl
*The MapWindow GIS project has moved to GitHub
<https://github.com/MapWindow>!*
Download the latest MapWinGIS mapping engine.
<https://github.com/MapWindow/MapWinGIS/releases>
Download the latest MapWindow 5 open source desktop application.
<https://github.com/MapWindow/MapWindow5/releases>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170213/559bc041/attachment.html>
More information about the gdal-dev
mailing list