Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDALAutoCreateWarpedVRTEx(): do not set padfSrcNoDataReal/padfDstNoDataReal if already set in passed-in options (fixes mapbox/rasterio#2233) #4646

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions gdal/frmts/vrt/vrtwarped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,39 +157,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 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rouault in rasterio/rasterio#2233 we'd like the arrays to be NULL, have no source alpha band, but then use the source's internal mask band. I haven't had a chance to try this PR yet, but I think my use case will pass that test above, and shouldn't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then use the source's internal mask band

use of the source's internal (non-alpha) mask band is something that has no direct control in the psWO structure. It should trigger automatically in the WarpOperation logic at https://github.com/OSGeo/gdal/blob/master/gdal/alg/gdalwarpoperation.cpp#L2149

{
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