Opened 6 years ago

Closed 5 years ago

#4221 closed enhancement (fixed)

Support Create() method for NetCDF driver so that gdalwarp can be used on a netcdf file

Reported by: pds Owned by: warmerdam
Priority: normal Milestone:
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: NetCDF, Create, IO
Cc: etourigny


We'd like to be able to use gdalwarp functionality with NetCDF files as an output, which requires supporting the Create() and IWriteBlock() methods for the NetCDF driver.

The NetCDF C API supports creating a file with empty variables, then later updating an existing file, and random-access writing, all prerequisites for the Create() method in GDAL.

This should likely involve refactoring the GDAL driver so common functionality is shared between the Create() and CreateCopy?() methods.

Change History (9)

comment:1 Changed 6 years ago by Even Rouault

Cc: etourigny added

comment:2 Changed 5 years ago by etourigny

Re-factored the driver and added a Create() function, commited to trunk (r23456), and autotests (r23457).

Significant changes brought by this commit:

  • removed vars that are used temporarily (e.g. panBandZLev)
  • Set* functions write to netcdf file when in update mode
  • Create() and CreateCopy?() common functionality in CreateLL()
  • write bands now in IWriteBlock()
  • bottom-up = FALSE by default
  • updated all sprintf to (%.8g / %.16g) because of projection parameter precision differences

comment:3 Changed 5 years ago by etourigny

committed small fixes to trunk (r23458, r23459, r23460)

comment:4 Changed 5 years ago by Even Rouault

Etienne, you might want to check the correctness of the first part of the following fix :

r23461 /trunk/gdal/frmts/netcdf/netcdfdataset.cpp: Fix compiler warnings about wrong enum comparison, and uninitialized variable

comment:5 Changed 5 years ago by etourigny

Fix is fine, thanks. It worked before by chance, because NC_BYTE and GDT_Byte have the same value.

r23463: Added autotest for Create() and CreateCopy?() a band with unsigned byte data and fix to PIXELTYPE metadata when calling Create().

comment:6 Changed 5 years ago by etourigny

In GDAL Byte data is unsigned by default and uses PIXELTYPE=SIGNEDBYTE metadata to specify signed byte, following

Byte data in netcdf is by default signed, and the following conventions are used by the driver to specify unsigned byte

comment:7 Changed 5 years ago by etourigny

Using gdalwarp on a large dataset with -co COMPRESS=DEFLATE option (which forces NC4C format) does not work (takes a very long time). This is probably due to wrong chunksize, which was optimized for CreateCopy?(). Exporting without compression works, so use that for now.

comment:8 Changed 5 years ago by etourigny

r23635 : properly enable chunking in netCDFDataset::DefVarDeflate?() (#4404 and #4221)

comment:9 Changed 5 years ago by etourigny

Resolution: fixed
Status: newclosed

closing this ticket, see related bugs #4404 and #4432

Note: See TracTickets for help on using tickets.