From 7e71d01228d259d485a460b38365f9772c1ba047 Mon Sep 17 00:00:00 2001 From: Alvaro Huarte Date: Tue, 6 Feb 2018 10:08:22 +0100 Subject: [PATCH] Fix nodata values --- src/GDALTiler.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/GDALTiler.cpp b/src/GDALTiler.cpp index 041b77a..b6a671a 100644 --- a/src/GDALTiler.cpp +++ b/src/GDALTiler.cpp @@ -304,7 +304,26 @@ GDALTiler::createRasterTile(double (&adfGeoTransform)[6]) const { psWarpOptions->panDstBands = (int *) CPLMalloc(sizeof(int) * psWarpOptions->nBandCount ); + // Consider NODATA values + psWarpOptions->padfSrcNoDataReal = + (double *)CPLCalloc(psWarpOptions->nBandCount, sizeof(double)); + psWarpOptions->padfSrcNoDataImag = + (double *)CPLCalloc(psWarpOptions->nBandCount, sizeof(double)); + psWarpOptions->padfDstNoDataReal = + (double *)CPLCalloc(psWarpOptions->nBandCount, sizeof(double)); + psWarpOptions->padfDstNoDataImag = + (double *)CPLCalloc(psWarpOptions->nBandCount, sizeof(double)); + for (short unsigned int i = 0; i < psWarpOptions->nBandCount; ++i) { + int bGotNoData = FALSE; + double noDataValue = dataset()->GetRasterBand(i + 1)->GetNoDataValue(&bGotNoData); + if (!bGotNoData) noDataValue = -32768; + + psWarpOptions->padfSrcNoDataReal[i] = noDataValue; + psWarpOptions->padfSrcNoDataImag[i] = 0; + psWarpOptions->padfDstNoDataReal[i] = noDataValue; + psWarpOptions->padfDstNoDataImag[i] = 0; + psWarpOptions->panDstBands[i] = psWarpOptions->panSrcBands[i] = i + 1; }