Creating a layer style 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) in the XML format.
Getting ready
You will need to download the zipped directory named saveqml
and decompress it to your qgis_data/rasters
directory from https://geospatialpython.googlecode.com/svn/saveqml.zip.
How to do it...
We will create a color ramp for a DEM and make it semi transparent to overlay a hillshaded tiff of the DEM. We'll save the style we create to a QML file. To do this, we need to perform the following steps:
- First, we'll need the following Python Qt libraries:
from PyQt4.QtCore import * from PyQt4.QtGui import *
- Next, we'll load our two raster layers:
hs = QgsRasterLayer("/qgis_data/saveqml/hillshade.tif", "Hillshade") dem = QgsRasterLayer("/qgis_data/saveqml/dem.asc", "DEM")
- Next, we'll perform...