Skip to content

Instantly share code, notes, and snippets.

@bmcbride bmcbride/README.md
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.