How to open HDF files on Sinusoidal Coordinate System in QGIS3 with PyQGIS - Tutorial


For a normal GIS user, QGIS 3 brings a lot of new tools, new forms to perform spatial analysis but also it doesn´t bring (yet) some options available in QGIS 2. This is the case for the representation of HDF raster files that is not available in QGIS 3 but it is available in QGIS 2. Research have been performed to address this issue and many options were evaluated to open the HDF files and perform a geotransformation from Sinusoidal Coordinate System to Geographical Coordinate System.

The solution came from the powerful gdal library and some core Python functions. This tutorial show the procedure to open a layer of a MOD13A2, a MODIS data product for vegetation evaluation and reproject it to geographical coordinate system (lat/lon).


Python code

This is the Python code that open the HDF file, reproject one layer to WGS84 and bring it to canvas.

import gdal, os

## List input raster files
rasterFiles = os.listdir(os.getcwd())

## Open HDF file
hdflayer = gdal.Open(rasterFiles[0], gdal.GA_ReadOnly)

# Open raster layer
rlayer = gdal.Open(hdflayer.GetSubDatasets()[0][0], gdal.GA_ReadOnly)

# Define output raster and warp-reproject
outputName = rlayer.GetMetadata_Dict()['LOCALGRANULEID'][:-4]+'_NDVI.tiff'
outputRaster = '..\\outputRaster\\'+ outputName

# Add output raster to canvas
iface.addRasterLayer(outputRaster, outputName)




Input files

You can download the input files for this tutorial here.



Website of NADA Earthdata Search to download MOD13A2 files:

More information on the MOD13A2 vegetation data product:

Saul Montoya

Saul Montoya es Ingeniero Civil graduado de la Pontificia Universidad Católica del Perú en Lima con estudios de postgrado en Manejo e Ingeniería de Recursos Hídricos (Programa WAREM) de la Universidad de Stuttgart con mención en Ingeniería de Aguas Subterráneas y Hidroinformática.

Smiley face

Subscribe to our free e-newsletter for tutorials, articles, webminars, courses and more.