~mil/mepo

ref: 041d978478ae78e241802ca9d750677e101c3f5b mepo/scripts/mepo_ui_menu_route_overpassrelation.sh -rwxr-xr-x 1.8 KiB
041d9784Miles Alan Show progress in % complete for transfer datum on tiles while downloading 5 months ago
                                                                                
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env sh
DISPLAYNAME=" Route: via OSM Relation / Public Transit"
HOTKEY=R

RELATIONS="
  NYC Subway A: 9727210
  NYC Subway C: 366775
  NYC Subway E: 366776
  NYC Subway 1: 364630
  NYC Subway 2: 9655663
  NYC Subway 3: 366784
  Mexico City 1: 443191
  Mexico City 2: 443229
  Mexico City 3: 443206 
"

main() {
  RELATIONID="$(
    echo "$RELATIONS" |
      awk '{$1=$1};1' | 
      grep . | 
      PROMPT="Relation (or enter custom relation id):"  mepo_ui_helper_menu.sh |
      grep -oE "[0-9^]+$"
  )"

  JSON_RESULTS="$(
    curl  "https://lz4.overpass-api.de/api/interpreter" --data-raw "data=$(
      echo '
        [out:json][timeout:25];
        rel(RELATIONID);
        (._;>>;);
        out+body;
        >;
        out+skel+qt;
      ' | sed "s/RELATIONID/$RELATIONID/g"
    )"
  )"

  # E.g. get order of reference ids in relation
  SORTED_REFS="$(
    echo "$JSON_RESULTS" | 
      jq '.elements | .[] | select(.type=="relation") | .members | .[].ref'
  )"
  FILEREFSORDER="$(mktemp)"
  echo "$SORTED_REFS" > "$FILEREFSORDER"

  # E.g. get all nodes with tags
  NODES="$(
    echo "$JSON_RESULTS" |
      jq '.elements | .[] | "\(.lat) \(.lon) \(.id)" ' |
      tr -d \" |
      grep -vE 'null$' |
      grep -vE '^null' |
      awk -F' ' '{lat=$1; lon=$2; id=$3; $1=""; $2=""; $3=""; gsub(/^[ \t]+/,"",$0); print id " " lat " " lon " [] [" $0 "]"}'
  )"
  FILENODES="$(mktemp)"
  echo "$NODES" > "$FILENODES"

  echo "
    prefset_n pingroup_1_ordered 1;
    pin_groupactivate 1;
    pin_purge;
  "

  # Sort nodes based on reference ids, delete first item, only show printable chars
  # and pin add each entry
  awk 'FNR==NR {x2[$1] = $0; next} $1 in x2 {print x2[$1]}' "$FILENODES" "$FILEREFSORDER" |
    cut -f 2- -d ' ' |
    sed 's/[^[:print:]]//g' |
    xargs -ID echo 'pin_add -1 0 D;'
}

if [ -n "$1" ]; then "$@"; else main; fi