[gdal-dev] HFA (.img) driver prints Warning 1: NaN converted to INT_MAX when float raster has nan as the NoData value
Jason Roberts
jason.roberts at duke.edu
Thu May 8 14:01:47 PDT 2025
Hi GDAL team,
I'm working with the GDAL Python API. I have some HFA (.img) files that
are float32 and that use nan as their NoData value. As far as I can
tell, using nan is allowed but I could be wrong. When I open them, I get
"Warning 1: NaN converted to INT_MAX." Everything seems to work fine
after that. Is this message something I need to worry about? If not, may
I suggest you remove it from the HFA driver if possible?
Here's some code demonstrating the message. If need be, I can provide an
example file, or write some code to generate one.
>>> import numpy as np
>>> from osgeo import gdal
>>> gdal.__version__ # this version is packaged with ArcGIS Pro
3.4, but I don't think the version matters
'3.9.2e'
>>> ds =
gdal.Open(r'\\conch\denmod\Covariates\NARW25\CMEMS_GLORYS\SST\1999\SST_199901.img',
gdal.GA_ReadOnly)
Warning 1: NaN converted to INT_MAX.
>>> band = ds.GetRasterBand(1)
>>> gdal.GetDataTypeName(band.DataType)
'Float32'
>>> band.GetNoDataValue()
nan
>>> arr = band.ReadAsArray() # the data look ok:
>>> np.isnan(arr).sum()
86788
>>> (~np.isnan(arr)).sum()
142985
>>> np.max(arr)
nan
>>> np.nanmax(arr)
27.078554
As far as I can tell, the warning comes from this code in
gdal/frmts/hfa/hfafield.cpp:
else if (std::isnan(dfDoubleRet))
{
CPLError(CE_Warning, CPLE_AppDefined,
"NaN converted to INT_MAX.");
nIntRet = nMax;
}
But I don't know if there are any negative ramifications that will result.
Thank you for your help. And, as always, thank you very much for
developing and maintaining GDAL.
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250508/a42b00ee/attachment.htm>
More information about the gdal-dev
mailing list