Introduction to Google Earth

Video presentation for this talk is available <here> (Duke login required)

Introduction

Chances are that you have played around with Google Earth. It’s an amazing bit of technology and has a knack to draw you in to explore features across the globe that you would otherwise never discover. It is a powerful visualization and communication tool that easily leaps language barriers and engages people of all walks of life.

In this tutorial we will explore what’s behind Google Earth and actually learn what it takes to put our own features into Google Earth. Don’t expect to come out of this short tutorial as an expert Google Earth developer as there’s much to learn beyond what we cover here. Rather, think of this as a guide on how to sit down and begin learning a new technology. Google has some great documentation and useful tools for teaching yourself its technologies. You may be surprised how simple [some of] this stuff really is.

Some Examples: What is Google Earth capable of?

Let’s begin by taking a look at a few examples that Google provides:

Plenty of other “extreme” Google Earth applications can be found here:

After the glitz of these examples has passed, take a more analytical look at what’s shown in them. Many objects shown on the maps are placemarks that link content (text, photos, graphics, shockwave animation, etc.) to a point location. The example of the ascent of Half Dome (http://services.google.com/earth/kmz/everytrail_yosemite_n.kmz) and the USGS quake map (http://services.google.com/earth/kmz/realtime_earthquakes_n.kmz) also show polylines. The USGS map of watersheds (http://edna.usgs.gov/watersheds/sheds/USWatersheds/USWatersheds.kml) shows watershed boundaries – an example of polygons. We also can (and will) drape image overlays on top of Google Earth’s terrain. So, much of Google Earth’s magic is boiled down to: points, lines, polygons, and raster (image) datasets – this is all somewhat familiar to us and so we should have a distinct advantage over the common pleb yearning to learn how to make maps in Google Earth.

That said, however, there are some additional capabilities of Google Earth that we may not be so familiar with. First, polygons in Google Earth (and in ArcGIS too) can be extruded to give them a 3rd dimension. This is shown in the London example (http://services.google.com/earth/kmz/city_london_timeline_n.kmz). The London example also shows the addition of a 4th dimension – time. So there’s actually quite a bit that Google Earth can do – more than what we can learn in a few classes.

An overview of Google Earth & KML

So how are all these spatial features created and added to Google Earth? It’s all quite similar to shapefiles in ArcGIS, but with some notable exceptions.

Nearly all vector-based features, whether they’re points, line, polygons, or 3d shapes, are stored in KML documents. KML is, like HTML or XML, a markup language (its name is short for Keyhole Markup Language), and so it’s comprised of a series of data elements and attribute tags. Google Earth interprets these tags and uses the data elements to construct geometric shapes. We’ll take a look at some examples shortly.

Image/raster based features are stored in their native formats (GIF, TIF, jpg, etc.) and KML is written to link to these files and place them where they should be.

What’s unique about KML files relative to shapefiles is that they are entirely open. You can view and edit them in any text editor (if they’re not encrypted). KML files can point to other files on remote servers, vastly expanding the library of objects that can be displayed on your map and also enabling live maps via linking to updating sites.

In a sense, Google Earth is similar to ArcGIS except that its canvas is not a static ArcMap document but rather a dynamic web-based platform – a sort of 3-dimensional web page where hyperlinks are located via geography!

But enough pontificating about how interesting a concept Google Earth really is; let’s get to learning it…

Learning KML

We can’t possibly learn all there is to know about Google Earth in one lab session, so we’ll learn just enough to get us past the initial hurdles. We’ll start simple by creating a few objects in a KML file, view them in Google Earth and experiment with the syntax of the language.

For this we’ll essentially be following Google’s own documentation on how to teach yourself KML, found at:
http://developers.google.com/kml/documentation/kml_tut .

When you get there, click on the KML SamplesInEarth link (https://developers.google.com/kml/documentation/KML_Samples.kml). This opens a set of examples in Google Earth.

For the remainder of this tutorial we will examine the basic building blocks of KML. Below is an outline of what we hope to cover. Our approach to learning this will be to explore KML in both text form and in Google Earth, changing things in the text and seeing how the changes affect how the data are displayed.

A few general tips:

  • KML files are simply text files. You can right click on layers in Google Earth and select “Save Place As…” to save the KML file to your computer. Then you can open the file up in any text editor. A KMZ file is simply a compressed KML file. If you open a KMZ file using WinZip or 7zip, you can extract the KML file within it.
  • Google provides a nice playground for playing with KML objects in it Interactive Sampler interface:
    http://kml-samples.googlecode.com/svn/trunk/interactive/index.html

Google Objects

Run through the examples provided by Google Earth and make a note of the KML syntax used to create each of these objects and how the various implementations are created within a KML document.

  1. Placemarks
    • Simple
    • Floating
    • Extruded
  2. Descriptive HTML in Placemarks
    • Highlighted icons
    • Descriptive HTML
  3. Ground overlays
  4. Screen overlays
    • Simple crosshairs
    • Absolute positioning
    • Dynamic positioning
  5. Paths
    • Tessellated
    • Untessellated
    • Absolute
    • Absolute extruded
    • Relative
    • Relative extruded
  6. Polygons
    • Extruded polygons
    • Absolute v relative

To get started, examine the simple placemark layer in the KML samples. Save just this layer as a KML file on your machine and open it up in notepad2. Examine the tags and values, referring back to the Google Earth documentation regarding what they mean.

  • Can you create a simple placemark located on LSRC?
    (Long=-78.94233707398286, Lat=36.00445392565037)
  • What happens when you change the name and description values?

Next, look at the Floating Placemark example in Google Earth. What’s different about this relative to the simple placemark? Now look at the KML noting any additional elements. Back in Google Earth, open up the properties of the Floating Placemark and change some things. See how these changes alter the KML.

You should be getting a feel for how to explore and gain familiarity with building your own Google Map. If you continue to work with Google Earth this way, before too long you will have a good grasp of at least the fundamentals of creating your own maps. You’ll also likely move from tutorials to the reference documentation to figure out how to accomplish your objectives. Another complementary approach to learning this is to find other Google Earth kml or kmz files and ‘reverse engineer’ them.

In subsequent tutorials we will examine how to construct kml files programmatically and add image overlays. For now, however, try the exercises below to familiarize yourself with how edits to a KML file manifest themselves in Google Earth.

 


Exercises

The goal of this tutorial is to get you on your way to learning KML so that you can create your own features that can be viewed in Google Earth. Rather than a comprehensive guide to all that you can do in Google Earth, these exercises focus on how to experiment with the various features of KML so that you can continue your quest to mastering KML – or at least accomplish whatever it may be that you want to show in Google Earth.

I. Creating a Google Earth placemark

The placemark is the most basic element in Google Earth – a point on the map often shown as a yellow pushpin. It can be embellished with various features or show in different ways (as we’ll see next), but we’ll begin with its most basic form. The following exercise instructs how you can find and copy the KML code for a simple placemark (or most any basic feature available in KML) to your drive so you can edit it, and how you can see how your edits manifest themselves in Google Earth. In doing so, you can see directly what controls what in KML.

The goal of this exercise will be to create a placemark showing the location of the LSRC. We’ll begin by viewing the code Google provides for making a placemark, and manipulating that code through experimentation so that we know how to move it to a different location and modify the placemark’s name and description.

1.      Finding the code for a simple placemark.

  1. Download the Samples in Earth KML file from the KML Tutorial web page and open it in Google Earth. This file contains examples of many of the various elements you can create with KML.
  2. Expand the Placemarks folder and you’ll see various formats in which you can display placemarks, or points, in Google Earth. You should see your own Simple Placemark entry separate from the one contained in the KML Samples folder previously loaded into Google Maps.
  3. Right click the Simple placemark entry and save it as a KML (not KMZ) file to your local drive.
  4. Open the KML file in Notepad++. You are now looking at the basic KML code for a creating a placemark.
  5. With the KML file still open in Notepad++, double click the file to open it up in Google Earth.
  6. Have a look at the file in Notepad++. We begin with our experimentation by hypothesizing how some of the various elements in KML control the item’s appearance in Google Earth. We’ll begin with the <coordinates>
  7. In Notepad++, change the coordinates in the existing file to those of the LSRC –
    Long=-78.94233707398286, Lat=36.00445392565037 – and save the file.
  8. Now go to Google Earth. The Simple Placemark feature doesn’t update automatically. Instead, you have to right click the item in Google Earth and select Revert to re-read the KML file.

2.      Learning KML through experimentation

If you got your placemark to appear on top of the LSRC, you have successfully learned the role of the <coordinate> element in KML! Now see what happens when you change the values between the <name></name> and between the <description></description> tag pairs. If you need any additional explanation or are simply curious to learn more (which is highly encouraged) you can examine the documentation for the given element in the KML reference document:

More about the <name> tag: https://developers.google.com/kml/documentation/kmlreference?csw=1#name

More about the <description> tag: https://developers.google.com/kml/documentation/kmlreference?csw=1#description

II. Taking it a bit further: creating an extruded placemark

Now that we have a bit of confidence with our KML abilities and can put a placemark anywhere we want, let’s delve further into customizing the appearance of this placemark. You’ll see that the KML samples file we downloaded and opened in Google Earth has two other types of placemarks: floating and extruded. We can examine and experiment with these just as we did with the simple placemark to learn more about how KML can be used to create and manipulate Google Earth features.

3.      Experimenting with the extruded placemark

  1. First, examine the extruded placemark example in the KML Samples file so see what exactly makes a placemark and “extruded” placemark.
  2. Save the KML code for the above sample to a file on your local drive. You’ll notice that it has a number of additional tags and values compared to the simple placemarks.
  3. Experiment with the various tag values. What do they control? In particular, which tags make this an extruded placemark?

III. Creating paths in KML

We’ve now observed that a placemark is just a point (or coordinate pair) represented in KML along with various instructions on how to display the point and perhaps from what vantage point to look at this point. From our experience in ArcMap, we know that a line can be represented as just a series of points marking the vertices of the line. It’s just the same in KML/Google Maps, as well see in the following exercise.

In this exercise, we also use a different technique for exploring KML. Here, instead of downloading the KML file to a local drive, editing it, and then opening it back up in Google Earth to see what’s change, we do the inverse. By opening the properties of a feature in Google Earth, we can change some of its settings. Then when we save the feature to a new KML file, we can see what’s changed by viewing the KML file in a text editor.

4.      Manipulating a path

  1. First, have a look at the different ways paths can be displayed in Google Earth by viewing the different examples in the KML Samples file. What are the differences between “tessellated” and “untesselated”? Between “absolute” and “relative”?
  2. Make a local copy of the Relative Extruded path item found in the KML Samples so that you can view it in a text editor.
  3. Open that local file back up in Google Earth, and then open its properties (via right-click). This offers another means for playing with the different characteristics of the file. You can also edit the path’s geometry when the property window is open.
  4. In the object’s properties (in Google Earth), try to change the colors and the height at which the features are displayed. When finished, save the features as a different KML file. Can you see how those manipulations appear as differences in the KML file?
  5. Also in Google Earth (with the property window open), move a few vertices to get a feel for how the shape can be edited.

Another key item to note with paths is that the actual line is defined by a list of coordinate pairs with elevations. If you were given raw data of X,Y, and Z values, say generated by a GPS or an animal tracking tag, all you need to do is convert this to longitude/latitude/elevation values (e.g. via a Python script), and then you can simply cut and paste those values between the <coordinate></coordinate> tags in your KML and you’ll have a KML file that will show your path in Google Earth! (Note: you may want to either edit or simply delete the <LookAt> section so Google Earth will zoom to your path and not the one you edited out…)

 

So now you see that there are two approaches to experimenting with KML, from editing the KML file itself or by playing with a feature’s properties in Google Earth. Through these simple manipulations, you should be getting a feel for how to teach yourself KML. Some aspects are fairly straightforward; others will take more experimentation and reference to the on-line documentation. At the very least, however, you should now understand that all the cool things you see in Google Earth are controlled via KML files. There’s no mystical wizardry, but rather a limited (but growing) library of KML tags and values assembled in a text file that can be opened and understood by the Google Earth application.

As you progress in learning the basics of KML, you’ll likely want to become more and more familiar with the documentation provided: https://developers.google.com/kml/documentation/

In particular, you should run through the tutorial and at the very least familiarize yourself with what Google Earth can do: https://developers.google.com/kml/documentation/kml_tut . The tutorial is also another source of basic KML files that you can copy to your local drive, save as text files with the extension .kml and experiment with in Google Earth.

Alternatively, you can use Google’s Interactive KML sampler as a very easy means of experimenting with KML: https://kml-samples.googlecode.com/svn/trunk/interactive/index.html. Note that this requires the Google Earth plugin for your browser. Also, on campus machines, you’ll have to disable Symantec’s blocking of the JavaScript for the page to load correctly. See the figure below:

Lastly, when you become more advanced with your tinkering of KML, you’ll likely want to dig into the Developer’s guide (https://developers.google.com/kml/documentation/topicsinkml) and the KML reference pages (https://developers.google.com/kml/documentation/kmlreference). While a great deal of interesting features can be displayed in Google Earth using the basic features in KML, Google Earth can actually create quite sophisticated presentations. But that requires much more investment in learning the ins and outs of KML.

But now you at least have a road map for your learning quest!