[GIS] Overriding georeferenced bounds when generating Tiff in Gdal for Python

extentsgdalgdal-translatepython

I need to convert an "Aura OMI NO2 Data Product" in .he5 format to a Tiff.

Using Python, I achieve the conversion with the following code:

trans = "gdal_translate -of GTiff -sds -a_srs WGS84 -a_ullr -180 90 180 -90" + " " + input_file + " " + output_file"
os.system(trans)

I am trying to write this command within Python, but have not found how to override the georeferenced bounds as the GDAL command -a_ullr ulx uly lrx lry does.

The code I have is the following:

# Import gdal and osr
import gdal
import osr

# Open he5 file
src_ds = gdal.Open(input_file)

# Get the 4th subdataset and open it
subdatasets = src_ds.GetSubDatasets()
mysds = subdatasets[3][0]
sub_ds = gdal.Open(mysds)

# Set Projection
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
sub_ds.SetProjection(srs.ExportToWkt())

# Convert to Tiff
format = "GTiff"
driver = gdal.GetDriverByName( format )
dst_ds = driver.CreateCopy( destination_tif, sub_ds, 0 )

# Clean up
dst_ds = None
src_ds = None
sub_ds = None

I need to set the bounds of the generated raster, as it doesn't match up correctly. In the following picture, the top raster was generated with my imbedded Python code, whereas the bottom was created with the GDAL_translatePicture.

Furthermore, is it better practise to assign the Projection and Bounds to the subdataset or to the Tiff once it has been generated?

Best Answer

Using GDAL 2.1, the following command reproduces the gdal_translate code:

gdal.Translate(dst_f, ssub_ds, format = 'GTiff',
               outputSRS = 'EPSG:4326', outputBounds = [ -180, 90, 180, -90])