2

Im am trying to convert a radar file provided in HDF5 to a GeoTIFF using gdal.Translate() in my Python script.

An example of the HDF5 file can be downloaded here

I have already managed to get it working using the commandline and gdal_translate which gives me the expected result:

import os
os.system('gdal_translate -of GTiff \
-a_srs "+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378140 +b=6356750 +x_0=0 y_0=0" \
-a_ullr 0.0 -3649999.1798970395 700000.9100000001 -4415003.157897039 \
"HDF5:\"RAD_NL25_PCP_NA_201910281110.h5\"://image1/image_data" \
"test-translate.tif"')

enter image description here

However, when I try to do the same using library function gdal.Translate() inside my script I get an error.

My code:

from osgeo import gdal

kwargs = {
    'format': 'GTiff',
    'projWinSRS' : '+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378140 +b=6356750 +x_0=0 y_0=0',
    'projWin' : [0.0, -3649999.1798970395, 700000.9100000001, -4415003.157897039]
}

fn = 'HDF5:\"RAD_NL25_PCP_NA_202101080825.h5\"://image1/image_data'
dst_fn = 'output.tif'

ds = gdal.Translate(dst_fn, fn, **kwargs)
ds = None

Gives me the following errors:

ERROR 0: -projwin_srs ignored since the dataset has no projection.
ERROR 1: Error: Computed -srcwin 0 -3.65e+06 700001 -765004 has negative width and/or height.

Am I doing something wrong?

2
  • Translate need two CRS information, hence, I'm not 100% sure it's able to figure out the one of your input dataset based on the error message. This may help: gis.stackexchange.com/a/226519/65370 Jan 19 at 21:34
  • I found the issue, it is not that Translate needs two CRS informations, as in the commanline code it works fine with just one output CRS. The problem however is that I should use 'outputSRS' and 'outputBounds' instead of 'projWinSRS' and 'ProjWin'... Thanks for pointing me in the right direction @s.k!
    – sam_cocha
    Jan 20 at 14:50
1

Found the answer to this question!

Instead of using the 'projWinSRS' and 'projWin' options in gdal.Translateoptions you have to use 'outputSRS' and 'outputBounds' respectively.

This the new code that works well for me:

from osgeo import gdal

kwargs = {
    'format': 'GTiff',
    'outputSRS' : '+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378140 +b=6356750 +x_0=0 y_0=0',
    'outputBounds' : [0.0, -3649999.1798970395, 700000.9100000001, -4415003.157897039]
}

fn = 'HDF5:\"RAD_NL25_PCP_NA_202101080825.h5\"://image1/image_data'
dst_fn = 'output.tif'

ds = gdal.Translate(dst_fn, fn, **kwargs)
ds = None

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.