Search code examples
gdalgeotiffgrib

Write GeoTIFF File to GRIB2 Using GDAL


I am looking to convert a GeoTIFF file to GRIB2, and define several pieces of metadata manually as seen in the provided literature here. I am using the GDAL library, specifically the script gdal translate.

My attempt to convert and pass specific metadata is as follows:

gdal_translate -b 1 -mo DISCIPLINE=0 IDS_CENTER=248 IDS_SUBCENTER=4 IDS_MASTER_TABLE=24 IDS_SIGNF_REF_TIME=1 IDS_REF_TIME=2020-07-02T00:00:00Z IDS_PROD_STATUS=0 IDS_TYPE=1 PDS_PDTN=0 PDS_TEMPLATE_NUMBERS="0 4 2 0 96 0 0 0 1 0 0 0 0 103 0 0 0 0 2 255 0 0 0 0 0 7 228 7 2 13 0 0 1 0 0 0 0 2 2 1 0 0 0 1 255 0 0 0 0" PDS_TEMPLATE_ASSEMBLED_VALUES="0 4 2 0 96 0 0 1 0 103 0 2 255 0 0 2020 7 2 13 0 0 1 0 2 2 1 1 255 0" input.tif output.grb2

However, upon executing this command I receive the following error:

ERROR 6: Too many command options 'IDS_MASTER_TABLE=24'

Potential errors: Not calling the correct subprocess (currently using -mo) when attempting to pass the metadata, all metadata pairs must be encased in quotation marks, etc.

Any help would be greatly appreciated!


Solution

  • You need to add an -mo flag for every metadata. Your command would become:

    $ gdal_translate -b 1 \
        -mo DISCIPLINE=0 \
        -mo IDS_CENTER=248 \
        # etc.
        input.tif output.grb2