Opened 17 years ago

Closed 13 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 Shannon

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 17 years ago.
netcdf-scale-offset-support-mloskot.patch (150.0 KB ) - added by Mateusz Łoskot 16 years ago.
This is regular patch including fixes proposed in attached netcdfdataset.cpp file.

Download all attachments as: .zip

Change History (10)

by hulst, 17 years ago

Attachment: netcdfdataset.cpp added

comment:1 by hulst, 17 years ago

Component: defaultGDAL_Raster
Milestone: 1.5.0
Version: 1.4.1svn-trunk

comment:2 by warmerdam, 17 years ago

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 by hulst, 17 years ago

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 by warmerdam, 16 years ago

Owner: changed from Denis Nadeau to dnadeau

by Mateusz Łoskot, 16 years ago

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

comment:5 by Mateusz Łoskot, 16 years ago

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 by Kyle Shannon, 14 years ago

Cc: Kyle Shannon added

comment:7 by Kyle Shannon, 14 years ago

Keywords: netcdf scale offset add_offset scale_factor → netcdf, scale offset, add_offset, scale_factor

comment:8 by Kyle Shannon, 13 years ago

Milestone: 1.5.41.8.0
Resolution: duplicate
Status: newclosed

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.