[Qgis-developer] What is the API for opening and displaying HDF5 files through native python console in QGIS?

Thomas Gratier osgeo.mailinglist at gmail.com
Sun Jun 19 10:11:06 PDT 2016


Hi,

Just use the following


from qgis.core import QgsRasterLayer

layer = QgsRasterLayer(u"/your/path/your_hdf5_file")
if (len(layer.subLayers()) > 1):
    sub_layer = QgsRasterLayer(layer.subLayers()[1], 'sub layer') # Choose
arbitrarily the 2nd sub layer
    QgsMapLayerRegistry.instance().addMapLayer(sub_layer)

You can see more code about HDF5 at
https://github.com/qgis/QGIS/blob/master/python/plugins/processing/tools/dataobjects.py#L393

Cheers


Thomas Gratier

2016-06-13 17:05 GMT+02:00 Adrián Lugo Bendezú <
adrian.lugo.bendezu at gmail.com>:

> Hello,
>
> I would like to kindly ask for help opening a .h5 file, which is the
> extension for HDF5 file format, through the python console. Specifically I
> would like to open and display a dataset object (specific object type in
> HDF5) nested inside a group object (other specific object type in HDF5). I
> know that QGIS existing functionality allows HDF5 files to be opened and
> displayed through the GUI. When I use the Layer > Add Layer > Add Raster
> layer tool and open my desired HDF5 file, a window called “Select raster
> layers to add…” pops up listing all dataset objects inside my file that
> would ultimately open as raster files on QGIS. Selecting any of them
> effectively displays them in the map canvas. However, I would like to know
> the API for opening and displaying the HDF5 file dataset object through the
> native python console rather than the toolbar. I expect to be able to use
> the API to open and display any of the dataset objects within the HDF5 file
> and potentially provide proper CRS (Coordinate Reference System) for proper
> georeference. I am using QGIS 2.12.1 Lyon on Windows.
>
> Thanks,
>
>
> Adrián Lugo Bendezú
> Airborne Observation Platform Intern
> (NEON) National Ecological Observatory Network
> Office: 720.921.2726
> www.neonscience.org
> [image: cid:DFE8F099-73CA-444B-8146-6182E78AEFA4]
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160619/5dd740e5/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GetFileAttachment.png
Type: image/png
Size: 20892 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160619/5dd740e5/attachment-0001.png>


More information about the Qgis-developer mailing list