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

Michael Sumner mdsumner at gmail.com
Tue Apr 5 04:11:35 PDT 2022


Excellent - I'll submit a PR for the include in the first snippet.

I've become more au fait with the different idioms today, and this
description is very helpful.

Best, Mike

On Tue, Apr 5, 2022 at 8:47 PM Even Rouault <even.rouault at spatialys.com>
wrote:
>
>
> 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.
>


--
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220405/939edaa0/attachment-0001.html>


More information about the gdal-dev mailing list