Skip to content

Instantly share code, notes, and snippets.

@bmcbride
Last active August 29, 2015 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmcbride/920e45c82f16563c7618 to your computer and use it in GitHub Desktop.
Save bmcbride/920e45c82f16563c7618 to your computer and use it in GitHub Desktop.
Post-processing scripts for generating OpenTrails compliant Trailheads CSV & GeoJOSN files from the Fulcrum OpenTrails Trailhead App- http://fulcrumapp.com/apps/opentrails-trailheads

Data exported out of the Fulcrum OpenTrails Trailhead App requires some post processing in order to generate the proper files, per the OpenTrails trailheads.geojson specification. Simply export as Shapefile and execute the following GDAL/OGR commands:

ogr2ogr -f "SQLite" opentrails-trailheads.sqlite -nln "trailheads" -a_srs "EPSG:4326" opentrails_trailheads.shp
ogr2ogr -update -f "SQLite" opentrails-trailheads.sqlite -nln "osm_tags" opentrails_trailheads_osm_tags.dbf
ogr2ogr -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.sqlite
ogr2ogr -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

Execute the fulcrum-trailheads.sh bash script from the same directory as the exported Shapefiles file to generate both CSV and GeoJSON files.

#!/bin/bash
ogr2ogr -f "SQLite" opentrails-trailheads.sqlite -nln "trailheads" -a_srs "EPSG:4326" opentrails_trailheads.shp
ogr2ogr -update -f "SQLite" opentrails-trailheads.sqlite -nln "osm_tags" opentrails_trailheads_osm_tags.dbf
ogr2ogr -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.sqlite
ogr2ogr -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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment