GEOG 863
GIS Mashups for Geospatial Professionals

What about KML?

PrintPrint

KML (Keyhole Markup Language, named for a company acquired by Google in 2004) was originally developed for the display of data in what would become Google Earth, but subsequent modifications to the Maps API made it possible to view KML data in Google Maps as well.

KML data can also be incorporated into your own mashup through the use of the KmlLayer class. This map contains an example of the use of that class:

var kml = new google.maps.KmlLayer({
  url: 'http://ssc.e-education.psu.edu/get_ssc_in_kml.php?day=0&app=maps'
});
kml.setMap(myMap);

FYI...

The points displayed in this KML are weather stations symbolized according to the type of weather occurring there (such as Dry Polar, Moist Tropical, etc.). The weather types are determined using a system called the Spatial Synoptic Classification (SSC), originally developed at the University of Delaware in the mid-1990s. Here is more SSC information if you're interested.

Your first reaction might be that this is a lot easier than the process for adding shapefile data outlined earlier in the lesson. Yes, it is true that for some applications adding your data as KML might be a far better solution. In addition to making it easier to add your data to a map, the other big advantage to using KML is that it is an open data standard that makes the data interoperable with other applications (most notably, Google Earth).

That said, adding KML data to a Google Map also has a number of drawbacks:

  • The fact that multiple features can be added as one overlay is one of the things that greatly reduces the Javascript code needed, but it can also be a disadvantage if you want to manipulate individual features.
  • It is more difficult to produce a sidebar that behaves as we saw earlier in the lesson. (There are 3rd-party extensions that address this issue.)
  • Symbology styles encoded within a KML file for use in Google Earth may not yield desirable results in Google Maps. For example, the weather stations displayed in the link above were originally symbolized using 12-pixel x 12-pixel icons. However, when displayed in Google Maps such icons are scaled to 32x32 pixels, creating an ugly map. My solution was to center the existing 12x12 images within 32x32 canvases and add transparent pixels around the outside.
  • KML is a rather verbose language (you might try viewing the KML from my example above in a plain text editor like Notepad), so if you are going to author KML yourself (e.g., by writing a script that retrieves data from a database), you will need to spend some time familiarizing yourself with its syntax.

If you are interested in learning more about KML, I’ll refer you to the KML documentation maintained by Google. There you’ll find a language reference and examples laid out in much the same way as the Google Maps API documentation site.

How to create KML

As a form of XML, KML is stored in plain text files. Thus, any text editor can be used to author a KML document. However, unless you’re dealing with just a few features, manually coding the KML file in a text editor is not practical. Fortunately, KML’s evolution into an open international standard has meant that it is not difficult to find tools that automate the conversion of other data formats into KML. For example, in ArcGIS, users can convert data stored in shapefile or geodatabase format to KML using the Layer to KML tool or entire maps using the Map to KML tool. I encourage you to try one or both of these tools, upload the output file to your personal web space and copy and paste the URL to the file into the Google Maps search box.

Now that we've talked about a couple of file-based options for data storage, let's shift our attention to a cloud-based option: Google's Fusion Table technology.