GeoProc.com
GeoProc.com

ImageLegend_widget: A QGIS layer tree (Legend) widget for displaying image legend in a raster layer   ImageLegend logo
V1.4 - 24 November 2019

This QGIS layer tree widget adds an "Image Legend" entry into the Legend tab of a raster layer properties.

Distributed under the GPL licence
 

This widget works only on QGIS version ≥ 3.4.

 

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 widget requires an extra pyton module: pillow.

pillow could require manual installation and can be "pip install" from QGIS command line (pip install pillow).

Minimum module version required to use this widget:

Follow instructions here to install this widget.

Then enable it in Plugin Manager. Its name is: Layer Tree Image Legend Widget

Once successfully installed the widget is found in Properties -> Legend -> Embedded widgets in legend -> Available widgets.
For raster layers only!

 

Preparing the image legend

In order to work correctly this widget requires a specific sidecar file (specially named file) for the selected raster. Two cases are dealt with: 1) one legend sidecar file per raster or 2) a common legend file for all rasters in the directory that do not have their own legend sidecar file.

Case 1 - One legend sidecar file per raster file:

Case 2 - Common legend for rasters in folder:

Example

Let's say we want to georeference a map. That map is probably an image showing map content and a legend associated with it. Would it be nice to georeference the map content only and have the legend as a separate item displayed in the layer tree?

Well, this is now possible and to do it we need to prepare our map/legend pair.

  1. Open the image file (e.g. my_map.jpg) of the map with legend in an image editor
    my_map
  2. Save a copy of the file as a png (or jpg, from version 1.2) file named as follows: my_map.legend.png where my_map is the same name as the original file, without extension, and .legend.png (or .legend.jpg) must be like that (this is a sidecar to the original image. This convention is necessary on order for the widget to find the legend from the raster name)
  3. In the image editor, crop the image to only show the legend, and save. Close the image
    my_map.legend.png
  4. Re-open the original image file and crop the image to only show the map. Save and close
    my_map.png
  5. In QGIS, georeference the map
  6. Then load the georeferenced image into the layer tree

 

How to use

Map taken from pinterest


Download zip file here for manual installation.


 

Change log

Many thanks to Nyall Dawson at North Road for creating toggle_labels_widget on which this widget is based!

 

Published date: 25 Aug 2019.