This example combines a simple raster and vector map to create a legend for a spatial object. The object is first loaded (line 15) and its colour table saved as a temporary file (line 22). A long thin raster, whose dimensions are determined in lines 8 and 9, is then created with continuous values that range from the object's minimum to maximum values (lines 25 and 30). By associating the spatial object's colour table with this new raster (line 67), the raster can be used to represent the colours as a colour bar.
A simple vector map is used to display the legend text. Each item of text is associated with a vector point (lines 35-40 and lines 55-60) with an attribute value containing the text to display (lines 41-45 and 61-65). Border spacing around the legend is created by adding some unlabeled points to the vector at the corner points (lines 35-36 and lines 55-56).
Finally, the labelling style is set (lines 75-78) and combined with the raster colour bar (line 81).
|
legend.png (direction set to 'vertical'):legend.png (direction set to 'horizontal'): |