[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);
        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: " +
        if (gcHandle.IsAllocated)

    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?



*Paul Meems *
Release manager, configuration manager
and forum moderator of MapWindow GIS.

Owner of MapWindow.nl - Support for
Dutch speaking users.

*The MapWindow GIS project has moved to GitHub

Download the latest MapWinGIS mapping engine.

Download the latest MapWindow 5 open source desktop application.
-------------- 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