~mil/mepo

ref: 041d978478ae78e241802ca9d750677e101c3f5b mepo/scripts/mepo_ui_menu_reposition_nominatim.sh -rwxr-xr-x 1.0 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
#!/usr/bin/env sh
DISPLAYNAME=" Relocate map: via search"
HOTKEY=g

err() {
  echo "$@" >&2
  exit 1
}

main() {
  OPTIONS='
    Cancel
    Amsterdam
    Paris
    NYC
    Boston
    India
    Romania
    Iraq
  '

  QUERY="$(
    echo "$OPTIONS" |
      awk '{$1=$1};1' | 
      grep . | 
      PROMPT="Nominatim Relocate" mepo_ui_helper_menu.sh |
      sed 's/ /%20/g'
  )"

  [ "$QUERY" = "Cancel" ] && exit
  echo "$QUERY" | grep -q . || err "Blank search query"

  RESULT="$(
    curl "https://nominatim.openstreetmap.org/search?format=json&q=$QUERY" |
      jq '.[] | "\(.display_name) \(.lat) \(.lon)" ' |
      PROMPT="Pick result" mepo_ui_helper_menu.sh 
  )"

  COORDS="$(
    echo "$RESULT" |
    grep -oE '[-0-9.]+' |
    tail -n2 |
    tr "\n" " "
  )"

  [ -z "$COORDS" ] && {
      echo "Failed to determine COORDS from: $RESULT" >&2
      exit 1
  }

  LAT="$(echo "$COORDS" | cut -d ' ' -f1)"
  LON="$(echo "$COORDS" | cut -d ' ' -f2)"
  echo "prefset_n lat $LAT;"
  echo "prefset_n lon $LON;"
}

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