[gdal-dev] Specify data type on opening a netcdf

Even Rouault even.rouault at spatialys.com
Fri Jul 31 06:37:32 PDT 2020


On vendredi 31 juillet 2020 15:04:45 CEST Federico Gianoli wrote:
> Dear all,
> I have an issue opening a netcdf with gdal. I should declare the data type
> of my raster in gdal.Open().
> 
> The Netcdf data type is declared in the metadata as "Float", but GDAL reads
> this information as Float64 and not as Float32. This reading error
> misinterprets my decimal values causing rounding errors.
> 
> float 32 to float64 (wrong):
> [0.9160000518, 0.920000052] > 0.92 --> [False, True] WRONG
> 
> flaot32 to float32 (correct):
> [0.916, 0.92] > 0.92 --> [False, False] CORRECT
> 
> 
> Is there a way to specify the input data type?

No. What do you mean by "The Netcdf data type is declared in the metadata as "Float"" ? Is 
this some text attribute that would override the native data type, which would be Float64 ? 
the GDAL netCDF driver has proper support for both Float32 or Float64 based on the data 
types of variable.
If you need to override it, your best option is to use the -ot Float32 switch of gdal_translate 
to down cast.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200731/42775bd5/attachment.html>


More information about the gdal-dev mailing list