aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/gpx/gpx2geojson.sh
blob: eefcf5eecdcb53d0410d19c0c6380d888febc397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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: .
  }
'