diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/gpx/gpx2geojson.sh | 48 |
1 files changed, 48 insertions, 0 deletions
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 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | <$1 xq '.gpx | | ||
4 | ( | ||
5 | label $out | | ||
6 | if .wpt != null then [.wpt] else break $out end | | ||
7 | flatten[] | | ||
8 | { | ||
9 | type: "Feature", | ||
10 | properties: { name: .name }, | ||
11 | geometry: { | ||
12 | type: "Point", | ||
13 | coordinates: [ | ||
14 | (.["@lon"]|tonumber), | ||
15 | (.["@lat"]|tonumber), | ||
16 | (.ele | if . == null then null else tonumber end) | ||
17 | ] | ||
18 | } | ||
19 | } | ||
20 | ), | ||
21 | ( | ||
22 | label $out | | ||
23 | if .trk != null then [.trk] else break $out end | | ||
24 | flatten[] | | ||
25 | { | ||
26 | type: "Feature", | ||
27 | properties: { name: .name }, | ||
28 | geometry: { | ||
29 | type: "MultiLineString", | ||
30 | coordinates: | ||
31 | [.trkseg] | flatten | map( | ||
32 | .trkpt | map( | ||
33 | [ | ||
34 | (.["@lon"]|tonumber), | ||
35 | (.["@lat"]|tonumber), | ||
36 | (.ele | if . == null then null else tonumber end) | ||
37 | ] | ||
38 | ) | ||
39 | ) | ||
40 | } | ||
41 | } | ||
42 | ) | ||
43 | ' | jq -s ' | ||
44 | { | ||
45 | type: "FeatureCollection", | ||
46 | features: . | ||
47 | } | ||
48 | ' | ||