[gdal-dev] Creating NetCDF dataset with sub datasets
Even Rouault
even.rouault at spatialys.com
Tue Mar 12 05:48:21 PDT 2024
Le 12/03/2024 à 13:33, Pierre Chatelier a écrit :
>>
>>> But I can't figure out how to customize the <band name>, which is
>>> Band1, Band2, Band3...
>>> I tried GDALRasterBand::SetDescription(), but without success
>>
>> Looking at netcdfdataset.cpp line 9625, the netCDF variable name for
>> a band is extracted from the NETCDF_VARNAME band metadata item of the
>> source band.
>
>
> Sounds good, doesn't work.
It must be set on the *source* band, before creating CreateCopy(). I've
just tested it successfully with:
$ gdal_translate byte.tif input.vrt
$ python -c "from osgeo import gdal; ds = gdal.Open('input.vrt',
gdal.GA_Update); ds.GetRasterBand(1).SetMetadataItem('NETCDF_VARNAME',
'my_varname'); ds.SetMetadataItem('my_varname#long_name', 'my long name')"
$ gdal_translate input.vrt tmp.nc
$ ncdump -h tmp.nc | grep my_varname
byte my_varname(y, x) ;
my_varname:long_name = "my long name" ;
my_varname:_Unsigned = "true" ;
my_varname:valid_range = 0s, 255s ;
my_varname:grid_mapping = "transverse_mercator" ;
Not super intuitive admitedly. This is mostly done in a way that netCDF
-> netCDF CreateCopy() preserve the variable name and long_name attributes
--
http://www.spatialys.com
My software is free, but my time generally not.
More information about the gdal-dev
mailing list