[gdal-dev] HFA (.img) driver prints Warning 1: NaN converted to INT_MAX when float raster has nan as the NoData value
Even Rouault
even.rouault at spatialys.com
Thu May 8 14:51:30 PDT 2025
Jason,
It looks like something in the code asks a float64 field to be returned
as a int32, and thus NaN has to be turned into something else. That's
perhaps fine in the context where that happens with your file and could
potentially be silenced, but access to the file would be needed to
investigate
Even
Le 08/05/2025 à 23:01, Jason Roberts via gdal-dev a écrit :
> 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
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
--
http://www.spatialys.com
My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250508/0f6d0d56/attachment.htm>
More information about the gdal-dev
mailing list