Converting point data to Google Earth - For Application Development
The point data application receives an XML stream based on this schema . The annotations in the schema give application developers direction on the use of the various elements. The example code provided is for the PHP language using a variable called $v_xml.
1. The first step within your programming code is to intialize the xml variable with header information. For example:
$v_xml = '<?xml version="1.0" encoding="UTF-8"?>';
$v_xml .= '<response><header>
<description>Canadian records of Vanessa, Lepidoptera</description>
<url>http://www.laep.org/uclasp/ISSUES/butterflies/images/redadmiral.gif</url>
<title>Vanessa</title>
</header><records>';
2. The next step is to build the one to many <record> complex type elements and fill them with point data and optional URL's and short descriptions for particular records . The following PHP code shows an
example of how to populate individual simple type elements in each <record>. In this case array variables have already been populated with the appropriate data. A test could be done on both <recordurl> and <recordname> so they are only added if there are data available [eg. if (strlen($recordurl[$i] > 0)) ]. Note: In the <recordurl> element use & between name/value pairs and not simply an &.
$numrows = count($lat);
for ($i = 0 ; $i < $numrows; ++$i) {
$v_xml .= '<record><longitude>' .trim($long[$i]).'</longitude>';
$v_xml .= '<latitude>' .trim($lat[$i]).'</latitude>';
$v_xml .= '<recordurl>' .trim($recordurl[$i]).'</recordurl>';
$v_xml .= '<recordname>' .trim($recordname[$i]).'</recordname></record>';
}
3. Now close the XML stream so that it is valid and well-formed:
$v_xml .= '</records></response>';
4. From your application, POST the XML stream as the name/value pair to http://www.cbif.gc.ca/mapdata/kml/point-reflector.php?xml=<your-xml-stream>. Note that the XML stream has to be urlencoded. For example, in PHP language this is easy. If your xml stream is contained in a variable called $v_xml then the following code will accomplish this:
echo '<INPUT type="hidden" name="xml" value="' . urlencode($v_xml) . '">';
This *Map It!* button has a sample urlencoded XML stream that will be converted to a file for Google Earth. The icon image is retrieved from the Internet (see the <url> tag example above). Click on an icon to see a popup box with a link that retrieves biological record information from the Species Access Canada website and presents that in a browser either in Google Earth or separately. If you view source on this document you will see what the urlencoded XML stream looks like.
These scripts have been contributed by Derek Munro of the Canadian Biodiversity Information Facility (CBIF) to GBIF beginning on 2005-09-28. More...
|