[gdal-dev] Experiments with the gdal_grid C API

Joaquim Manuel Freire Luís jluis at ualg.pt
Tue Jan 28 04:26:34 PST 2020

Hi Even,

I'm playing with the C API for the GDAL programs inside GMT. More specifically with the gdal_grid C API. All in all I managed to make it work but there are some issues.
The main problem is that apparently the API was not thought to keep the result in memory.

What ended up doing was this

               hDstDS = GDALGrid("NUL", hSrcDS, psOptions, &bUsageError);
               if ((tmp = calloc((size_t)nYSize * (size_t)nXSize, nPixelSize)) == NULL) {
                              GMT_Report (GMT->parent, GMT_MSG_NORMAL, "gdalread: failure to allocate enough memory\n");
                              return -1;

               if ((gdal_code = GDALRasterIO(hBand, GF_Read, 0, 0, nXSize, nYSize, tmp,
                               nXSize, nYSize, GDALGetRasterDataType(hBand), 0, 0)) != CE_None) {
                              GMT_Report (GMT->parent, GMT_MSG_NORMAL, "GDALRasterIO failed to open band [err = %d]\n", gdal_code);

-Note that I'm using "NUL" for the output file name because that was the only way I found to prevent saving the file in disk (remember, I want to have it memory).

-The second thing not shown above is that I had to use "-ot GTiff" in the psOptions. Using "-ot Memory" lead to errors.

-Although using "NUL" works, GDAL prints these error messages when at the end I close the DS (GDALClose(hSrcDS);)
               ERROR 1: TIFFScanlineSize64:Computed scanline size is zero
               ERROR 1: TIFFWriteEncodedStrip:Must set "ImageWidth" before writing data
               ERROR 1: FillEmptyTiles() failed because panByteCounts == NULL

-Last thing. I was forced to make a copy of the array in order to extract the grid  from the hDstDS handle via GDALRasterIO().

Ok, so my questions are. Is there a better way to do this? Could we, by some mean, send in a pre-allocated array and owned by the external program to the API so the duplication step could be avoided?


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

More information about the gdal-dev mailing list