DAV-Felsinfo data as GPX track (or other formats)

August 12, 2018

We want to go climbing…

The website of the DAV has a nice list of rocks with descriptions and coordinates, but is not optimized for mobile/offline use. Ideally I would like to have the list of all rocks in my navigation app on my phone (OsmAnd in my case). Thus I wrote a small script which scapes their website and generates a GPX file with the rocks.

The website is parsed using Nokogiri:

def read_page(url)
    page = Nokogiri::HTML(open(url))
    /(?<name>Fels.*)/ =~ page.css('title').text
    info_text = page.css('#allgemein > div .kategorie_titel,.felsinfo').text
    /Geogr.\ Länge\s*(?<longitude>\d+\.\d+)\s*°/m =~ info_text
    /Geogr.\ Breite\s*(?<latitude>\d+\.\d+)\s*°/m =~ info_text
    {
        name: name,
        url: 'http://%s' % url,
         latitude: latitude,
        longitude: longitude,
    }
end

And the result is passed to rubys templating engine:

def template_binding(rocks)
    include ERB::Util
    binding
end

puts ERB.new(File.read(options[:template])).result(template_binding(rocks))

This allows to define arbitrary templates. In my case I am mostly interested into GPX:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="Wikipedia"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
    <% for @rock in rocks.select { |x| x[:latitude] != nil } %>
        <wpt lat="<%= @rock[:latitude] %>" lon="<%= @rock[:longitude] %>">
            <name><%= html_escape(@rock[:name]) %></name>
            <cmt><%= html_escape(@rock[:url]) %></cmt>
        </wpt>
    <% end %>
</gpx>

Loaded into OsmAnd this allows me to view all rocks on the map as well as access the original page with the full info:

In the end, here is a GPX file including all the rocks. The code is available at https://gitlab.com/ablu/felsinfo-exporter.