HTML labels in Context

“HTML (Hyper Text Markup Language) are sets of markup symbols or codes which is used to define the contents of a webpage”

HTML can be used in QGIS for rendering complex labels and also adding functionality to the map composer. HTML enables QGIS to produce maps with complex labels and tables.
In this module, we will explore how HTML can be used to generate complex and beautiful labels in map composer.

You try:

Goal: To learn how to use HTML and functions to label map elements

Data: ne.sqlite
Layers: ne_10m_admin_1_states_provinces_shp, ne_10m_urban_areas

Check your results:

  • Load the layers and filter the admin layer using the filter. Substitute 'ZAF' with your country ISO code for a localised exercise.
  • Use the filtered admin layer to create layers that only intersect the admin layer. Name the new layer 'urban areas'.
  • Remove layers with the prefix ne except the admin layer.
  • Symbolize all the layers above.
  • Select admin layer and zoom to extent of Gauteng.
  • Go to composer and select Portrait
  • Add the label rule and render it as html.
  • Edit the label rule to show the second line of the label in blue. Hint use the red-font.
  • Add a grid using the given parameters.
  • Add map credits and use the map date function to show the year/month/date map was created.
  • Add all other map elements. Ie scale bar.

Name Expectation

Map date

now()

filter

"sr_adm0_a3" = 'ZAF'

Grid 1

vInterval unit. X and Y = 5, Interval units = cm

Label rule

[HTML_REMOVED]Map of South Africa Province[HTML_REMOVED][HTML_REMOVED] [HTML_REMOVED]The province is Gauteng [HTML_REMOVED]

red-font

[HTML_REMOVED]This is some text![HTML_REMOVED]

More about

QGIS has an advanced labelling engine which explores the data and allows users to define complex label rules. In some cases users wants to to generate labels which are independent of the data. Rendering labels as HTML allows for nice catrographic visualisation and adds more options to the QGIS labelling engine. One usefull scenario for rendering labels as HTML is when you want to create a composite label that countains a different types of text sizes,colours and typographical emphasis.

Check your knowledge:

  1. Which of the following statement is incorrect:
    1. When a user wants to create a table they can use HTML
    2. A logo can be inserted as an HTML when the image is fetched from the internet
    3. Layer labels can be converted into HTML labels in map composer.
  2. HTML labels cabe used when map layers contains rasters:
    1. True
    2. False