R and Google Earth
This is a simple example of using R to create input for Google Earth. We are not concerning ourselves here with the best way to display the data at this point. Rather we are exercising the mechanism for generating KML from data in R so that we can display information on Google Earth. You can load this into Google Earth by clicking on this link. Alternatively, you can look at some screen shots The data are temperature measurements for each of 100 cities in the US taken in each of January, April, July and October. So, for each city we have a time series, and for any of these 4 times, we have a picture of the distribution of temperature across the US geographically. By displaying the information in Google Earth, we get different forms of interactivity relatively easily. A user can click on a point and get an HTML document to appear in a popup "bubble" window. The user can zoom in and out and see the big picture or individual cities. We could setup an animation so that we can see how the temperature varies over time dynamically rather than looking at the different time series. For better or worse, we will do something reasonably obvious but not necessarily visually effective.- At each city, we will display a small picture of the time series of the temperature for that city.
- We color the lines connecting the points to illustrate whether it was cold, warm, hot or very hot.
- A legend in the lower-left corner of the screen maps the colors to values.
- Each city has a thumb-tac which a user can click on to pull up a window giving a more detailed display of the time series with an axis and also a table listing the actual values.
- If the Google Earth time window is widened to include two or more months, clicking on the thumb-tac illustrates all of the points within that time period for that city by placing them on spokes eminating from the thumb-tac.
- there is little variation in weather, e.g. California (especially San Francisco), Hawaii but that Hawaii is very warm all year round, whereas California is cooler in the early part of the year;
- that the mid-west is very cold in the winter and hot in the summer;
- Alaska has quite a bit of variation, but is cooler than the rest of the country;
- the south-east part of the country is noticeably warmer;
- the Rocky mountains don't seem to be very different from the flat mid-west. Is this because the cities in the Rockies are not at very high elevations;
- Lake Superior keeps Duluth cooler in the hot periods than other cities nearby, but this is not true for Lake Michigan's effect on Milwakee and Chicago on the other lake.
The Code
-
- Code to generate XML
- This creates the KML document in R and the serializes it to a file.
- Code to generate images
- This is done once, not each time we generate the XML, so
createHist(temperature); createHist(temperature, mini = TRUE); createLegend(temperature)
is the command. - Code to generate XML
Future work
There are lots more interesting things to do with this interface.-
- On Windows, we can control Google Earth directly using a DCOM client interface.
- We can work with different example data
- For instance, earthquake information, animal migration.
- Have interactive controls in R (e.g. via RGtk, RwxWidgets, RQt, tcltk) and have queries in R select points in a dataset and highlight those in Google Earth
- Interpolate the temperatures for time and space over all the US and superimpose a surface. And then allow the user to transition between these over time via the Google Earth time control.
- On Windows, we can control Google Earth directly using a DCOM client interface.
Notes
This is a fresh start, but relates to the work that Motoki Wu did in an "Advanced Computing Topics" class in Davis in 2007.Duncan Temple Lang <duncan@wald.ucdavis.edu> Last modified: Tue May 15 10:39:05 PDT 2007