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

Federico Gianoli alpacagis at gmail.com
Fri Jul 31 08:01:46 PDT 2020


Thanks Even,

If I look at the metadata of my netcdf, the values of "offset" and "scale
factor" are in float64 instead of float32. So the correct values to read
should be -0.08 as offset and 0.004 as scale factor.
If I open the netcdf in SNAP, for example, I am able to correctly see this
information. So, I suppose that, by default, gdal reads metadata values  in
float64 instead of 32bit, and I would like to know if there is a way to
force gdal to read these values as float32.

  NC_GLOBAL#title=10-daily Normalized Difference Vegetation Index 333M:
GLOBE 2020-06-21T00:00:00Z
  NDVI#add_offset=-0.079999998
  NDVI#flag_meanings=Missing cloud snow sea background
  NDVI#flag_values={251,252,253,254,255}
  NDVI#grid_mapping=crs
  NDVI#missing_value=255
  NDVI#scale_factor=0.0040000002
  NDVI#valid_range={0,250}
  NDVI#_FillValue=255

Band 1 Block=3270x1272 Type=Byte, ColorInterp=Undefined
  NoData Value=255
  Offset: -0.0799999982118607,   Scale:0.00400000018998981
  Metadata:
    add_offset=-0.079999998
    flag_meanings=Missing cloud snow sea background
    flag_values={251,252,253,254,255}
    grid_mapping=crs
    long_name=Normalized Difference Vegetation Index 333M
    missing_value=255
    NETCDF_VARNAME=NDVI
    scale_factor=0.0040000002
    valid_range={0,250}
    _FillValue=255



Il giorno ven 31 lug 2020 alle ore 15:37 Even Rouault <
even.rouault at spatialys.com> ha scritto:

> 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/cef0a32d/attachment.html>


More information about the gdal-dev mailing list