(This should be a comment, but too long and too formatted.)
NB: This is using a Swift wrapper for GDAL, so not actual C++, but hopefully it will give you some idea of how I use GDALWarp()
. In particular, my use case DOES use the -r
option.
(Note the opts
, here, is the Swift array, and cOpts
is the equivalent C array.)
I hope this helps.
In brief, I just generate each element of each option as an element of the array. So in the case of the -r
option, both the -r
flag and the cubic
value are consecutive elements of the options arrary.
guard let destSRSWKT = srs.wkt() else { return (false, nil) }
let opts = ["-t_srs", destSRSWKT, "-r", "cubic", "-dstalpha", "-of", driver.nameShort()]
return withMutableArrayOfMutableCStrings(opts) { (cOpts) in
var optionalSourceDSRef: GDALDatasetH? = _ds
return withUnsafeMutablePointer(to: &optionalSourceDSRef) { (dsPointer) in
let warpOpts = GDALWarpAppOptionsNew(cOpts, nil)
if let _ = reprojectDelegate {
// Not possible to pass a closure as a C function parameter if the closure contains any context
// so have to convert anything required in the closure to pointer to pass in
// and then within the closure convert back to object
let selfPtrOuter = UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque())
GDALWarpAppOptionsSetProgress(warpOpts, { (progress, message, selfPtrInner) in
if let selfPtrInner = selfPtrInner {
let mySelf = Unmanaged<RasterDataset>.fromOpaque(selfPtrInner).takeUnretainedValue()
if let repDel = mySelf.reprojectDelegate {
return repDel.reprojectProgressShouldContinue(progress)
}
}
return 1
}, selfPtrOuter)
}
var err: Int32 = 0
let destDSRef = GDALWarp(url.path, nil, 1, dsPointer, warpOpts, &err)
GDALWarpAppOptionsFree(warpOpts)
const char* args[] =
, three times on consecutive lines? Each one replaces the one before it, making the earlier ones pointless. Also, the first of the three is missing some quotation marks. Additionally, please update your post to explain what goes wrong when you run the code (including full text of any error messages).