Skip to content

Instantly share code, notes, and snippets.

@atomotic
Created October 19, 2017 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomotic/1115cb16e8375a9d8f74b125c054e647 to your computer and use it in GitHub Desktop.
Save atomotic/1115cb16e8375a9d8f74b125c054e647 to your computer and use it in GitHub Desktop.
save into an sqlite database data of the first trackpoint of a gpx track using openstreetmap reverse nominatim
#!/usr/local/Cellar/bash/4.4.12/bin/bash
# sqlite3 tracks.db "CREATE TABLE tracks ( id integer primary key, gpxfile varchar, osm json)"
GPX=$1
echo "$GPX"
COORD=$(xml sel -N x=http://www.topografix.com/GPX/1/1 -t -v "//x:trkpt[1]/@*" "$GPX")
readarray -t y <<<"$COORD"
LAT=${y[0]}
LON=${y[1]}
OSM=$(curl -s "http://nominatim.openstreetmap.org/reverse?format=json&lat=$LAT&lon=$LON&zoom=18&addressdetails=1")
sqlite3 tracks.db "INSERT INTO tracks (gpxfile, osm) VALUES ('$GPX', '$OSM');"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment