Tuesday, January 09, 2007

Importing GIS Data into Google Earth

Google Earth has often been described as a geospatial data browser. The reason for this is simple ... while Google Earth is fantastic for visualization, it does not do (nor has it been intended to do) many traditional GIS tasks. As an example, you cannot really query GIS data or directly access attribute data. You also cannot edit or manage geospatial data. Google Earth is really intended to do one thing very well, and that is to display geospatial data on a visually appealing framework. There have been many efforts by a lot of people to try and wring GIS type capabilities out of Google Earth. Many of the more successful ones used a combination of network links and data embedded in the description tag (and visible in the callout balloon) to link points to other data available on servers. What would really make things easier would be if users could click on Google Earth and grab coordinates. If we could do this, then we could attach geospatial capabilities behind Google Earth to make it act as a GIS interface. The new Google Earth API (and a lot of trickery) have now made that possible. The first thing I wanted to do was to be able to create toolbars that could be accessible in Google Earth. Since I could not do that, I started looking into grabbing the Google Earth Windows handle so that I could embed the viewer in my application. I had a 75% solution in the bag when I stumbled on GoogleEarthAirlines. GoogleEarthAirlines is an ActiveX control written in Delphi that does just what I was planning to do. When I found this, I put my control on the backburner and started using this. The graphic below shows the GoogleEarthAirlines control in my application.

The plan now is to link GIS data with KML. KML will act as the layer file that does nothing more than render my GIS data. to get the GIS data into Google Earth, I used a modified form of Shape2Earth. Shape2Earth converts the shapefiles to KML, and then writes an XML file that links the two files together.

Shape2Earth is used to create height values of GIS Data

Basic colors for the output KML are selected

A Unique ID is selected from the Attribute field. This will be used to attach to databases through Google Earth

The steps above walk through loading a shapefile into the Google Earth GIS application. Now, we use our trickery to click on Google Earth and grab a coordinate. This is done using the method described here.

The great thing about this method is that it does not matter what the orientation of Google Earth is. It will always return the coordinate that you clicked.
In the graphic below, I have selected the ID button, and then clicked on a building. The application uses geoprocessing capabilities provided by the open source GIS application MapWindow. It loads the selected shapefile, and uses the coordinate to determine what has been selected. The result is the ability to directly access geospatial attribute data by clicking directly in Google Earth.

The same method can be used to select multiple features, as is shown below.

Select Tool lets the user drag a selection box across Google Earth

MapWindow components are used to select the geospatial features and display their attributes
Now that we can do some basic GIS type functions directly in Google Earth, we can start doing more sophisticated workflows. The next step is to actually create GIS data directly in Google Earth. That has already been done, and will be posted here shortly.


  1. thanks for the tip. I do however have a problem with GEplugin. I get an EIdCouldNotBindSocket (could not bind socket) exception everytime i launch my app. How did you get around this one? thanks

  2. I have never encountered that error. You might want to download the sampe code put out by the author of Google Earth Airlines at http://www.googleearthairlines.com/ look under the apps tab).

  3. Nice article. How 'bout posting some key pieces of code? The pieces that tie things together.

  4. Anonymous2:58 AM

    Can u please give the code to import custom toolbar in goole earth.

    Thanks in advance...