Generating KML with RSSBus

RSSBus is good for more than just generating RSS feeds or helping you easily create an API for your data or services. Its also useful in easily outputting other formats as well, such as KML (an XML format for Google Earth).

For example, recently Tim posted an example of using XmlTextWriter to generate KML. For most of ius, its not rocket science, but compare his code and the ease of writing it with how it can be done with RSSBus. With RSSBus you can just literally write the XML and plug-in the values you want to change with variables like [icon], etc.

Tim's example takes three querystring variables: lon (a longitude coordinate), lat (a latitude coordinate), and icon (an icon to mark the location in Google Earth). Below is the same example as an RSSBus template. Simply hit the template with your own lat, lon, and icon, and the KML is generated and opened on your machine. If you do not provide a lat, lon, and icon it will default to Bank of America Stadium where the Carolina Panthers win.

You can hit this script live here.

Also check out FeedMapper, which can also generate KML (as well as Virtual Earth and Yahoo maps) for entire feeds.

<rsb:allow user="*" host="*"/>

<!-- This script takes the following optional inputs from the querystring:
lat - latitude of geographic point
lon - longitude of geographic point
icon - url of icon that will plot the point
-->

<!-- Set the content type for kml -->
<rsb:set item=_httpheaders attr="Content-Type" value="application/vnd.google-earth.kml+xml"/>

<!-- check for required inputs, or set defaults -->
<rsb:set attr="lat" value="[lat | def('35.2257')]" />
<rsb:set attr="lon" value="[lon | def('-80.8531')]" />
<rsb:set attr="icon" value="[icon | def('http://www.textbox1.com/examples/panthers.jpg')]" />

<xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
  <Snippet>KML generated by RSSBus</Snippet>
  <description>KML Demo</description>
  <name>KML Demo</name>
  <LookAt>
    <longitude>[lon]</longitude>
    <latitude>[lat]</latitude>
    <range>300</range>
    <tilt>20</tilt>
    <heading>0</heading>
  </LookAt>
  <visibility>1</visibility>
  <Style>
    <IconStyle>
      <Icon>
        <href>[icon]</href>
        <w>-1</w>
        <h>-1</h>
      </Icon>
    </IconStyle>
  </Style>
  <Point>
    <extrude>1</extrude>
    <altitudeMode>relativeToGround</altitudeMode>
    <coordinates>[lon], [lat], 0</coordinates>
  <Point>
<Placemark>
<kml>

Technorati : , , ,

Print | posted on Monday, October 2, 2006 9:23 AM

Feedback

# re: Generating KML with RSSBus

Left by Tim Hibbard at 10/2/2006 9:54 AM
Gravatar My next post is going to be titled, "If you don't like how I'm doing this, wait 3 days and Lance will show you an easier way with RSSBus" :)

Nice touch carrying on the football stadium trend.

I've been looking to redo how I handle KML history in Where's Tim now that timestamps are supported, I should use RSSBus for that.

Your comment:





 
 

Copyright © Lance Robinson

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski