[gdal-dev] GDAL warp tutorial question (C vs. C++)

Even Rouault even.rouault at spatialys.com
Tue Apr 5 03:47:42 PDT 2022


Le 05/04/2022 à 01:28, Michael Sumner a écrit :
> Hello, the warp tutorial  needs at least inclusion of "cpl_conv.h" for 
> CPLMalloc to work.
>
> https://gdal.org/tutorials/warp_tut.html
>
> But, I'd like to ask why it uses the style of the C examples (as per 
> the Raster API tutorial 
> https://gdal.org/tutorials/raster_api_tut.html) rather than the C++ - 
> i.e. it uses 'GDALDatasetH hSrcDS' declarations rather than 
> 'GDALDataset *poDataset', and all the 'GDAL<Functions>' rather than 
> '->' pointer syntax.
>
> Is that recommended, or is it just old style in this tutorial (because 
> the apps were originally C)?

Probably just the preference of the author of the example. At least the 
first code snippet 
(https://gdal.org/tutorials/warp_tut.html#a-simple-reprojection-case) 
uses some C++ with the GDALWarpOperation class so it could be 
potentially converted to full C++ (but you'll need to keep CPLMalloc() 
and not use new[] because GDALDestroyWarpOptions() expects panSrcBands 
and panDstBands to have been allocated with CPLMalloc())

Actually I see the second snippet 
(https://gdal.org/tutorials/warp_tut.html#creating-the-output-file) does 
use some bits of C++ with the OGRSpatialReference class. It could be 
either fully converted to C++ (but some functions like 
GDALCreateGenImgProjTransformer() or GDALSuggestedWarpOutput() only 
exist in the C API, so you'd have to cast C++ dataset objects to C 
handles at some point. This also applies to the first snippet, which 
explains that using C functions is more practical to avoid those casts)) 
or C.


-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the gdal-dev mailing list