Creating a layer-definition file
Layer styling is one of the most complex aspects of the QGIS Python API. Once you've developed the style for a layer, it is often useful to save the styling to the QGIS Markup Language (QML) XML format.
Getting ready
You will need to download the following zipped directory, named saveqml
, and decompress it to your qgis_data/rasters
directory:
https://github.com/GeospatialPython/Learn/raw/master/saveqml.zip
How to do it...
We will create a color ramp for a digital elevation model (DEM) and then make it semi-transparent for overlay on a hillshaded tiff of the DEM. We'll save the style we create to a QML file:
First, we'll need the Python Qt libraries:
from PyQt4.QtCore import * from PyQt4.QtGui import *
Next, we'll load up our two raster layers:
hs = QgsRasterLayer("/qgis_data/saveqml/hillshade.tif", "Hillshade") dem = QgsRasterLayer("/qgis_data/saveqml/dem.asc", "DEM")
Then...