[gdal-dev] how to create NETCDF with several 3D variables?

Anton Korosov anton.korosov at nersc.no
Mon Jul 23 07:50:30 PDT 2012


Dear list,

how to create a NetCDF file with several variables that have more than 
two dimensions?
I have to save time series of several fields (sst, chlorophyll, etc) in 
one file.

I found that in order to create one 3D variable I can add
NETCDF_DIM_EXTRA, NETCDF_DIM_time_DEF, NETCDF_DIM_time_VALUES to the 
metadata in a VRT file. Then I use 'gdal_translate -of NetCDF' or 
gdal.GetDriverByName('NetCDF').CreateCopy() to generate a .nc file.

However I cannot make several 3D variables!

Here are two VRTs. One works fine (one variable: 'sst', 3 dimentions: 
time, x, y). Another one produces two variables (chl, sst)  but time 
dimension is not added!
Is it possible to do it in theory?

I use the latest release of GDAL 2.0dev

With best regards and great thanks for the developers of the fantastic 
NetCDF driver!

Anton
-------------- next part --------------
<VRTDataset rasterXSize="4320" rasterYSize="2160">
  <SRS>GEOGCS["Clarke_1866",DATUM["Clarke_1866",SPHEROID["Clarke 1866",6378206.4,294.9786982139006]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]</SRS>
  <GeoTransform> -1.7999999491497874e+02,  8.3333335816860199e-02,  0.0000000000000000e+00,  9.0000002544373274e+01,  0.0000000000000000e+00, -8.3333335816860199e-02</GeoTransform>
  <Metadata>
    <MDI key="NETCDF_DIM_EXTRA">{time}</MDI>
    <MDI key="NETCDF_DIM_time_DEF">{3,6}</MDI>
    <MDI key="NETCDF_DIM_time_VALUES">{0,1,2}</MDI>
  </Metadata>
  <VRTRasterBand dataType="Int16" band="1">
    <Metadata>
      <MDI key="NETCDF_DIM_time">0</MDI>
      <MDI key="NETCDF_VARNAME">sst</MDI>
    </Metadata>
    <ColorInterp>Gray</ColorInterp>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">gdal_test/alwdgg.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="4320" RasterYSize="2160" DataType="Int16" BlockXSize="4320" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
      <DstRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
    </SimpleSource>
  </VRTRasterBand>
  <VRTRasterBand dataType="Int16" band="2">
    <Metadata>
      <MDI key="NETCDF_DIM_time">1</MDI>
      <MDI key="NETCDF_VARNAME">sst</MDI>
    </Metadata>
    <ColorInterp>Gray</ColorInterp>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">gdal_test/alwdgg.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="4320" RasterYSize="2160" DataType="Int16" BlockXSize="4320" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
      <DstRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
    </SimpleSource>
  </VRTRasterBand>
  <VRTRasterBand dataType="Int16" band="3">
    <Metadata>
      <MDI key="NETCDF_DIM_time">2</MDI>
      <MDI key="NETCDF_VARNAME">sst</MDI>
    </Metadata>
    <ColorInterp>Gray</ColorInterp>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">gdal_test/alwdgg.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="4320" RasterYSize="2160" DataType="Int16" BlockXSize="4320" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
      <DstRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
    </SimpleSource>
  </VRTRasterBand>
</VRTDataset>
-------------- next part --------------
<VRTDataset rasterXSize="4320" rasterYSize="2160">
  <SRS>GEOGCS["Clarke_1866",DATUM["Clarke_1866",SPHEROID["Clarke 1866",6378206.4,294.9786982139006]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]</SRS>
  <GeoTransform> -1.7999999491497874e+02,  8.3333335816860199e-02,  0.0000000000000000e+00,  9.0000002544373274e+01,  0.0000000000000000e+00, -8.3333335816860199e-02</GeoTransform>
  <Metadata>
    <MDI key="NETCDF_DIM_EXTRA">{time}</MDI>
    <MDI key="NETCDF_DIM_time_DEF">{0,6}</MDI>
    <MDI key="NETCDF_DIM_time_VALUES">0</MDI>
  </Metadata>
  <VRTRasterBand dataType="Int16" band="1">
    <Metadata>
      <MDI key="NETCDF_DIM_time">0</MDI>
      <MDI key="NETCDF_VARNAME">sst</MDI>
    </Metadata>
    <ColorInterp>Gray</ColorInterp>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">gdal_test/alwdgg.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="4320" RasterYSize="2160" DataType="Int16" BlockXSize="4320" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
      <DstRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
    </SimpleSource>
  </VRTRasterBand>
  <VRTRasterBand dataType="Int16" band="2">
    <Metadata>
      <MDI key="NETCDF_DIM_time">0</MDI>
      <MDI key="NETCDF_VARNAME">chl</MDI>
    </Metadata>
    <ColorInterp>Gray</ColorInterp>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">gdal_test/alwdgg.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="4320" RasterYSize="2160" DataType="Int16" BlockXSize="4320" BlockYSize="1" />
      <SrcRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
      <DstRect xOff="0" yOff="0" xSize="4320" ySize="2160" />
    </SimpleSource>
  </VRTRasterBand>
</VRTDataset>


More information about the gdal-dev mailing list