Logo preload
close Logo

Designing An OpenTrails Compatible App

August 13, 2014

We recently received an inquiry from our friends at Code For America who suggested designing an app for documenting trailhead information which would be compatible with their new Open Trail System Specification. The OpenTrails initiative seeks to “provide a uniform exchange format for publishing machine readable data on the extent, attributes, and use of our nation’s trail systems”. The goal is to help facilitate the open exchange and use of trail data between various stakeholders, including data stewards, trail managers, government agencies, and public users.

App Dashboard

A Modern, Logical Specification

According to the documentation, the OpenTrails specification is “designed to provide a wieldy format for web and application developers”. The spec includes detailed data schemas for Trail Segments, Trailheads, and Administrative Areas. GeoJSON is the required format for spatial data while non-spatial data (lookup tables for Stewards and Named Trails) should be stored in CSV files.

While CFA is working on developing a suite of tools for converting existing trail data shapefiles into OpenTrails compliant files, many municipalities and park governments lack good trailhead data to begin with. This is a perfect use case for Fulcrum!

From Spec to App

With such a well-defined specification, building the app in Fulcrum literally took about 15 minutes.

Trailheads Spec

Trailheads Schema

Trailheads App

Trailheads App

  • The Trail ID’s multiple choice field pulls values from a Named Trails choice list, which contains the name and id fields imported from the standard named_trails.csv file.
  • The Trail Steward single choice field pulls values from a Stewards choice list, which contains the name and id fields imported from the standard stewards.csv file.
  • The OSM Tag key-value pairs are handled by nesting a classification set inside a repeatable field. The classification set includes a key-value hierarchy of recommended osm tags.

Post-processing Fulcrum Exports

This app allows us to collect all the information required, but the Fulcrum export still requires some minimal processing in order to generate the proper trailheads.geojson file per the spec. This post-processing can easily be accomplished using the excellent ogr2ogr utility, which is part of the open source Geospatial Data Abstraction Library (GDAL). Basically, we need to join the osm_tags table and replace commas with semicolons. I’ve outlined the post-processing steps in the following bash script to help automate this task.

#!/bin/bashogr2ogr -f “SQLite” opentrails-trailheads.sqlite -nln “trailheads” -a_srs “EPSG:4326” opentrails_trailheads.shpogr2ogr -update -f “SQLite” opentrails-trailheads.sqlite -nln “osm_tags” opentrails_trailheads_osm_tags.dbfogr2ogr -f “GeoJSON” -sql “SELECT geometry, name, id, replace(segment_ids, ‘,’, ‘; ‘) AS segment_ids, steward_id, area_id, address, parking, drinkwater, restrooms, kiosk, GROUP_CONCAT(replace(osm_tag, ‘,’, ‘=’), ‘; ‘) AS osm_tags FROM trailheads JOIN osm_tags ON trailheads.fulcrum_id = osm_tags.fulcrum_pa” trailheads.geojson opentrails-trailheads.sqliteogr2ogr -f “CSV” -sql “SELECT geometry, name, id, replace(segment_ids, ‘,’, ‘; ‘) AS segment_ids, steward_id, area_id, address, parking, drinkwater, restrooms, kiosk, GROUP_CONCAT(replace(osm_tag, ‘,’, ‘=’), ‘; ‘) AS osm_tags FROM trailheads JOIN osm_tags ON trailheads.fulcrum_id = osm_tags.fulcrum_pa” trailheads.csv opentrails-trailheads.sqlite

view rawfulcrum-trailheads.sh hosted with ❤ by GitHub

Summary

This exercise demonstrates the power of integrating well-defined, easily-accessible open data specifications with Fulcrum’s ability to quickly build highly-customizable data collection apps. The OpenTrails Trailheads app is up on the App Gallery and available for you to start collecting data today.

For more information regarding the OpenTrails initiative, join their Discussion Group. As always, if you’ve got a suggestion for the Fulcrum App Gallery, email us & let us know.