I just uploaded the source code for this library, used in the Virtual Earth mash-up described in my previous post. You can browse/download it from here.

What you will find:

  • A simple domain model for GeoRSS feeds with support for points, lines and polygons; links and icons

GeoRssData geoData = new GeoRssData("Mount Saint Helens", "Trailheads and campsites in the Mount Margaret area of Mt. Saint Helens, WA");

geoData.AddPoint( "Lakes Trailhead", "This is where we started our hike", 46.2913246, -122.2658157 );

polygon = geoData.AddPolygon("Coldwater Lake", "Formed by the 1980 eruption of Mount St. Helens.", "46.31409 -122.22616 46.31113 -122.22968 46.31083 -122.23320 46.29802 -122.25877 46.29245 -122.26641 46.29286 -122.26392 46.28746 -122.26744 46.28741 -122.26006 46.29049 -122.25955 46.29120 -122.25620 46.28924 -122.255430 46.30271 -122.23251 46.31284 -122.22315 46.31409 -122.22616")

polygon.Link = "http://somelink”;

The GeoRssData provides common methods for creating the shapes and passing the information (like coordinates). For example, AddLine and AddPolygon methods come in two versions: one that takes a Point[] and another that takes a string:

public GeoRssLineItem AddLine(string itemTitle, string itemDescription, Point[] line);

public GeoRssLineItem AddLine(string itemTitle, string itemDescription, string line);

The latter is convenient if you persist your information in a single field in a database for example, as I’m doing in LitwareHR.

There are also simple validations like point should have 2 coordinates, lines should have an even number of coordinates, strings should be parsed as doubles, etc.

SyndicationFeed feed = GeoRssFeedBuilder.GetFeed(geoData)

The feed can then be passed to Rss20FeedFormatter.

  • Unit tests for all with +99% coverage:
image image
  • A very simple sample demonstrating how to use it (besides the tests which are self explanatory)

Final notes:

I liked the System.Xml.Linq classes very much. In my original implementation I assembled the Xml elements by hand, concatenating strings, etc. mainly because I couldn’t find a way of programmatically constructing them in the way Virtual Earth likes (e.g. all georss elements have to use the namespace “georss”, the elements must be fully qualified, etc.). Using XElement & XAttribute was straightforward and compact:

XNamespace grns = "http://www.georss.org/georss";
XElement x = new XElement(grns + "point", new XAttribute(XNamespace.Xmlns + "georss", grns.NamespaceName ), 10, 20 );

will serialize as:

<georss:point xmlns:georss=”http://www.georss.org/georss”>10 20</georss:point>

The model should be fairly simple to extend to include support for other elements (radius, etc). or even the broader set of attributes in the SyndicationFeed class and related cousins. I hope you find it useful.