Hpricot + GeoRSS + KML

May 15 by Andre

ShapeWiki now supports import for both KML and GeoRSS. GeoRSS testing is a bit sketchy, as I had a hard time finding GeoRSS feeds with shapes in them.

To import shapes from either GeoRSS or KML, go to the KML Import tab on the top of the page.

With KML import, you can now use Google MyMaps to build shapes, and import the shapes directly into ShapeWiki. Give it a try by 1) creating new map at maps.google.com; 2) using the shape tool to create one or may shapes on your map; 3) copying the URL (via "link to this page" on Google Maps) into the ShapeWiki import.

The import code is straightforward. I use Hpricot for XML parsing, as it makes dealing with XML marginally bearable. I check if the shapes are in folder(s), and if they are, I use the folder names for tags. To make his work, I added an #ancestors method to Hpricot's Elem:

module Hpricot
  class Elem
    def ancestors
      element=self
      path=Hpricot::Elements.new
      while element.class != Hpricot::Doc do
        path.push element
        element = element.parent
      end
      path
    end
  end
end

. . . which returns a nice Elements array of all the ancestors of the element on which it was called. I use it like so:

shape.tag_list=p.ancestors.search('/folder/name').map{|e|e.inner_html.strip.gsub(' ','_').downcase}.uniq.join(' ')

I was a bit surprised that Hpricot's Elem didn't already have an ancestor method. If I missed something, or there's an easier way to do this, drop me a comment!

Post a comment

 
This is so filters can reject the spam-bots. Thanks!