GDAL – How to Convert NetCDF to GeoTIFF Upside Down

climate-data-operatorsgdalgdal-translatenetcdf

I want to convert monthly precipitation netCDF file, downloaded from TerraClimate data to GeoTIFF and available as 1 file per year. Example: http://thredds.northwestknowledge.net:8080/thredds/fileServer/TERRACLIMATE_ALL/data/TerraClimate_ppt_2020.nc (+-103MB).

To do the conversion for each month, I use CDO to select the date. Below is the complete script:

for t in `cdo showdate TerraClimate_ppt_2020.nc`; do
   cdo seldate,$t TerraClimate_ppt_2020.nc dummy.nc
   gdal_translate -of GTiff -a_ullr -180 90 180 -90 -a_srs EPSG:4326 dummy.nc ../tif/TerraClimate_ppt_$t.tif
done

Unfortunately the result when I open to QGIS is upside down. Is there any configuration options from CDO or GDAL that I should use in above script to avoid the upside down result?

Below is the metadata from ncdump and gdalinfo, also result in qgis.

gdalinfo

ncdump

qgis

Best Answer

I think gdalmdimtranslate is a perfect use case for your problem (New in version 3.1).

Reposting what worked for you

gdalmdimtranslate -of GTiff -co COMPRESS=LZW -co PREDICTOR=1 dummy.nc ../TerraClimate_ppt_$t.tif
Related Question