1.1.3. KML Symbolism

Information

Style elements can be associated with Placemarks to determine the symbolism applied to the geometry described by our termKML . We can associate images with Points in termKML . We can also vary hue, lightness, saturation, size and a number of other visual variables applied to the symbols associated with Placemarks.

The various geometries available in Placemark elements are associated with different styles, for example :

Style elements can be associated with individual Placemarks by adding them as children within the appropriate Placemark element.

Alternatively, Styles can be specified once and shared by a number of Placemark elements in one or more documents when referenced by a URL using the styleUrl element.

In this latter case Style elements must contain id attributes that uniquely identify the Style. These styles are then accessed through the styleUrl element with 'url/#id'

These possibilities provide plenty of scope for defining symbolism precisely in termKML for cartography and for sharing cartographic symbolism between termKML files and mashups.

Example

Here are sections of a termKML file containing information that Styles attributes of a point symbol (left) and a Polygon associated with a Placemark (right).

example #1

<Placemark>
<Style>
<IconStyle>
<color>#800080ff</color>
<size>1.5</size>
</IconStyle>
</Style>
<Point>
... etc ...
</Point>
</Placemark>

example #2

<Placemark>
<Style>
<PolyStyle>
<color>#800080ff</color>
<outline>1</outline>
</PolyStyle>
</Style>
<Polygon>
... etc ...
</Polygon>
</Placemark>

Note that color is specified with eight characters. These represent three hexadecimal values from 00 to ff using an RGB model and an additional hexadecimal level of opacity. The four hexadecimal values are ordered :

  1. opacity
  2. blue colour component
  3. green colour component
  4. red colour component

Also note that the Style element must be within the Placemark, but outside the definition of the geometry (e.g. Point or Polygon).



Example #3 shows a Placemark containing a Style that associates a color, a scale and a remotely referenced Icon with a Point element.

example #3

<Placemark>
<Style>
<IconStyle>
<Icon><href>http://www.gicentre.org/carto/icon/5am.png</href></Icon>
<color>#ff40a0ff</color>
<scale>0.80</scale>
</IconStyle>
</Style>
<Point>
<coordinates>-105.020,39.744</coordinates>
</Point>
</Placemark>

You can access icon files for each of the 24 hours of the day at the URL shown in this example. Simply change the file name from 5am to a different time, for example : 11am, 12am, 7pm, 10pm, etc.



Example #4 shows a termKML file containing a Style definition in which several Style statements are used to differentiate between five different colour schemes for Polygons. We can share Styles using style definition files such as this. The id attribute is used to distinguish between the Styles in a termKML document.

example #4

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">

<Document>
<name>YlOrBr5</name>
<Style id="k1"><PolyStyle><color>#e0e2feff</color></PolyStyle></Style>
<Style id="k2"><PolyStyle><color>#e0e1feff</color></PolyStyle></Style>
<Style id="k3"><PolyStyle><color>#e0dffeff</color></PolyStyle></Style>
<Style id="k4"><PolyStyle><color>#e0defdff</color></PolyStyle></Style>
<Style id="k5"><PolyStyle><color>#e0ddfdff</color></PolyStyle></Style>
</Document>
</kml>



When applying a Style from a shared source to an individual Placemark use the styleUrl element. This points to the termKML document containing the Style definitions and the id of the particular Style. Use the URL of the file (absolute or relative) and the full id of the required Style separated by a hash - #. Example #5 shows how this is achieved by making reference to the file shown in example #4 using its full URL.

example #5

<Placemark>
<styleUrl>
http://www.gicentre.org/carto/colorbrewer-YlOrBr5.kml#k1
</styleUrl>
<Polygon>
... etc ...
</Polygon>
</Placemark>

Exercise

The examples show how we can use Style elements to change the visual attributes of the geometric symbols that we specify in termKML .

See if you can edit your termKML to ...

  1. change the size and color of your Point symbols.
  2. change the color of your Polygon.
  3. add clockface icons to Point symbols with Icon and href
  4. colour the Polygon using each of the five shades described in the online style definition document using styleUrl

Notes

Remember, that colours are specified using hexadecimal values in the order opacity, blue, green, red in termKML .

Once again, remember to save your latest termKML efforts with a new filename when you are making these edits. Load or reload the termKML file in termGoogle Earth to view the results.

The example Style definition file containing shared Styles shown above is available online at :

Colours from Brewer's 5-class sequential YlOrBr scheme (Brewer 2002) are available as Styles with the following ids :

All 'ColorBrewer' (Brewer 2002) schemes are available as a series of 2,120 KML Styles in the following file :

The Styles can be referenced using the ColorBrewer scheme names followed by the number of classes, the letter 'k' and the class number. For example, class 7 from the 8 class PRGn scheme would be referenced with ...

The KML in 'colorbewer.kml' that produces this Style is as follows :

Diverging schemes are also available in reverse order by re-ordering the colours in the scheme title. For example, class 7 from the 8 class PRGn can also be referenced with ...

A list of all ColorBrewer schemes (Brewer 2002) documented as Styles in the 'colorbrewer.kml' KML file is available here :

The file contains ColorBrewer scheme names (Brewer 2002), colour definitions, colour swatches and termKML Style references.

Example KML Style for ColorBrewer colour scheme. Schemes available from http://www.gicentre.org/carto/colorbrewer.htmlExample KML Style for ColorBrewer colour scheme. Schemes available from http://www.gicentre.org/carto/colorbrewer.html