Georgetown University



[pic]

Using KML, XML, and XSL to Create Google Earth Applications: A Tutorial

Betsy Page Sigman

McDonough School of Business

Georgetown University

412 Old North

Washington, D.C. 20057

bps@georgetown.edu

(202)687-7062

William J. Garr

Center for New Designs in Learning and Scholarship (CNDLS)

312 Car Barn

Georgetown University

Washington, D.C. 20057

Wjg8@georgetown.edu

(202)687-9119

ABSTRACT

Google Earth and Google Maps have provided researchers and laypeople with ways to map any set of data quickly and easily. This tutorial covers the following topics: 1) The benefits of displaying data using Google Earth/Google Maps; 2) KML and the creation of placemarks in Google Earth/Google Maps (GE/GM); 2) Using an Access database to create many placemarks simultaneously; 3) Creating different styles of placemarks based on the value of an attribute.

INTRODUCTION: THE BENEFITS OF DISPLAYING DATA USING GOOGLE EARTH/GOOGLE MAPS

Recent developments have made possible the creation of ‘mashups’ (web applications which include functions borrowed from other web-based programs.) Google Earth and Google Maps make it especially easy to use their sophisticated functions in simple applications you can create from your own data.[1] With the creation of KML, or Keyhole Markup Language, named after Keyhole, Inc., a software company founded in 2001 and taken over by Google, it is now possible for developers to easily make placemarks, polygons, paths, and other objects to be shown on Google Earth/Maps.

The display of information directly on representations of satellite maps (through GE/GM) conveys a number of distinct benefits: 1) It allows the viewer to understand the data more fully, because it is tied to geographic locations in the viewer’s mind; 2) It can enable the viewer to use the data more easily. For example, if the viewer sees a placemark indicating a location of a building, he/she can more easily figure out where that building actually is, and get there more easily. 3) It gives the viewer a more comprehensive view about how the data presented relate to each other. For example, the viewer looking for a placemark that indicates an organizational presence (say for a hobby club) in one area can easily see that there are numerous other places nearby. 4) And, it can aid in decision support, due to the properties discussed above.

Additionally, the placemark offers viewers a way to selectively and quickly view information they need. For example, in the case of an organization, they can easily access such facts as address, contact email, website, etc. Such information can be accessed by clicking on the placemark or may be identifiable by differentiating the placemarks by some property such as color or shape.

While placemarks may be created individually, it is often useful to create many placemarks at a time, if a database with the appropriate information is available, even if the information does not already contain location information. Users can subsequently add the location information using Google Earth/Map’s user interface. This paper will serve as a tutorial that explains how to use KML, XML, and XSL with an Access database to create many placemarks simultaneously. We begin by discussing KML.

KML

KML is based on XML (its tags are standardized XML tags) and is used for creating placemarks (as well as polygons, images, 3D models, etc) on Google Earth and Google Maps (GE/GM).[2] Here is a simple KML file that creates one placemark:

1

2

3

4 Washington, D.C.

5 Washington, D.C.

6

7 -76.5427,38.583314,0

8

9

10

Let’s go through this KML file statement by statement (I’ve put numbers in for ease of reference. Don’t include these numbers if you use this as a model.):

1) This statement tells what version of xml to use. It is called the XML header. It also describes the encoding used. KML is based on XML.

2) This is the beginning kml tag and specifies the xml namespace (thus xmlns) that you are going to be referring to in your document. It is called an XML namespace declaration. The XML namespace attribute in the example above is . This is a Uniform Resource Identifier or URI. A URL is the most common type of URI. Although it looks like a URL, this URI does not point to any content on the Web. It is only used to establish the uniqueness of the namespace. XML documents can be combined in various ways, so it is important to distinguish placemarks in the KML schema from any similarly-named tag defined in some other schema. This attribute enables you to use kml tags. You must include this when you create any kml 2.0 document.

3) This line refers to the Placemark object. This object holds three elements here: description, name, and point.

4) In between the description tags, you often give information about the placemark. The name, “Washington, D.C.,” will appear on the placemark callout.

5) The name element serves as the label, or the tag beside the placemark.

6) The point element is set up.

7) The coordinates element has the coordinates that are given (longitude, latitude, and height). The end tag is on the same line.

8) End tag for point.

9) End tag for placemark.

10) End tag for kml.[3]

HOW TO CREATE A KML FILE

KML files can be created in 3 ways: 1) Using Google Earth’s placemark creator. One can click on the placemark icon and fill in the blanks. 2) Creating the code in a plain text editor such as Notepad or an XML text editor. 3) Output data from a database to quickly create a KML file for many placemarks. In this tutorial, we show how to do this using Access and an XSL transform.

We will start by creating a placemark the way such placemarks are often created, individually, using Google Earth’s placemark icon.

Once you have installed Google Earth on your PC, go ahead and open it up. At the top, you should see an icon with a yellow pushpin on it. Click on this to create a placemark near your hometown.

1) When you click on the yellow pushpin icon, a window opens up. In the space labeled “Name” type in the name of your hometown or some other place of your choice.

2) Notice that latitude and longitude are filled in.

3) Cursor over the yellow box containing the pushpin (that is now floating over GE) until it changes to a hand with a pointing finger. (Note that the only time that this change in the cursor will take place is when the Description box is open.)

4) Holding down the left mouse button, position the finger near the place you have chosen. Use the compass arrows that appear in the upper right hand corner of your screen to orient your movements.

5) Fill in a description. You can put whatever you like here.

6) When you are done, click “OK.”

7) Now look over to the left in the sidebar section labeled “Places” and you should see a pushpin with a link bearing the title of your hometown.

8) Click the link to go to the pushpin again.

9) Right click and go to “Properties.”

10) Now click on the pushpin in the upper right hand corner of the box. You should see an array of different icons.

11) Experiment with the placemark using the Google Earth interface until you get a placemark that looks like what you think should be the model for this project. Use the methods below to change various attributes of your placemark:

a. Shape: Click on the icon next to the name of your icon to select a shape for your placemark. Note that you can also bring in custom icons from an external source.

b. Color of placemark: Click on the color to choose a different color for the shape you just selected.

c. Scale: Increase the number in the “Scale” box to increase the size of the icon.

d. Opacity: Lower the percentage from 100% (fully opaque) in the “Opacity” box to make the icon appear more transparent.

e. Color, Scale and Opacity of Label: Click on the “Style, Color” tab to change the color, scale, and opacity of the label that appears next to the placemark.

f. View: Change the Tilt of the placemark by clicking on “View,” then changing the degree of the “Tilt.”

g. Altitude: Change the height of the placemark by clicking on “Altitude” and placing it clamped to the ground (or relative to the ground or at an absolute height) or hovering over the ground at a specified height.

Look at the KML that makes up the placemark you just created

1) Once you get your placemark looking the way you like, click on the placemark in the window to the left of GE, right click, and select “Copy.”

2) Open up Notepad, right click and select “Paste” and try to understand the statements that make it up.

3) Next, add another dummy placemark right below where you created your first placemark. It should be in the same folder.

4) Go back and click on the folder that holds both placemarks. (Or, you can create a new folder to store the placemarks. Right click and go to Add, New Folder. You can cut and paste the placemarks into the new folder you have just created. In the sample below, the folder is named “Test Placemark Folder.” The placemarks are named “Test Placemark One,” and “Test Placemark Two.”) Right click and copy to a new document in Notepad.

5) Again, try to figure out what is going on. Look at the document element that contains the information about the folder and the icons used in the folder. Review the style elements and try to understand them, or look them up.

Here is an example of the kml for such a file. Note that this is for the house icon (that highlights when you get close to it, thus the two different styles in the kml below.) Comments are used to describe what is going on.

EXAMPLE OF A SIMPLE KML FILE

KmlFile

normal

#sn_icon10

highlight

#sh_icon2

1.1





Test placemark1

House placemark

-95.26548319412245

38.95938957105108

0

11001000

0

1.134720376143785e-014

#msn_icon10

-95.26548319412245,38.95938957105108,0

EXPORTING AN ACCESS DATABASE TO XML (WITHOUT AN XSL TRANSFORM)

Now that you have seen the way that KML is generated, and have some understanding of the tags it includes, you can start to think about how use records from a dataset to create XML tags (remembering that KML is a subset of XML). Here we will export an Access database to XML, to examine the formatting that occurs without any stylesheet transformation.

1) Look over the Access database that contains the data you want to use to create placemarks from.

2) Think about the fields you want to include in your placemarks.

3) Select those fields and create a query using those fields in Access. Save the query.

4) Export that query to a KML file, by going to the “External Data” tab, then going to the “Export” tab, and going to “More,” then selecting “XML File.”

5) Look at the output by opening it in a Notepad file. If you need to, go back and change any field names, getting rid of spaces and characters such as underscores, that don’t translate well to KML and re-output the file. Notice that each record becomes an element encompassed by tags bearing the name of the query. Thus, if you named your query “ExportQuery,” the fields for each record would be included within tags labeled “ExportQuery.”

CREATING AN XSL TRANSFORM TO CONVERT THE XML OUTPUT TO KML

XSL can be used to transform the output when you export an Access database to XML. XSL stands for eXtensible Style Language. Basically, XSL tells how XML should be displayed. Since KML is a subset of XML, we can also use XSL to transform XML output to KML.

You can use XSL to change what ends up in the output file. You can add or take away elements from the file, sort elements, make decisions about what to do with an element—depending on its value, etc. You can also embed HTML to make the output for a placemark look the way you would like. Here, we will use an XSL Transform to change the way data is output to a file, so that the proper tags and formatting for creating placemarks are automatically generated.

Below, the steps used to create an XSL Transform are detailed. We begin by telling the browser that we want to use XML and XSL (actually declaring an XSL stylesheet) with the following statements:

In the next statement, we say to go back to the root element to start getting XML records. This gives the template for the rules that apply when you match a specified node, in this case, the root element (or the whole document).

The statement below indicates the version of kml that will be used.

Then comes the declaration of the document and the name:

KmlFile

The statements below describe the way the pushpins will look. If you wanted to change this example stylesheet so that it would transform the data to look like the icons you used in the placemarks you developed above, you would simply replace the code below with what you had created earlier for the icons you chose.

1.1



1.3



normal

#sn_ylw-pushpin

highlight

#sh_ylw-pushpin

Here we start the description element. Notice how we use CDATA to create breaks. In this case, CDATA enables us to embed HTML in the description of the placemark. We also go through and select the “Community” field, and put in a break.

]]>

]]>

Below, we set up a way to test whether the value of “Town” is the same as “DistrictState” and if so, only print “Town”. Then, using an “otherwise” element, select “Town” as well as “DistrictState” if the above is not true. Note also that we’ve put in commas between the “Town” and the “DistrictState” using CDATA again. We’ve also included the organization’s email.

]]>

Below, we’ve used a little programming to create dummy coordinates for our placemarks around the equator, at multiples of 5 degrees longitude, since we were using an international database of some fairly remote places and did not have a database of latitude and longitude we could match locations to. We’ve also given all the points a height of 5, just to make visualization easier. Later, these can be moved to their appropriate geographic locations.

,0,5

The file above needs to be saved (in Notepad ) as an .xsl file. Then it can be used for an XSL Transform.

CREATING KML PLACEMARKS BY TRANSFORMING ACCESS DATA USING AN XSL TRANSFORM

To export your Access data to KML in Microsoft Access 2007 by using an XSL transform, carry out the following steps:

1) Select table or query to export;

2) Click “External Data” tab;

3) Under Export, click “More” to show more export options, then “XML File”;

4) Browse to find the location you want to export the data to (being sure that it will be saved as an XML file), click “OK”;

5) Be sure that the “Data” box is checked;

6) Click “More Options” and then click “Transforms.”

7) Click “Add” and find the .xsl file where you stored the code to transform your data into XML. Click “OK.”

8) Be sure that “Export Data” is checked and under “Records to Export”, the “All Records” radio button is selected.

9) Click “OK” to transform the data set to XML.

Creation of a KML File

It is simple to then create a KML file by renaming and saving the XML file with an extension of .kml. This change allows it to be read by Google Earth.

Bringing up Google Earth with the KML file

If Google Earth is installed on the computer (and the coding has been done correctly), the newly-created KML file can be double-clicked and Google Earth should appear with the formatted placemarks. Or you can right click and select “Open with” and then “Google Earth.” The file can also be posted on a web site and clicked on, and if the viewer has Google Earth installed, the placemarks will automatically appear. [4]

Creating different placemark styles and automatically assigning them to records based on an attribute

Often there is a need to create different types of placemarks to differentiate between types of organizations, places, etc. This can be done using an xsl:choose statement in combination with xsl:when test statements. An example of an xsl spreadsheet that was used to create blue ranger station icons (that look similar to schoolhouses) to represent high schools and red ranger station icons to represent colleges is shown below.

STAND

ffff5500

1.2



normal

#sn_ranger_station

highlight

#sh_ranger_station

ffff5500

1.4



normal

#sn_ranger_station_copy1

highlight

#sh_ranger_station_copy1

ff0000ff

1.4



ff0000ff

1.2



#sn_ranger_station

]]>

]]>

]]>

]]>

,,0

#sn_ranger_station_copy1

]]>

]]>

]]>

]]>

,,0

Conclusion

In the tutorial above, we have shown some ways that a Microsoft Access database can be used to quickly create Google Earth and Google Maps applications, by automating the creation of placemarks using XSL transforms. By using methods such as these, information can be quickly made available to people who can search visually for organizational and other types of information that have a geographic component.

-----------------------

[1] “The World on your Desktop,” The Economist Technology Quarterly, September 8, 2007.

[2] A compressed version of a KML file is called a KMZ, which is a zipped file. Sometimes, you may need to change the extension to zip in order to open a kmz file.

[3] This is a very simple explanation of some of the tags available in kml. For more information, go to

[4] This project was developed as part of a project funded by the Center for New Designs in Learning Systems (CNDLS) through an Engelhard Grant. The Engelhard Program looks at the effects of linking the content of college courses with student civic engagement and mental health issues. For this course, we examined two data sets. The first contained data on HIV/AIDs clinics from the South African Catholic Bishops Conference (SACBC) and th active in promoting awareness advocating for an end to the current genocide in Darfur, Sudan and working to create a permanent anti-genocide student movement. (). The second contained data from STAND, a Student Anti-Genocide Coalition, which serves as an umbrella group for student groups active in

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download