GeoProc.com
GeoProc.com

bcCBar3: Colour Scalebar for One-Band Rasters    bcCBar logo
V3.5 - 11 September 2020

This QGIS Processing algorithm creates a colour scalebar image file (svg and, optionally, png*) for a coloured 1-band raster. Use the created colour scalebar as legend in print composer.

Distributed under the GPL licence
 

This algorithm works only on QGIS version 3.x.
It is NOT backward compatible with old .qml formats generated with QGIS versions ≤ 2.99

This algorithm is part of the Processing geoprocAlgos plugin. Once installed the geoprocAlgos plugin can be found in the 'Processing toolbox'.

 

Please report any bug/problem/wish on GitHub or, not recommended, to the QGIS User mailing list [mailto: qgis - user at lists dot osgeo dot org].


Contents


 

Installation

Be aware that this algorithm requires extra pyton modules (numpy, matplotlib, pillow, beautifulsoup & lxml).

numpy & matplotlib should be installed with your QGIS installation, but pillow, beautifulsoup & lxml could require manual installation. They can be "pip install" from the QGIS command line (pip install pillow for pillow, pip install bs4 for beautifulsoup & pip install lxml for lxml).

For Windows users, another option is to install from 'wheels' from Christoph Gohlke's very resourceful site.

Minimum modules version required to run this algorithm:

See here for installation instruction.

Once successfully installed the algorithm is found in the Processing toolbox under GeoProc -> composer -> Create Colour Scalebar:

geoprocAlgos in Processing

Double-click "Create Colour Scalebar" to launch the configuration window:

 

Anatomy of a colour scalebar

A colour scalebar is made of the following elements:

Anatomy of a colour scalebar

Each element can be customised through optional parameters.

 

Parameters

Many options are available to customise the generated colour scalebar! But they are all optional and a default value is provided. Note that those default values are not optimum at all and fine tuning will be necessary...

The only required parameter is a 1-band raster in input, which has already been styled. If you select a raster layer in QGIS legend before running this algorithm then it is automatically set as input. The raster must be a styled one-band raster otherwise the algorithm will fail.

By default the algorithm produces a vertical colour scalebar with ticks and labels for each value of the raster colours located on the right side of the scalebar.

Main parameters

Most used parameters: (see figure above)
Input one-band raster
The currently selected raster layer in the QGIS legend. Or select another raster layer present in the QGIS legend. Selecting a raster from a file is not supported unless it has an associated qml sidecar (i.e. a file with the exact same name as the raster but with extension .qml in the same directory as the raster).
Scalebar orientation
"vertical"* or "horizontal"
Title
A title for the colour scalebar. Use ΓΏ (ASCII 255) as a multiline marker. E.g.: SRTM tile NW234
Sub-title
Sub-title of the colour scalebar (single line). Generally units of the raster. E.g. Elevation (m)
Number of decimals to display
Number of decimals to display for the tick labels (default: 2). E.g. 125.00
Tick separation
Every 'ticksep' is shown (default: 1 [≥ 1]). E.g. if set to 5, every 5 colour labels will be shown.
Advanced parameters: (see figure below)

Advanced parameters

Ratio width/length
Ratio of the width of the colour scalebar relative to its full length (default: 0.1 [10%])
Number offset
A relative offset to arrive at nice numbers for ticks labelling (default: 0. [-100., 100.]).
E.g. original ticks position at are 134 154 174... With an -4 offset the ticks will be located and labelled at 130 150 170...
Alternate ticks on both axis?
Do the tick labels alternate between the two axis? False*. If True the "Label both sides" setting is ignored. Check this setting to declutter the labels if they overlap each other. This is an alternative to increasing 'Tick separation' and/or decreasing font size.
Alternate labels on both sides of the colour scalebar
Label both sides
Do you want label both sides of the colour scalebar or not? False* (only one side or none, see below)
Ticks side
Or, on which side of the colour scalebar the ticks will be located: 'none', 'both', 'top', 'bottom'*, 'right'*, 'left'. Valid values depend on the orientation of the colour scalebar.
Font sizes
Ticks label font size relative to plot area. The font size is relative and not in current units (pt or px). Default 4, [0.2, 10.]
Title font size relative to ticks label font size, i.e. an offset relative to the ticks label font size. Default +2 [-10.,10.]
Sub-title font size relative to ticks label font size, i.e. an offset relative to the ticks label font size. Default +1 [-10.,10.]
Line widths
Colour scalebar frame line width. Default 1.0 [0.0, 5.0]
Dividers line width, between colours. Default 0.0 [0., 2.5]
Colours
Title colour: a valid colour name or a (r,g,b,a) list of numers between [0., 1.]. ('black'*). E.g. [0.,1.,0.,1.] for green
Sub-title colour: a valid colour name or a (r,g,b,a) list of numers between [0., 1.]. ('black'*). E.g. (1., .5, .5, 1.) for light red
Frame colour: a valid colour name or a (r,g,b,a) list of numers between [0., 1.]. ('black'*). E.g. 'red'
Divider colour: a valid colour name or a (r,g,b,a) list of numers between [0., 1.]. ('black'*). E.g. 'blue'
Other options
The scalebar can be reversed. False*
A png (see note) file can be created in addition to the svg file. False*
Additional parameters
It is also possible to more completely define the fonts used for title, sub-title and label using a python dictionary structure. See the section Extra parameters below for details.

 

Ouptut
The name of the svg file representing the generated colour scalebar. The base name (without extension) will be used to generate a filename for the report and for the optional png file. If left empty (default) the name will be random and the files will be located in your Processing temp directory.

* is the default value for that parameter

Extra parameters

Those parameters are formatted as a python dictionary, so the general format is
 {'Parameter_name':value, 'parameter_name':value, ...}

Parameter_name can be any of:

Note that alignments of title and sub-title are made relative to the colour scalebar frame. The ticks label widths are not taken into consideration! It is then best to use those parmeters only for horizontal scalebars.

* is the default value for that parameter

 

The font dictionary can have the following keys: 'family' and 'size'. Note that the values ('style', 'variant', 'stretch' and 'weight') cannot be set in Matplotlib with a font name defined in the font dictionary.

Accepted values for each key are:

Examples

 

Results

On completion, a svg file, a report file (html) and optionally a png file are created. If all is ok a screen similar to the one below is shown:

Processing results

and the report is available in Processing results pane:
Procesisng Results Viewer
Click on the "File path" link to open the report. This report shows the generated colour scalebar(s) as well as the location of the generated file(s) and a list of the parameters used. A standard suffix is added to the name of the file (e.g. _H12Tt. See below for an explanation). See example report here.

 

To import the colour scalebar into QGIS Composer do as follows:

Standard suffix

This is a 7 character string appended to the name of the colour scalebar and the meaning of each character is as follows:

Notes

 

Change log

 

Published date: 12 Jun 2019.