How do I convert a GeoTIFF into a NetCDF file?
We recommend using the Geospatial Data Abstraction Library (GDAL) to convert GeoTIFF files into a different format. If you want to reproject to lat/lon as well, then we recommend reprojecting before converting to NetCDF (see the FAQ "How do I reproject a GeoTIFF to from polar steroegraphic to geographic lat/lon?"). Here, we outline command line and python options for using GDAL to convert GeoTIFF files into NetCDF format.
GDAL in the command line
- You will need to have GDAL already installed. If you need to install it, then further details can be found at https://gdal.org.
- Open a terminal/command prompt and navigate to the folder where the file that you want to convert is.
- Run the following command in the command line:
gdal_translate -of NetCDF <input filename> <output filename>
For example, if you wanted to convert 'Greenland_vel_moasic_250_vy_v1.tif to a netCDF file:
gdal_translate -of NetCDF Greenland_vel_mosaic_250_vy_v1.tif Greenland_vel_mosaic_250_vy_v1.nc
GDAL in python
- You will need the GDAL package installed in your python environment.
- The following code can be used to convert a geoTIFF to a netCDF file:
from osgeo import gdal
#Change the following variables to the file you want to convert (inputfile) and
#what you want to name your output file (outputfile).
inputfile = 'Greenland_vel_mosaic_250_vy_v1.tif'
outputfile = 'Greenland_vel_mosaic_250_vy_v1.nc'
#Do not change this line, the following command will convert the geoTIFF to a netCDF
ds = gdal.Translate(outputfile, inputfile, format='NetCDF')