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

Ivan Lucena lucena_ivan at hotmail.com
Thu Oct 20 08:03:03 PDT 2016


Hi Even,


OK. It is what it is. I guess.


I wrote a little test code:


#include <gdal.h>
#include <gdal_utils.h>

int main( int argc, char** argv )
{
   char* papszArgv[1024];
   int i = 0;

   const char*     pszSrcFilename = "rgbsmall.tif";
   const char*     pszDstFilename = "test90.tif";

   GDALDatasetH    hSrcDataset = NULL;
   GDALDatasetH    hDstDataset = NULL;

   GDALTranslateOptions* psOptions = NULL;

   GDALAllRegister();

   papszArgv[i++] = "-of";
   papszArgv[i++] = "GTIFF";

   papszArgv[i++] = "-b";
   papszArgv[i++] = "3";

   papszArgv[i++] = "-b";
   papszArgv[i++] = "2";

   papszArgv[i++] = "-b";
   papszArgv[i++] = "1";

   papszArgv[i++] = "-srcwin";
   papszArgv[i++] = "10";
   papszArgv[i++] = "10";
   papszArgv[i++] = "30";
   papszArgv[i++] = "30";

   papszArgv[i++] = "-co";
   papszArgv[i++] = "BLOCKXSIZE=4";

   papszArgv[i++] = "-co";
   papszArgv[i++] = "BLOCKYSIZE=4";

   papszArgv[i++] = NULL;

   psOptions   = GDALTranslateOptionsNew( papszArgv, NULL );

   hSrcDataset = GDALOpen( pszSrcFilename, GA_ReadOnly );

   hDstDataset = GDALTranslate( pszDstFilename, hSrcDataset, psOptions, NULL );

   GDALTranslateOptionsFree( psOptions );

   GDALClose( hSrcDataset );

   GDALClose( hDstDataset );
}


And I can say that it does work as expected. Maybe we should put that example somewhere on the wiki.


I found to interesting issues. That is just a C application using the GDAL C API but I could only compile with g++, not with gcc. I can't record that was the case 10 years ago. It used to be the case that gdal_translate itself was isolated from the core. Maybe it has something to do with that.


The GTIFF create-option BLOCKXSIZE doesn't seems to work. I tries with larger images and it seems like we can only control the number of rows on a block (BLOCKYSIZE),  but not the number of columns (BLOCKXSIZE).


Thanks again.


Best regards,

Ivan

________________________________
From: Even Rouault <even.rouault at spatialys.com>
Sent: Wednesday, October 19, 2016 3:55:09 PM
To: gdal-dev at lists.osgeo.org
Cc: Ivan Lucena
Subject: Re: [gdal-dev] Utilities as a library, C API

Ivan,

The fact that GDALTranslateOptions is opaque is a design decision that was the
outcome of the discussion phase of RFC 59. It was thought that it would be
difficult to have a stable C structure that could be also extented in the future
without becoming too messy. For example regarding old options that would have
been generalized into newer syntax. Hence the decision to have a minimal
string based interface that takes the same arguments than the command line
strings that lead to RFC 59.1.
So it is up to you to build a nicer API on top of this and build the string
array (that's what the python bindings do for example). Note that the strings
must be split like the arguments of the main(), ie. { "-of", "GTiff", NULL }.

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20161020/d8dff9e3/attachment.html>


More information about the gdal-dev mailing list