Building Sensor Network Interfaces with KML
In the Fall of 2005, I was challenged to create a unified visualization interface to the micro-climate sensor and multimedia networks at the James Reserve. Having already developed some web-based graphing tools for sensor data visualization, I was eager to start add a spatial dimension to diverse sensor deployments.
screen shots from the James
Reserve KML layer
The James Reserve KML layer has received rave reviews, even catching the attention of Google's own Vinton Cerf at our grant's External Advisory Board meeting this past January. Dr. Cerf helped to arrange a visit to Google's office in Mountain View, where I demonstrated the project during an Urban Sensing Tech Talk given by a group of us from the Center for Embedded Network Sensing (CENS).
During that trip, I also had the opportunity to show it directly to several members of the Google Earth Team. Having kept in contact with Rebecca Moore ever since, I have been able to send some KML recommendations to the GE team, and share some of my KML ideas and side-projects.
Since my visit to Google earlier this year, I have presented the James Reserve KML layer to great interest at numerous functions, including:
- ESRI's 2006 SCGIS Conference
- a meeting with ESRI's ArcExplorer development team
- Univ. of Calif. Natural Reserve System meetings for the acquisition of new lands
- Crossbow - wireless sensor network technologies (a CENS partner)
- GreenInfo.org - GIS mapping services for public interest groups
Download the layer:
This layer is quite complex, and without an introduction to the sensor systems at the James Reserve, it might be a bit daunting.
If it's a little too much to consume without some guiding explanation, check out the Movies section for an easier look at the layer.
Four flavors available:
- "Live KMZ" version - all webcam images, sensor
sparklines, and groundoverlays are retrieved 'live' from our server.
returns a network link to the kml generation script... minimal download time; updates every 5 minutes
- "Complete KMZ" packages all images/overlays needed
for an offline demo (except external links to live graphing
tools)
please be patient, as these take a while to prepare... you will be presented with a file to download momentarily
About James Reserve Sensor Networks
The James Reserve, in Southern California's San Jacinto Mountains, is the field test-bed for the Center for Embedded Network Sensing. There are nearly a dozen independent research projects (2) (3) and accompanying sensor system deployments at the Reserve. In total they comprise of more than 50 webcams and more than 500 stationary and mobile sensors at over 60 locations. Over the next 6 years, the number of sensors at the James Reserve will increase exponentially, as we become the technology proving grounds for the entire National Ecological Observatory Network (NEON).
Short list of the KML layer's features:
- Access to current
sensor values across the Reserve
- External links for graphing
of historical micro-climate conditions
- A 'heads-up' or 'bulletin board' view of 28
active webcams
- GIS layers (contours, aspect/slope/hillshade/DEM) and
maps of plant community distributions
- Polygon representation of sensor systems for KML 2.0
- Sketchup Collada Models of sensor systems for KML 2.1
Some details about the KML PHP script :
My PHP scripts can be easily tuned to output several different KML options:
- Will generate either KML 2.0 or 2.1 on-demand
- "Live" KMZs where all webcams images, sensor
"sparklines", and overlays are
downloaded on-demand from our webserver. These can be refreshed every 5 minutes
for new sensors values and images.
- "Complete" KMZs that package up all the images,
sparklines, GIS layers, GroundOverlays and Collada models (for KML 2.1) for
viewing without internet connections (and more reliable demos!)
- Optional inclusion of a custom <Schema> that will
encode all of the sensors values and site-related info as custom KML tags
(for RSS feeds, XSLT transformations, and eventually descriptions generated
entirely with <BalloonStyles>).
- Caching features allow the creation of a new KMZ file only
every 5 minutes; helps to prevent database strain during heavy traffic.
- Debugging features that make it easy for admins to look at the incoming data values and troubleshoot KML problems.
![]()
some screen shots of the KML 2.0 version of the layer
PHP class for KML generation:
In order to efficiently generate KML, I recently wrote a small OO PHP class that validates KML schema relationships and tag values. This idea was originally inspired by the now abandoned work of TJ1, a once active member of the Keyhole BBS. Though TJ's work was quite complex and full-featured, several problems were beyond my repair and it only supported KML 2.0. Thus I decided to write my own class. Though not as glorious and 'professional' as TJ's promised to be, it has served me quite well.
Here is the source code for the php class.
KmlClass usage:
<?php
include_once("kml_class4.php");
/*
When creating a new KML element, all the required
children must be included at instantiation.
Optional Children can included afterwards
*/
$doc = new KmlClass(
'#create root <document> element', //internal name or comment
'Document', //KML tag name
array('name' => 'My kml Layer'), //array of child tags: 'child tag' => 'value'
array('id' => 'documentId') //'tag attrib' => 'value'
);
$coords = '-116, -30, 0';
$pt = new KmlClass(
'#coordinates for my house',
'Point',
array(
'coordinates' => $coords,
'altitudeMode' => 'relativeToGround'
)
);
$pl = new KmlClass(
'#my house',
'Placemark',
array(
'name' => 'Home',
'Snippet' => '',
'visibility' => 0,
'styleUrl' => '#myStyle',
'Point' => $pt,
'description' => 'Here is the house I grew up in...')
);
$doc->appendChild( array('Placemark' => $pl) );
/*
You can also pass in an array of Points/KML
tags if they are allowed to occur multiple times
$doc->appendChild( array('Placemark' => array($pl, $pl2, $pl3)) );
*/
$kml_output = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$kml_output = '<kml xmlns="http://earth.google.com/kml/2.0">' . "\n";
generate_kml($kml_output, $doc); //Global function from kml_classX.php
$kml_output .= '</kml>';
echo $kml_output;
?>
KML output:
<kml xmlns="http://earth.google.com/kml/2.0">
<Document id="documentId">
<name>My kml Layer</name>
<Placemark>
<name>Home</name>
<Snippet></Snippet>
<visibility>0</visibility>
<styleUrl>#myStyle</styleUrl> <Point>
<coordinates>-116, -30, 0</coordinates>
<altitudeMode>relativeToGround</altitudeMode>
</Point>
<description>Here is the house I grew up in...</description>
</Placemark>
</Document>
</kml>
