My investigation, might be an issue for the github :

band->SetMetadataItem("NETCDF_VARNAME", "foo"); will generate a netCDF band 
name of "foo1" because there must be a non-null papszExtraDimNames for some 
reason (netcdfdatasetp.cpp:9630)

However
-in order for "papszExtraDimNames" to be non-null, there must be a 
dataset->SetMetadataItem("NETCDF_DIM_EXTRA", ...)
-NETCDF_DIM_EXTRA="{}" is an empty array tokenized as null and does not help
-NETCDF_DIM_EXTRA="{dim1_name, dim2_name, ...}" will require 
NETCDF_DIM_dim<i>_name_DEF={dimension_size<i>,netcdf_data_type}...
-however, using extram dims  requires that the 
nDimSizeTot=product_i(dimension_size<i>, ...) == nBands ( 
(netcdfdatasetp.cpp:9473)
-this condition is a non sense in my scenario of a fixed number of 2D bands, 
there is no dimension_size<i> so that product_i(dimension_size<i>, ...) == 
nBands

Is there a bug or an artificial limitation by the current netCDF driver 
implementation ?

Pierre

> On 12 Mar 2024, at 14:16, Pierre Chatelier via gdal-dev 
> <gdal-dev@lists.osgeo.org> wrote:
> 
> Le 12/03/2024 à 13:48, Even Rouault a écrit :
>> 
>> 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:
> 
> For now I still have two problems :
> -it means I cannot work in-place in the final netCDF dataset, I have to use 
> another dataset and use CreateCopy()
> -for now  band->SetMetadataItem("NETCDF_VARNAME", "foo"); will generate a 
> netCDF band name of "foo1" because there is something related to 
> NETCDF_DIM_EXTRA that adds an index. (netcdfdatasetp.cpp:10507)
> 
>  I am investigating if I can force (even an empty) NETCDF_DIM_EXTRA. (but for 
> now it does not work)
> 
>> 
>> $ 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
>> 
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to