1.1.2. KML Geometry

Information

So what is termKML and how does it work?

Google (Google Inc. 2008) describe termKML as ...

"an XML grammar and file format for modeling and storing geographic features such as points, lines, images, and polygons for display in Google Earth"

... and use the spatial browser metaphor quite nicely when stating that ...

"A KML file is processed by Google Earth in a similar way that HTML and XML files are processed by web browsers.
Like HTML, KML has a tag-based structure with names and attributes used for specific display purposes.
Thus, Google Earth acts as a browser of KML files." (Google Inc. 2008)

termKML can be used to :

We will see how to do some of these things and how they enable us to produce cartography and support visualization in this short introduction to termKML .

We will do so by looking at some simple termKML examples. Each example contains three sections ...

In each case you should ...

  1. read the information section
  2. copy the examples and paste them into a text editor
  3. make changes as suggested and save the files in your workspace with a '.kml' extension
  4. open the termKML files in termGoogle Earth .
IMPORTANT : We recommend viewing termKML in an termadvanced text editor .
You should use a new file and unique filename to save and edit each of the examples in this introduction.

As it is an termXML language termKML consists of data (text, numbers and other characters) marked up, or surrounded by, elements that describe the text.

Elements are distinguished from text that they surround as they are enclosed by < and > symbols. Within these symbols are the element name and any attributes associated with the element. Attributes have values contained in "double quote marks". Elements begin with <elementName> and end with </elementName>. Any text between these opening and closing elements can be considered as being 'marked-up' with or 'tagged' by the element and its attributes.
Elements can be arranged hierarchically. An element that is within another element is said to be a 'child' of the enclosing 'parent' element. Child elements inherit the properties of their parents.
Elements that are used to specify attributes but that do not mark up textual content and do not contain children can be specified with a single tag, closing with /> - for example : <elementName attribute="value"/>.

As is the case with all termXML languages, termKML files must be both :

The Placemark element is the basis of termKML visualization and cartography. A termKML file can contain any number of Placemark elements. These contain children that allow us to specify coordinates and symbolise using points, lines and areas :

Example

Here is a simple termKML file that contains elements and attributes. It is both termwell-formed and termvalid and contains a single Placemark.

Do try to get a feel for the basic structure of termKML with the opening and closing elements and associated attributes and the hierarchical relationships between elements.

example #1

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<name>example kml document</name>
<Placemark>
<name>a simple placemark</name>
<description>a description</description>
<Point>
<coordinates>-105.020,39.744</coordinates>
</Point>
</Placemark>
</Document>
</kml>

The example file consists of an opening line that indicates that this is an termXML file. Then we have a kml element that points to the document in which the termKML language is defined. This root element encloses all other termKML elements. Within this is a Document element - these are used to structure the termKML . In our Document is a single Placemark, which is the element that describes a symbol or geographic feature. This element contains three others :

This hierarchical arrangement of elements with attributes is typical of termKML . All elements within the Placemark are associated with the Placemark.

Here is another simple termKML file, that contains some additional elements, that is both termwell-formed and termvalid .

example #2

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Placemark>
<name>Mile High Stadium</name>
<description>(INVESCO Field) home of the Denver Broncos</description>
<Point>
<coordinates>-105.020,39.744</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Colorado</name>
<description>state outline - polygon</description>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-109.051,40.998 -108.378,40.998 -107.003,41.004
-106.318,40.998 -104.051,41.004 -102.052,41.004
-102.046,40.002 -102.041,36.995 -102.999,37.000
-104.330,36.995 -105.875,36.995 -106.872,36.995
-106.877,37.000 -107.967,36.995 -109.046,37.000
-109.040,38.161 -109.062,38.276 -109.051,38.999
-109.051,40.998
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>

Elements to consider in this example include :

Exercise

To see how we can create and edit termKML , try the following ...

  1. open a new text file in your termtext editor
  2. copy the text from the 'example #1' above into the new file
    (use your mouse to highlight the text in the Web page. In Windows use CTRL and C to copy and CTRL and V to paste the text into your termtext editor )
  3. save the file in your termtext editor with a '.kml' extension
  4. open the termKML file in termGoogle Earth to view the results

You can make additions and changes to the file, save your edits and then reload the termKML file in termGoogle Earth .

So, why not edit the code to see whether you can ...

  1. add some Point symbols that identify interesting features :
    • your current location
    • your home location
  2. use the name and description features to add labels
  3. edit some of the coordinates to change the outline described in the Polygon

Notes

You can see coordinates at the bottom of the screen as you move the cursor around in termGoogle Earth . The coordinates used in these exercises are given in decimal degrees. Click Tools and Options to select 'Degrees' or 'Decimal' rather than 'Degrees, Minutes, Seconds' to change the way in which coordinates are displayed in termGoogle Earth .

Remember to make your edits, save the changes and then reload the termKML file in termGoogle Earth to view the results.

NOTE : this is a very rudimentary introduction and you are encouraged to experiment with the various tutorials and copious documentation and impressive examples that are available online :

Many more elements and attributes and relationships between them are described in this documentation.