You have a least a few ways to do it:
- GDAL command line utilities:
Since version 2.1 GDAL working fine (read and write) with raster and vector netCDF files. You can use both GDAL command line utilities (gdal_translate and gdalwarp) to reproject and output to GeoTiff format file.
gdal_translate -of GTiff -ot Float32 -a_srs "+proj=longlat +ellps=WGS84" input.nc output.tif
- Execute GDAL utility from Python scripts:
Here is some example:
import subprocess
def convert_netcdf_to_geotiff(infile, outfile, band_number=1, verbose=False):
with open(os.devnull, 'w') as devnull:
return subprocess.check_call([
"gdal_translate", infile, outfile,
"-of", "GTiff",
"-ot", "Float32",
"-a_srs", "+proj=longlat +ellps=WGS84",
"-b", str(band_number)
],
stdout=None if verbose else devnull
)
- Also, you can use GDAL utility in Docker container
If you don't want or can't install/build GDAL on your machine you can use prepared Docker images with GDAL 2.1 version or other versions with support netCDF driver.
There is one of the solutions:
cd /path/to/dir/with/netCDF/file
docker run -v $(pwd):/data geodata/gdal gdal_translate -of GTiff -ot Float32 -a_srs "+proj=longlat +ellps=WGS84" input.nc output.tif