[gdal-dev] GDALWarpAppOptionsNew and GDALWarp usage?

Sean Gillies sean.gillies at gmail.com
Wed Apr 13 13:36:03 PDT 2022


Thanks, Even!

When I checked the return of GDALWarpAppOptionsNew() and the error stack, I
found that the problem was that I'd been adding an unexpected "-wt
Unknown". After screening that out, I'm getting the resampling I expect.

On Wed, Apr 13, 2022 at 2:10 PM Even Rouault <even.rouault at spatialys.com>
wrote:

> Sean,
>
> This looks fine, except for the argv[0] value, "lolwut". What is that
> supposed to be ? I assume GDALWarpAppOptionsNew() fails on that and returns
> NULL.
>
> The obvious demo for using GDALWarp() is the gdalwarp binary itself:
> https://github.com/OSGeo/gdal/blob/master/apps/gdalwarp_bin.cpp
>
> The COG driver is also a user of it, perhaps more illustrative than the
> above :
> https://github.com/OSGeo/gdal/blob/master/frmts/gtiff/cogdriver.cpp#L552
>
> Even
> Le 13/04/2022 à 21:53, Sean Gillies a écrit :
>
> Hi all,
>
> I'm trying to figure out how to use the GDALWarp function from
> gdalwarp_lib.cpp. It looks like it takes a pointer to a GDALWarpAppOptions
> structure that is parsed from a string list, basically gdalwarp's argv,
> right?
>
> I'm able to get it to warp data, but the options, specifically the
> resampling option, don't seem to be passed into the warper. The output is
> the same for all resampling values.
>
> Here's my C usage (Cython, actually, but translates to C).
>
>     cdef GDALWarpAppOptions *warp_options = NULL
>     cdef char **argv = NULL
>
>     try:
>
>
>         argv = CSLAddString(argv, <const char *>"lolwut")
>         resampling_opt_value = Resampling(resampling).name  # like
> "bilinear"
>         argv = CSLAddString(argv, <const char *>"-r")
>         argv = CSLAddString(argv, <const char *>resampling_opt_value)
>         ...
>         CSLPrint(argv, NULL)
>         warp_options = GDALWarpAppOptionsNew(argv, NULL)
>         output_ds = GDALWarp(
>             NULL,
>             dst_dataset,
>             1,
>             src_datasets,
>             warp_options,
>             NULL
>         )
>     finally:
>         ...
>
> The printed output, my argv, is
>
>     lolwut
>     -r
>     bilinear
>
> Does GDALWarpAppOptionsNew expect more values at the head of the command
> line? Is that why it is missing "-r"? Or is my string list made up of the
> wrong kind of strings? Documentation examples of building the arguments for
> GDALWarp are scarce. I'd be super grateful for help from anyone who has got
> code this to work.
>
> Thanks,
>
>
-- 
Sean Gillies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220413/f3d621cd/attachment.html>


More information about the gdal-dev mailing list