5- Loading raster files

To load raster files in QGIS, the GDAL library is commonly used. In order to follow along with the examples in this tutorial, you will need to first download the data we will be working with from the following link: data.

Next, you will need to get the path of the downloaded raster file. For example:

uri = "D:/Python_QGIS/data/dem_subset.tif"

To load the raster file into QGIS using PyQGIS, use the following code in the Python console:

layer1 = iface.addRasterLayer(uri, "my_raster", "gdal")

In summary, this article explains how to use PyQGIS to load raster files into QGIS using the GDAL library. It provides step-by-step instructions on how to add a layer to QGIS, and includes a link to download the data used in the example code.

If you like the content, please SUBSCRIBE to my channel for the future content