Skip to content

Commit

Permalink
Merge pull request #4646 from rouault/fix_rasterio_2233
Browse files Browse the repository at this point in the history
GDALAutoCreateWarpedVRTEx(): do not set padfSrcNoDataReal/padfDstNoDataReal if already set in passed-in options (fixes rasterio/rasterio#2233)
  • Loading branch information
rouault authored and github-actions[bot] committed Oct 15, 2021
1 parent 85c200d commit f754ae3
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions gdal/frmts/vrt/vrtwarped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,39 +153,44 @@ GDALAutoCreateWarpedVRTEx( GDALDatasetH hSrcDS,
GDALWarpInitDefaultBandMapping( psWO, GDALGetRasterCount( hSrcDS ) );

/* -------------------------------------------------------------------- */
/* Setup no data values */
/* Setup no data values (if not done in psOptionsIn) */
/* -------------------------------------------------------------------- */
for( int i = 0; i < psWO->nBandCount; i++ )
if( psWO->padfSrcNoDataReal == nullptr &&
psWO->padfDstNoDataReal == nullptr &&
psWO->nSrcAlphaBand == 0 )
{
GDALRasterBandH rasterBand = GDALGetRasterBand(psWO->hSrcDS, psWO->panSrcBands[i]);
for( int i = 0; i < psWO->nBandCount; i++ )
{
GDALRasterBandH rasterBand = GDALGetRasterBand(psWO->hSrcDS, psWO->panSrcBands[i]);

int hasNoDataValue;
double noDataValue = GDALGetRasterNoDataValue(rasterBand, &hasNoDataValue);
int hasNoDataValue;
double noDataValue = GDALGetRasterNoDataValue(rasterBand, &hasNoDataValue);

if( hasNoDataValue )
{
// Check if the nodata value is out of range
int bClamped = FALSE;
int bRounded = FALSE;
CPL_IGNORE_RET_VAL(
GDALAdjustValueToDataType(GDALGetRasterDataType(rasterBand),
noDataValue, &bClamped, &bRounded ));
if( !bClamped )
if( hasNoDataValue )
{
GDALWarpInitNoDataReal(psWO, -1e10);
// Check if the nodata value is out of range
int bClamped = FALSE;
int bRounded = FALSE;
CPL_IGNORE_RET_VAL(
GDALAdjustValueToDataType(GDALGetRasterDataType(rasterBand),
noDataValue, &bClamped, &bRounded ));
if( !bClamped )
{
GDALWarpInitNoDataReal(psWO, -1e10);

psWO->padfSrcNoDataReal[i] = noDataValue;
psWO->padfDstNoDataReal[i] = noDataValue;
psWO->padfSrcNoDataReal[i] = noDataValue;
psWO->padfDstNoDataReal[i] = noDataValue;
}
}
}
}

if( psWO->padfDstNoDataReal != nullptr )
{
if (CSLFetchNameValue( psWO->papszWarpOptions, "INIT_DEST" ) == nullptr)
if( psWO->padfDstNoDataReal != nullptr )
{
psWO->papszWarpOptions =
CSLSetNameValue(psWO->papszWarpOptions, "INIT_DEST", "NO_DATA");
if (CSLFetchNameValue( psWO->papszWarpOptions, "INIT_DEST" ) == nullptr)
{
psWO->papszWarpOptions =
CSLSetNameValue(psWO->papszWarpOptions, "INIT_DEST", "NO_DATA");
}
}
}

Expand Down

0 comments on commit f754ae3

Please sign in to comment.