gdal_translate -a_srs EPSG:4326 NETCDF:"file_name.nc":variable_name output_file_name.tif -a_ullr -9.21200 53.28058 -8.88045 53.11338
I am working on some NetCDF files that include multiple variables. The goal is to transform them into GeoTIFF files and georeference them given known x,y-coordinates and if possible apply this process for all the variables included in the file at once. The abovementioned command has successfully transformed the NetCDF file variable into a GeoTIFF file, but I want to execute this inside a Python script.
The code I used is here:
transform = gdal.Translate(outname,ds_read,format = 'Gtiff', outputSRS = 'EPSG:4326',outputBounds = [-9.21200, 53.28058, -8.88045, 53.11338] )
The problems I am facing are the following:
When running the code, without specifying a band I get the following Traceback :
Warning 1: Recode from UTF-8 to CP_ACP failed with the error: "Invalid argument".
ERROR 1: Band 1 requested, but only bands 1 to 0 available.
I tried to change the code a bit to test if the variables are interpreted as bands and I added the argument : bandList = 1 inside the gdal_translate fuction. After that, I got the same traceback call as before.
When using the gdal_translate function with the arguments mentioned here : https://gdal.org/python/osgeo.gdal-module.html#Translate , I do not know how to specify a variable (or all variables) of the NetCDF file inside the function. I also tried (unsuccessfully) to parse all the arguments using :
input_format = '-if NETCDF'
output_format = ' -of GTiff'
projection = '-a_srs EPSG:4326 '
translateOptionText = projection + input_format + output_format + ' -a_ullr' + str(-9.21200) + '' + str(53.28058) + '' + str(-8.88045) + '' + str(53.11338)
translateOptions = gdal.TranslateOptions(gdal.ParseCommandLine(translateOptionText))
gdal.Translate(outname,new_name, options = translateOptions)
Any advice or idea?
gdalinfo filename.nc
?