9

I have .nc file sizing around 300MB with a couple of datasets (TEMP, DEWPOINT) forecast data. I need to convert (TEMP) dataset to multiple GEOTIFF (one .tif for each time slice).

Here is how the .nc file looks like.

enter image description here

Looked into this answer but it seems to be for the whole dataset.

I tried GDAL but not sure how to make it work for each time slice.

Any thoughts? netcdf4-python?

Dadep
  • 2,796
  • 5
  • 27
  • 40
johnny
  • 2,032
  • 1
  • 25
  • 45
  • 1
    Did you try to use `gdal_translate` from GDAL? `gdal_translate -of GTiff file.nc test.tiff` – AF7 Aug 28 '18 at 07:13
  • I did and works for the whole dataset, not one-time slice. Is there any option with gdal-tranlsate to add a time slice as an argument? – johnny Aug 28 '18 at 15:45
  • 1
    Sorry, I do not know that. But I'm sure you can easily write a script to separate the file into multiple time slices (e.g. with CDO or NCO), then translate them all separately. – AF7 Sep 06 '18 at 12:51
  • 1
    use gdal_translate -a_srs EPSG:4326 NETCDF:File_Name.nc:Band_Name -of ‘Gtiff’ Output_FileName.geotiff . band name can be obtain using gdalinfo command – Bharti Mohane Sep 12 '18 at 08:33

1 Answers1

16

gdal has a gdal_translate option that will allow you to do this to translate the file from .nc to .tiff.

See below:

gdal_translate -of GTiff file.nc test.tiff

and using the -b option will allow you to specify which band you want to convert.

gdal_translate -of GTiff -b 10 file.nc test.tiff  # to get 10th band

From the docs:

-b band: Select an input band band for output. Bands are numbered from 1. Multiple -b switches may be used to select a set of input bands to write to the output file, or to reorder bands. Starting with GDAL 1.8.0, band can also be set to "mask,1" (or just "mask") to mean the mask band of the first band of the input dataset.

Unfortunately, you will have to know which band you want (in numerical form as opposed it's date/time form), but a simple script can be used to iterate over the time dimension and obtain the index you need or simply iterate through each band one-by-one.

tda
  • 2,045
  • 1
  • 17
  • 42
  • Yeah. That is correct. You answered a bit late but I am using what exactly you suggest. So basically my data is forecast for next 100 hours and it is in order too. So I if want to get first 10 hours, that band (1-10). Also in my case the band is not a big deal too, even if the hours were not in order, I could still fix them when processing them to goeserver – johnny Sep 12 '18 at 14:21
  • 4
    Apologies for lateness haha - stumbled across when trying to search for something similar myself and thought I'd help out to reduce the number of unanswered questions! – tda Sep 13 '18 at 07:25