1.1.5. KML Visualization

Information

We have established that termKML provides plenty of scope for cartography, but need to consider the ways in which termGoogle Earth interprets the termKML and provides access to the features that we are mapping. Doing so allows us to take advantage of some of the interactive and dynamic capabilities of termGoogle Earth and generate termKML that is particularly appropriate for visualization.

The 'Places' window in termGoogle Earth is the key here. It allows us to select termKML files and importantly file sections from the termXML hierarchy. Two termKML elements are particularly significant in this context : Document and Folder.

These two elements act as 'containers' into which data may be structured. They can both be associated with name and description elements that provide labels for the containers in the 'Places' window. These are children of the Document and Folder elements and should be placed within them. Document and Folder elements can be arranged hierarchically and the 'Places' interface used to select branches of the hierarchical tree for display : any Placemark or other feature is only shown if all of its ancestors are selected.

These features allow us to organise our data in an hierarchical manner and select aspects of our data according to the hierarchy.

As well as selecting or toggling layers, we can use the animation controls in the 'Places' window to display layers in sequence. We can visually blend some layers, by selecting a layer in the 'Places' window and moving the slide bar that sets the transparency.

termGoogle Earth allows us to interactively select Placemarks or other features from the termKML files available for display according to time through the TimeStamp or TimeSpan elements. These can be placed within features, such as Placemarks. termGoogle Earth then allows us to select features according to particular periods or moments in time and to animate sequences.

Whilst the TimeStamp and TimeSpan elements are designed for encoding temporal information, they can be used to encode any ordered or periodic data if this is transformed into a series of arbitrary dates. We can thus use termGoogle Earth to interactively slice and select the data available as 'Places' as we engage in exploratory visual analysis.

So far, our termKML files and examples have been static and self-contained.

We can however make reference to external termKML files within our termKML documents. These are referenced by URLs and so we can serve elements into our termKML files from documents located anywhere on the Web.

The documents referenced by the URLs may be static or may change dynamically over time. In the latter case termKML files that we link to via the Internet may be generated periodically by a server or 'on the fly' whenever a request is made through a server-side scripting language such as termPHP . This gives us even more scope for generating data, maps and interactions to suit as we explore spatial data through visualization.

We include external links to termKML files on the Web through the NetworkLink element. Doing so will include termKML from an external source as referenced by the Url element in the NetworkLink.

When termGoogle Earth loads the termKML file it will replace the NetworkLink element with whatever is in the document referenced by the Url.

We can control certain conditions under which termGoogle Earth will check the server and re-load the URL specified in the NetworkLink by adding child elements within a Url.

It is useful to use server-side programming to extract information from a database according to a particular query at a particular time. Importantly, termGoogle Earth will add the bounding box of the currently selected view to the URL used by a NetworkLink when a request is made of a remote server. We can access this information through server side programming languages such as termPHP that connect to an online database and thus use the parts of the Url that describe the current bounding box as parameters in a database query.

These features of termGoogle Earth and termKML provide real scope for interactive visual exploration. We can :

Example

Here we will consider examples that show how the TimeStamp, NetworkLink and Document and Folder elements can be used in termKML for visualization.

Example #1 contains a section of a termKML file that defines a Placemark with a TimeStamp indicating that the Placemark exists on 28th October 2007.

example #1

<Placemark>
<name>current location</name>
<description>i am here!</description>
<TimeStamp>
<when>2008-10-20</when>
</TimeStamp>
<Point>
<coordinates>-83.0000,39.9700</coordinates>
</Point>
</Placemark>

The T symbol is used as a separator between date and time, which is in hourly notation and requires seconds as shown in example #2. Times in UTC should end with a Z.

example #2

...
<TimeStamp>
<when>2008-10-20T15:00:00</when>
</TimeStamp>
...

The section of a termKML file shown in example #3 contains a Folder, that in turn contains two Document elements. Each has an associated name and could include descriptions and other elements. Additional structural elements could be added within these Documents to build up a hierarchy for selecting particular aspects of the data in an hierarchical manner for visualization.

example #3

...
<Folder>
<name>example folder</name>
<Document>
<name>first document within a folder</name>
<!-- add elements here : e.g. NetworkLink -->
</Document>
<Document>
<name>second document within a folder</name>
<!-- add elements here : e.g. Placemarks -->
</Document>
</Folder>
...

In example #4 a NetworkLink is used to refer to a termKML on a remote server. It will load the data from the file 'shadedRelief.kml' into the termKML file in which the NetworkLink resides.

example #4

...
<NetworkLink>
<Url>
<href>http://www.gicentre.org/tutorials/gisGE/shadedRelief.kml</href>
</Url>
</NetworkLink>
...

The termKML file referenced by the href element of the Url in example #4 is shown below in example #5. It includes a 'GroundOverlay' - a termKML element that allows imagery to be draped on the surface of the Earth. The image is specified in the Icon element, and its bounding coordinates in the LatLonBox. The image used here was generated from the USGS National Elevation Dataset (NED) at 1" resolution (USGS 2008) using the termLandSerf GIS.

example #5

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<name>ground overlay example</name>
<GroundOverlay>
<name>shaded relief</name>
<description>
image showing shaded relief NE of Sacramento.
source : USGS National Elevation Dataset (NED) 1" resolution from seamless.usgs.gov
image produced using LandSerf GIS.
</description>
<LatLonBox>
<north>39.0419</north>
<south>38.632</south>
<east>-120.7295</east>
<west>-121.1819</west>
</LatLonBox>
<Icon>
<href>http://www.gicentre.org/tutorials/gisGE/shadedRelief.jpg</href>
</Icon>
</GroundOverlay>
</Document>
</kml>

Example #6 uses the Url of a NetworkLink to request a document containing a server-side script, rather than a static termKML file.

Note how the URL that is contained in the href element of the Url refers to a termPHP script rather than a termKML document. The termPHP script will generate a termKML document every time the URL is requested. In this case the script creates a single Placemark with a random location that changes on each request. The other elements within Url determine how and when the requests are made.

example #6

...
<NetworkLink>
<name>randomPoint.kml</name>
<Url>
<href>http://www.gicentre.org/tutorials/kmlGE/randomPoint.php</href>
<refreshMode>onInterval</refreshMode>
<refreshInterval>4</refreshInterval>
<viewRefreshMode>onStop</viewRefreshMode>
<viewRefreshTime>1</viewRefreshTime>
</Url>
</NetworkLink>
...

The refreshMode element is used to indicate that the NetworkLink should be updated at a particular interval. This is specified in the refreshInterval element.

The viewRefreshMode element is used to indicate that the NetworkLink should also be updated when the view is changed - when the user changes location in termGoogle Earth . The time delay between a change of location or view and the data being refreshed is specified in the viewRefreshTime element.

Exercise

Use the example code provided above to :

  1. add a TimeStamp to one or more of your Placemarks
    (copy and modify examples #1 and #2)
  2. add a NetworkLink to the 'shadedRelief.kml' file at :
    http://www.gicentre.org/tutorials/gisGE/shadedRelief.kml
    (copy and modify example #4)
  3. add a NetworkLink to the 'randomPoint.kml' file at :
    http://www.gicentre.org/tutorials/kmlGE/randomPoint.kml
    (copy and modify example #6)
    When the NetworkLink is working, experiment with :
    • refreshInterval
    • viewRefreshTime
  4. organise your Placemarks and NetworkLinks into Documents and Folders.
    (copy and build upon example #3)
  5. explore geographic information in termGoogle Earth with the final example described below.

This example uses the geographic information appended by termGoogle Earth to the Url in a NetworkLink to search an online database.

A termPHP script on the server processes this information about the bounding box of the current view and subsequently issues a database query. The query returns those geographic features within the specified view. The script then formats the results using the termKML elements that we have considered in this tutorial and returns this data to termGoogle Earth .

This termKML file contains three layers that retrieve data from the termFlickr database representing the 1000 most interesting photographs in the current view. Placemarks are used to display the data in termGoogle Earth and TimeStamps provide controls for visualization by encoding :

Use these examples to further explore the termFlickr database. Change your viewing position, and zoom in to areas of interest to interactively filter the data geographically. You will see more results and more detail as you use termGoogle Earth to explore the geography of this database of point georeferenced photographs. Select each of the three layers in turn and use the time line to consider the three alternative ordered sequences : date; time of day; interestingness.

'Interesting' Flickr photograph times and locations can be explored through the Google Earth timeline in exercise 5.'Interesting' Flickr photograph times and locations can be explored through the Google Earth timeline in exercise 5.