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.
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!
With such a well-defined specification, building the app in Fulcrum literally took about 15 minutes.
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
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.