From 0b3cb91a99aedaf6fa87ba6d4c23367e396694db Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 26 Jul 2020 13:03:26 +0800 Subject: Add gpx2geojson.sh --- tools/gpx/gpx2geojson.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 tools/gpx/gpx2geojson.sh (limited to 'tools') diff --git a/tools/gpx/gpx2geojson.sh b/tools/gpx/gpx2geojson.sh new file mode 100755 index 0000000..eefcf5e --- /dev/null +++ b/tools/gpx/gpx2geojson.sh @@ -0,0 +1,48 @@ +#! /bin/bash + +<$1 xq '.gpx | + ( + label $out | + if .wpt != null then [.wpt] else break $out end | + flatten[] | + { + type: "Feature", + properties: { name: .name }, + geometry: { + type: "Point", + coordinates: [ + (.["@lon"]|tonumber), + (.["@lat"]|tonumber), + (.ele | if . == null then null else tonumber end) + ] + } + } + ), + ( + label $out | + if .trk != null then [.trk] else break $out end | + flatten[] | + { + type: "Feature", + properties: { name: .name }, + geometry: { + type: "MultiLineString", + coordinates: + [.trkseg] | flatten | map( + .trkpt | map( + [ + (.["@lon"]|tonumber), + (.["@lat"]|tonumber), + (.ele | if . == null then null else tonumber end) + ] + ) + ) + } + } + ) +' | jq -s ' + { + type: "FeatureCollection", + features: . + } +' -- cgit v1.2.3-70-g09d2