[gdal-dev] GDAL multi bands files conversion to NetCDF

Even Rouault even.rouault at spatialys.com
Wed Jul 18 11:43:43 PDT 2018


Louis Philippe

there's no one single step to do that, but you can do that in 2 steps:

- use gdal_translate -sds to export all the subdatasets in separate tif files
- use gdal_merge.py -separate to combine them in a single tif file (provided 
they have same resolution, extent, cordinate system), which seems to be your 
case here

Even

> Hi everyone!
> 
> I have s question regarding the conversion of a multiband file (like
> GeoTIFF) to NetCDF.
> 
> First my observations:
> 
> I used gdal_translate to convert a Geotiff to NetCDF:
> 
> gdal_translate -of input.tif result.nc
> 
> The gdalinfo result is:
> 
> Driver: netCDF/Network Common Data Format
> Files: result.nc
> Size is 512, 512
> Coordinate System is `'
> Metadata:
>   NC_GLOBAL#Conventions=CF-1.5
>   NC_GLOBAL#GDAL=GDAL 1.10.0, released 2013/04/24
>   NC_GLOBAL#GDAL_AREA_OR_POINT=Area
>   NC_GLOBAL#history=Wed Jul 18 15:33:16 2018: GDAL CreateCopy( result.nc,
> ... ) Subdatasets:
>   SUBDATASET_1_NAME=NETCDF:"result.nc":Band1
>   SUBDATASET_1_DESC=[1500x1650] Band1 (32-bit floating-point)
>   SUBDATASET_2_NAME=NETCDF:"result.nc":Band2
>   SUBDATASET_2_DESC=[1500x1650] Band2 (32-bit floating-point)
>   SUBDATASET_3_NAME=NETCDF:"result.nc":Band3
>   SUBDATASET_3_DESC=[1500x1650] Band3 (32-bit floating-point)
>   SUBDATASET_4_NAME=NETCDF:"result.nc":Band4
>   SUBDATASET_4_DESC=[1500x1650] Band4 (32-bit floating-point)
>   SUBDATASET_5_NAME=NETCDF:"result.nc":Band5
>   SUBDATASET_5_DESC=[1500x1650] Band5 (32-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)
> 
> As you can see, the different bands are written in different SUBDATASET. I
> would like the output to be only different bands, not different datasets. I
> don't think I saw a creation option that could do that...
> 
> I would like something like:
> 
> Driver: netCDF/Network Common Data Format
> Files: output.nc
> Size is 1068, 510
> Coordinate System is `'
> Origin = (-140.999964377091317,83.499994903744323)
> Pixel Size = (0.083333295198278,-0.083333313348017)
> Metadata:
>   lat#axis=Y
>   lat#long_name=latitude
>   lat#standard_name=latitude
>   lat#units=degrees_north
>   lon#axis=X
>   lon#long_name=longitude
>   lon#standard_name=longitude
>   lon#units=degrees_east
> ...Some metadata...
> Corner Coordinates:
> Upper Left  (-140.9999644,  83.4999949)
> Lower Left  (-140.9999644,  41.0000051)
> Upper Right ( -52.0000051,  83.4999949)
> Lower Right ( -52.0000051,  41.0000051)
> Center      ( -96.4999847,  62.2500000)
> Band 1 Block=1068x1 Type=Float32, ColorInterp=Undefined
>     Computed Min/Max=-29.841,11.720
>   NoData Value=-99
>   Metadata:
>     long_name=Autumn mean temperature
>     missing_value=-99
>     NETCDF_DIM_time=17093376
>     NETCDF_VARNAME=tm_son
>     _FillValue=-99
> Band 2 Block=1068x1 Type=Float32, ColorInterp=Undefined
>     Computed Min/Max=-30.198,11.576
>   NoData Value=-99
>   Metadata:
>     long_name=Autumn mean temperature
>     missing_value=-99
>     NETCDF_DIM_time=17102136
>     NETCDF_VARNAME=tm_son
>     _FillValue=-99
> Band 3 Block=1068x1 Type=Float32, ColorInterp=Undefined
>     Computed Min/Max=-30.479,11.854
>   NoData Value=-99
>   Metadata:
>     long_name=Autumn mean temperature
>     missing_value=-99
>     NETCDF_DIM_time=17110920
>     NETCDF_VARNAME=tm_son
>     _FillValue=-99
> 
> 
> Is there anything I missed ? Can you think of another way to do that ?
> 
> Thanks a lot!
> 
> LP


-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list