Skip to content

Commit

Permalink
Merge pull request OSGeo#3745 from rouault/fix_cog_nan
Browse files Browse the repository at this point in the history
GTIFF/COG: fix overviews with NaN nodata value
  • Loading branch information
rouault authored Apr 26, 2021
2 parents 8fb9647 + 8c6798f commit 7dd9d71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions autotest/gcore/tiff_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -7447,6 +7447,22 @@ def test_tiff_write_lerc_float_with_nan(gdalDataType, structType):
ds = None
gdal.Unlink(filename)

###############################################################################
# Test creating overviews with NaN nodata


def test_tiff_write_overviews_nan_nodata():

filename = '/vsimem/test_tiff_write_overviews_nan_nodata.tif'
ds = gdal.GetDriverByName('GTiff').Create(filename, 32, 32, 1, gdal.GDT_Float32, options=['TILED=YES', 'SPARSE_OK=YES'])
ds.GetRasterBand(1).SetNoDataValue(float('nan'))
ds.BuildOverviews('NONE', [2, 4])
ds = None
ds = gdal.Open(filename)
assert ds.GetRasterBand(1).GetOverviewCount() == 2
ds = None
gdal.Unlink(filename)


def test_tiff_write_cleanup():
gdaltest.tiff_drv = None
4 changes: 3 additions & 1 deletion gdal/frmts/gtiff/geotiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5853,7 +5853,9 @@ CPLErr GTiffRasterBand::SetNoDataValue( double dfNoData )
{
m_poGDS->LoadGeoreferencingAndPamIfNeeded();

if( m_poGDS->m_bNoDataSet && m_poGDS->m_dfNoDataValue == dfNoData )
if( m_poGDS->m_bNoDataSet &&
(m_poGDS->m_dfNoDataValue == dfNoData ||
(std::isnan(m_poGDS->m_dfNoDataValue) && std::isnan(dfNoData))) )
{
m_bNoDataSet = true;
m_dfNoDataValue = dfNoData;
Expand Down

0 comments on commit 7dd9d71

Please sign in to comment.