[gdal-dev] Is it possible to modify netCDF driver so that it behaves like geotiff driver when operating on multiple datasets netcdf file

Etienne Tourigny etourigny.dev at gmail.com
Thu Mar 8 09:11:22 EST 2012


Hendy,

I suggest you have a look at the recent netcdf driver in trunk, I have
implemented proper handling of multidimension netcdf variables
(T,Z,Y,X). This might be able to resolve your problem - providing you
are able to create a netcdf file with multiple dimensions as this is
not done by the driver.

Basically, if a netcdf file has multiple dimensions (other than X,Y),
the driver creates multiple bands in GDAL  (as before), but when the
file is written back to netcdf, the driver creates a single variable
instead of a variable for each band.  However, this does not work for
gdalwarp directly, but works if using an intermediary VRT file.

See http://trac.osgeo.org/gdal/ticket/2581

On Thu, Mar 8, 2012 at 12:29 AM, Hendy Sumanto <hsumanto at vpac.org> wrote:
> Hi Devs,
>
> I have a geotiff file which contains several datasets, with this I just need to perform one gdalwarp operation on this geotiff file to apply transformation on 6 datasets inside it and the operation produces just one geotiff output file.
>
> If I translate this geotiff file into netcdf file, now I need to perform 6 operations to apply transformation on each of the 6 datasets inside it and produces 6 separate netcdf files which is quite cumbersome.

You are confusing GDAL "dataset" with GDAL "band" and netcdf
"variable", which is quite normal. Let me explain:

A "dataset" has its own projection and geotransform(GT), and a number
of bands which are (usually) of the same data type. In your gtiff
example, there is one dataset in WGS84 GCS with multiple bands of the
same type (Float64).

A netcdf file can have many "variables", each with their own
projection/geotransform (lon/lat variable and/or grid_mapping
variable) and data type.  So in many cases a netcdf file can contain
many "datasets" (one for each variable) when opened in GDAL - which
are treated as "subdatasets: (as in your example).

So when translating a multi-band gtiff file to netcdf, the GDAL netcdf
driver creates a variable for each band, so that is why a multi-band
gtiff gets converted to netcdf with many variables (although they are
of the same type and projection/GT).

>
> I am wondering if it is possible to modify the current netCDF driver so that it behaves like geotiff driver when operating on multiple bands (datasets) netcdf file.
> Any opinion on this is really appreciated.

In order for the driver to create a netcdf file which will have
muliple bands (and not sub-datasets) it would have to create a single
variable, with an extra dimension (such as time or height/depth) to
store the mulriple bands in a single variable.
Another option would be to modify the driver to scan for all variables
in Open(), and instead of creating subdatasets create a number of
bands IF they are of the same type and projection.

Either one are rather involved I'm afraid...

>
> This might be a potential issue though:
> When the several datasets have the same data type, it is not an issue but
> when the several datasets have different data type (some datasets are float while some other metadata are integer), then it might be an issue as when we do gdalwarp operation selecting one method of interpolation, that chosen interpolation method will be applied across all data types for all datasets in that single file.

I'm afraid that many file formats do not support bands of different
data types (such as GTiff), which would make it difficult to translate
to/from other formats.
A potential limitation is the  GDALDriver::Create() function which
takes a single data type as argument.
http://www.gdal.org/gdal_drivertut.html#gdal_drivertut_creation

-> although individual drivers do not have to respect that (I think) -
perhaps Even or someone else can comment?

Etienne

>
> =============================
> gdalinfo on the geotiff file: and netcdf file:
> =============================
> Driver: GTiff/GeoTIFF
> Files: multipledataset.tif
> Size is 4, 3
> Coordinate System is:
> GEOGCS["WGS 84",
>    DATUM["WGS_1984",
>        SPHEROID["WGS 84",6378137,298.257223563,
>            AUTHORITY["EPSG","7030"]],
>        AUTHORITY["EPSG","6326"]],
>    PRIMEM["Greenwich",0],
>    UNIT["degree",0.0174532925199433],
>    AUTHORITY["EPSG","4326"]]
> Origin = (141.000867233935992,-34.060737220013806)
> Pixel Size = (0.107999999999998,-0.107999999999998)
> Metadata:
>  AREA_OR_POINT=Area
> Image Structure Metadata:
>  INTERLEAVE=PIXEL
> Corner Coordinates:
> Upper Left  ( 141.0008672, -34.0607372) (141d 0' 3.12"E, 34d 3'38.65"S)
> Lower Left  ( 141.0008672, -34.3847372) (141d 0' 3.12"E, 34d23' 5.05"S)
> Upper Right ( 141.4328672, -34.0607372) (141d25'58.32"E, 34d 3'38.65"S)
> Lower Right ( 141.4328672, -34.3847372) (141d25'58.32"E, 34d23' 5.05"S)
> Center      ( 141.2168672, -34.2227372) (141d13' 0.72"E, 34d13'21.85"S)
> Band 1 Block=4x3 Type=Float64, ColorInterp=Gray
> Band 2 Block=4x3 Type=Float64, ColorInterp=Undefined
> Band 3 Block=4x3 Type=Float64, ColorInterp=Undefined
> Band 4 Block=4x3 Type=Float64, ColorInterp=Undefined
> Band 5 Block=4x3 Type=Float64, ColorInterp=Undefined
> Band 6 Block=4x3 Type=Float64, ColorInterp=Undefined
>
> =============================
> gdalinfo on the netcdf file:
> =============================
> Driver: netCDF/Network Common Data Format
> Files: multipledataset.nc
> Size is 512, 512
> Coordinate System is `'
> Metadata:
>  NC_GLOBAL#Conventions=CF-1.5
>  NC_GLOBAL#GDAL=GDAL 1.9.0, released 2011/12/29
>  NC_GLOBAL#history=Thu Mar 08 14:03:01 2012: GDAL Create( multipledataset.nc, ... )
> Subdatasets:
>  SUBDATASET_1_NAME=NETCDF:"multipledataset.nc":Band1
>  SUBDATASET_1_DESC=[3x4] Band1 (64-bit floating-point)
>  SUBDATASET_2_NAME=NETCDF:"multipledataset.nc":Band2
>  SUBDATASET_2_DESC=[3x4] Band2 (64-bit floating-point)
>  SUBDATASET_3_NAME=NETCDF:"multipledataset.nc":Band3
>  SUBDATASET_3_DESC=[3x4] Band3 (64-bit floating-point)
>  SUBDATASET_4_NAME=NETCDF:"multipledataset.nc":Band4
>  SUBDATASET_4_DESC=[3x4] Band4 (64-bit floating-point)
>  SUBDATASET_5_NAME=NETCDF:"multipledataset.nc":Band5
>  SUBDATASET_5_DESC=[3x4] Band5 (64-bit floating-point)
>  SUBDATASET_6_NAME=NETCDF:"multipledataset.nc":Band6
>  SUBDATASET_6_DESC=[3x4] Band6 (64-bit floating-point)
> Corner Coordinates:
> Upper Left  (    0.0,    0.0)
> Lower Left  (    0.0,  512.0)
> Upper Right (  512.0,    0.0)
> Lower Right (  512.0,  512.0)
> Center      (  256.0,  256.0)
>
>
>
> Regards,
>
> Hendy
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list