Mapping a GeoRSS Feed

Written by Andrew Burnes

Using the traffic incident data from the City of Charlotte’s RSS Feed to transform and map incident geodata.

Background

Many different local, state, and federal governments use RSS/GeoRSS feeds to keep the public and stakeholders informed. To use a location based GeoRSS feed for modern web mapping, the feed has to be converted from XML to JSON/GeoJSON to integrate easily with a variety of open source mapping libraries. The test feed is brought to us by the Charlotte, NC… “Charlotte’s Got A Lot.”

The feed can be found at http://maps.cmpd.org/datafeeds/accidentsgeorss.ashx. This feed comes to me from Danny Whalen who is a 2014 Code for America fellow working with the City of Charlotte to build innovative civic apps.

Putting Node.js to Work

To retrieve the feed, transform the data, and map the incidents, I will be using Node.js and the source can be found at https://github.com/apburnes/clt_crash_map.

Get and Transofm the GeoRSS

Dependencies
Install

npm install request

npm install xml2js

Get the Data
#!/bin/env node
/*** getFeed.js ***/

// Require and utilize the dependencies
var request = require('request');
var parseString = require('xml2js').parseString

// The location of the GeoRSS feed
var url = "http://maps.cmpd.org/datafeeds/accidentsgeorss.ashx";

// Get and convert GeoRss XML to an array of objects
function getGeoRss(url, done) {
  request(url, function(err, res, body) {
    if (err) return log(err);
    parseString(body, function(err, result) {
      if (err) return log(err);
      var events = result.rss.channel[0].item;
      done(null, events);
    });
  });
}

function log(msg) {
  console.log(msg);
}

exports.getGeoRss = getGeoRss;
Console Output
[{"type": "Feature",
  "properties": [{
    "title": "TRAFFIC CONTROL/MALFUNCTION at 707  PAVILION BV ",
    "eventNum": "O0529164400",
    "dateAdded": "5/29/2014 4:44:16 PM",
    "division": "UNIVERSITY CITY",
    "address": "707  PAVILION BV ",
    "eventType": "TF-CNTRL",
    "eventDesc": "TRAFFIC CONTROL/MALFUNCTION"
  }],
  "geometry": [{
    "type": "Point",
    "coordinates": [
      "-80.710670",
      "35.327362"
    ]
  }]
}, ...]