Opened 8 years ago

Closed 5 years ago

#1660 closed enhancement (duplicate)

add support for scale and offset in netCDF driver.

Reported by: hulst Owned by: dnadeau
Priority: normal Milestone: 1.8.0
Component: GDAL_Raster Version: svn-trunk
Severity: normal Keywords: netcdf, scale offset, add_offset, scale_factor
Cc: hulst@…, kyle

Description

Hello,

I've modified the netcdf driver so that it supports scale and offset attributes.

http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.0/cf-conventions.html#attribute-appendix

One can argue from the description above that the netcdf driver is not responsible for applying offset and scale, but the calling application. I find the driver a convenient location.

Attached you find the updated driver. For now I can think of one situation where the driver gives problems:

--- In order to apply scale and offset the data is read in the native netCDF type (f.i. UInt16), but stored as a float in memory. I maintain the original _FillValue of the originating dataset (e.g., -32768). When the dataset contains this value after the application of scale and offset the data is wrongfully accused of being garbage. A small chance, but still. ---

Regards, Sander

Attachments (2)

netcdfdataset.cpp (102.7 KB) - added by hulst 8 years ago.
netcdf-scale-offset-support-mloskot.patch (150.0 KB) - added by mloskot 8 years ago.
This is regular patch including fixes proposed in attached netcdfdataset.cpp file.

Download all attachments as: .zip

Change History (10)

Changed 8 years ago by hulst

comment:1 Changed 8 years ago by hulst

  • Component changed from default to GDAL_Raster
  • Milestone set to 1.5.0
  • Version changed from 1.4.1 to svn-trunk

comment:2 Changed 8 years ago by warmerdam

Sander,

Note that GDALRasterBand has methods to get the offset and scale. The normal GDAL practice would be to return them via those methods - not to apply them on the fly. Then it is up to the caller to do so if they wish.

comment:3 Changed 8 years ago by hulst

Hi Frank,

I'm aware of that. I have implemented the GetOffset? etc for netCDF. Indeed I apply them on the fly if I encounter such an attribute.

I agree with you that this is not the way it is normally done (only on request), but I failed to see how I should make such a request. Especially from mapserver that is.

Note that I need to take a real good look at the driver as there's an issue with int8 data, but I'll sort that out.

comment:4 Changed 8 years ago by warmerdam

  • Owner changed from Denis Nadeau to dnadeau

Changed 8 years ago by mloskot

This is regular patch including fixes proposed in attached netcdfdataset.cpp file.

comment:5 Changed 8 years ago by mloskot

Unfortunately, using attached netcdfdataset.cpp file to generate regular patch with svn diff output big patch being a mixture of real fixes and fake fixes like mixed tabs/spaces, etc.

I'd suggest and be very thankful for submitting real patches generated on user's system shortly after fixes have been applied, instead of submitting just a changed file. Patches are easy to review and apply, big files of mess are almost impossible to apply.

comment:6 Changed 6 years ago by kyle

  • Cc kyle added

comment:7 Changed 5 years ago by kyle

  • Keywords changed from netcdf scale offset add_offset scale_factor to netcdf, scale offset, add_offset, scale_factor

comment:8 Changed 5 years ago by kyle

  • Milestone changed from 1.5.4 to 1.8.0
  • Resolution set to duplicate
  • Status changed from new to closed

changing this to a duplicate of #3797 , as it has a test dataset. I will take a look at the patch as well.

Note: See TracTickets for help on using tickets.