Is there any way to set variable name in netCDF file with GDAL?
GDAL always sets the name Band1. I would like to set a different name. Still no success to find some -co (creation option) to overcome it.

E.g. command to rasterize a polygon

gdal_rasterize -a value -ot Int16 -te -180 -60 180 60 -tr 0.01 0.01 -of netCDF -co WRITE_LONLAT=YES -co TYPE_LONLAT=float -co FORMAT=NC4 -co COMPRESS=DEFLATE -l input input.shp result.nc

Possibly, is there any other simple way to do this?

  • No, you can't set the name of each band (2D variable) with the NetCDF driver. – mdsumner Dec 13 '17 at 11:18

Don't think that's currently possible with GDAL for netcdf. Otherwise, this would work

    rasterband1.setDescription("A better band name")

Instead you might be better off using a different command line tool such as: https://code.mpimet.mpg.de/projects/cdo or even with the netCDF4 library in python.

  • Unfortunatelly, my research until now is the same: no creation option with GDAL. Thanks @toferkey for another two hints. – jurajb Dec 13 '17 at 15:44

Use NCO's ncrename utility to rename the variable Band1 to my_var, keeping the same filename:

ncrename -v Band1,my_var result.nc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.