diff options
author | Hsieh Chin Fan <typebrook@gmail.com> | 2020-07-26 13:03:26 +0800 |
---|---|---|
committer | Hsieh Chin Fan <typebrook@gmail.com> | 2020-07-27 00:29:14 +0800 |
commit | 0b3cb91a99aedaf6fa87ba6d4c23367e396694db (patch) | |
tree | 2456b4beb9f196277a0297580b6f6e5464b18766 | |
parent | c28706dcfd2f2c7175306d228b351b709573a5a4 (diff) |
Add gpx2geojson.sh
-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 | ' | ||