[gdal-dev] Utilities as a library, C API

Ivan Lucena lucena_ivan at hotmail.com
Wed Oct 19 12:47:24 PDT 2016

Hi there,

I am trying to use C API defined in gdal_utils.h.

By reading the RFC 59.1 I understand that the SWIG wrappers will have a nice interface to pass the parameters [1], ex.:

          format --- output format ("GTiff", etc...)
          outputType --- output type (gdal.GDT_Byte, etc...)
          bandList --- array of band numbers (index start at 1)
          srcWin --- subwindow in pixels to extract: [left_x, top_y, width, height]

But it seems like for C, the only way to pass the parameters will be by passing "char** papszArgv" in the same fashion as GDAL command line.

That doesn't seems to be fair with poor C programmers like me. We would need to translate things like "format=XXX" to "-of XXX" and "outputType=XXX" to "-ot XXX" for all the options and all the utilities.

The GDALTranslateOptions is opaque [2], so we cannot access it's member either. See commented line and the error message:

       GDALTranslateOptions* psOptions = GDALTranslateOptionsNew( papszArgv, NULL );

//     psOptions->pszFormat = pszOutDriver; // error: dereferencing pointer to incomplete type

       hDstDataset = GDALTranslate(
           (const char*) pszOutFilename,
           (GDALDatasetH) hSrcDataset,
           (const GDALTranslateOptions*) psOptions,

           (int*) NULL );

       GDALTranslateOptionsFree( psOptions );

Is there any other way to pass the parameters to the GDAL "Utilities as Libraries" in C?



[1] - https://trac.osgeo.org/gdal/wiki/rfc59.1_utilities_as_a_library

[2] - http://www.gdal.org/gdal__utils_8h.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20161019/ada0879f/attachment.html>

More information about the gdal-dev mailing list