A Look at KML, an Open Standard to Represent and Visualize Spatial Information

Ad:

Fast developing GIS technology has become even more easily available to the general public through smart phones and tablets. At the Esri 2015 User Conference, the president of Esri, Jack Dangermond, stated that GIS is the tool to apply geography everywhere. However, to apply GIS more broadly, the barrier of proprietary data formats, such as the geodatabase, must be overcome.  As an open spatial data standard, KML (Keyhole Markup Language) has a simple data structure and is more widely accepted and used. The Google Earth program can create and open KML files. Users can also directly use any text editor, such as free Notepad ++, to create and edit a KML file to visualize spatial data. Following is a brief systematic introduction to KML files and how they may be used.

KML was developed by Keyhole Inc. along with its Earth Viewer application in 2001. The word Keyhole may have come from an American military satellite program developed in the 1970s. Google acquired Keyhole Inc. in 2004 and began to use KML as a file format to display geographic data in an Earth browser, such as Google Earth, Google Map, and Google Maps for mobile. Google has submitted KML 2.2 specification to the Open Geospatial Consortium (OGC) and OGC approved OpenGIS® KML Encoding Standard (OGC KML) on April 14, 2008. In other words, KML is an international open and implementation standard and maintained by the OGC. At present, many applications can display or consume KML, including Google Earth, Google Map, Google Maps for mobile, Marble (virtual globe and world atlas), NASA WorldWind, ESRI ArcGIS Explorer, Adobe PhotoShop, AutoCAD, and Yahoo! Pipes. Within ArcGIS for Desktop (10.3.1), there are 3 KML related tools, such as layer to KML, KML to Layer, and map to KML. Future KML 2.3 standard is under development by OGC.

KML uses the geographic coordinate system of longitude, latitude, and altitude (optional) to represent a spatial point on Earth. Unlike a shapefile, a KML file itself can define symbology, labeling, and transparency. Also, it is able to add icon and graphic overlays. From file structure aspect, KML is a XML-based (Extensible Markup Language) language schema (to certain degree, it is similar to basic HTML file structure). In fact, a markup language is a set of markup tags (or element) and each tag describes different document content between its start (the tag name itself) and end (a forward slash in front of that tag name). In other words, every element tag needs to be closed, such as <kml> is closed by </kml>

Like all XML files, KML must begin with the XML header information followed by the KML root element tags.  The kml 2.2 namespace specification must be present in all KML files. One KML file can only contain one <kml> element and all other information should be wrapped within the <kml> tag (Figure 1).

Figure 1 KML header which is required by all KML files

Figure 1 KML header which is required by all KML files

Besides the element of <kml>, KML has many defined elements and all of them need to be contained in angle brackets. Also, all elements are case sensitive, i.e., each element’s name must be spelled exactly as the it is in the KML standard. KML elements are divided into two categories: complex (parents) element which begins with a capital letter and can contain other elements, and simple (children) element which begins with lower case letter. KML requires child elements to be listed in the same order as listed in KML 2.2 Reference, but not all child elements are required for a complex element (elements can be omitted).

To represent point, line, or polygon, <Placemark> element tag is needed. There are many children for <Placemark> and the most commonly used ones are <name>, <description> and geometry tag.  The element of <name> will be used as label for the spatial feature and <description> provides extra information about it. Geometry elements include <Point>, <LineString>, <LinearRing>, <Polygon>, <MultiGeometry>, and <Model>. Examples of point, line, and polygon KML files will be discussed below.

Figure 2 shows a point KML file which represent the entrance of Stephen F. Austin State University Experimental Forest. The longitude and latitude of the point were collected in the field. Within Notepad++, all the information can be typed in and the file can be saved ending in .kml. Google Earth can directly open this file as shows in Figure 5. The indentation in the file is only for readability and it is not required by the syntax of KML standard. There are two required values for <coordinates> element as longitude and latitude expressed in decimal values. Altitude is the third value with a default value of 0. The values are separated by comma and no space is needed after comma. Attention is needed here as longitude is specified first for KML files.

Figure 2 A point KML file

Figure 2 A point KML file.

If there are multiple points, a <Document> tag will be needed right after the <kml> element. Every point will be described by its own <Placemark>, <name>, <description>, <Point> and <coordinates> tags. The </Document> tag shows up after all points are defined. Similar principle applies to multiple-feature line or polygon KML files.

To represent line features, the <LineString> element can be used and it requires two or more coordinate values as vertices of the line. Figure 3 shows the road KML file in SFA Experiment Forest. There are 8 GPS measurements to form this line.

Figure 3 A line KML file

Figure 3 A line KML file.

To define polygon, more KML elements (<Polygon>, <outerBoundaryIs>, and <LinearRing>) are needed than to represent point and line. This setting allows the possibility to represent polygons with hole(s) which can be described by <innerBoundaryIs> element. The beginning point’s coordinates need to be repeated as the ending one to have the polygon closed. The forest inventory study site polygon KML file is shown in Figure 4.

Figure 4 A polygon KML file

Figure 4 A polygon KML file.

The point, line, and polygon KML files demonstrated above were opened by Google Earth Pro (free to the public) and all spatial features were shown correctly (Figure 5). Each file’s property can be opened in Google Earth’s Places and thus to define its symbology (line width, line and fill color, and transparency). The line’s length is automatically measured as 0.69 miles and the study site has an area of 24 acres with a perimeter of 0.78 miles.

 Figure 5 The point, line, and polygon are shown on Google Earth

Figure 5 The point, line, and polygon are shown on Google Earth.

KML is very powerful to represent spatial data with many other tags, such as<extrude>(extend the feature to the ground) and <tessellate>(allow the line to follow the terrain). The spatial feature can also be viewed from different direction or viewpoint by setting up <LookAt> element. Also dynamic KML files can be defined suing the <Update> element to change, delete, or add elements to a file.

KML files and their related images (if any) can be compressed into KMZ file. KML and KMZ files can be emailed or host online for sharing purpose. In summary, the simple and open KML file format provides the public an easy way to visualize and share spatial data.

This work was supported in part by McIntire-Stennis funding.

Authors:

Yanli Zhang, Ph.D., associate professor and Matthew W. McBroom, Ph.D., professor, Stephen F. Austin State University.

 


Advertising



Like this article and want more?

Enter your email to receive the weekly GIS Lounge newsletter:

Advertising