~mil/mepo

ref: 041d978478ae78e241802ca9d750677e101c3f5b mepo/scripts/mepo_ui_menu_search_nominatim.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
#!/usr/bin/env sh
DISPLAYNAME=" POI Search: via Nominatim"
HOTKEY=G

nominatimspecialphrasesfromwiki() {
  curl 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/EN' |
    grep '^| ' |
    grep -v '| -' |
    sed -E 's/\|\|.+$//g' |
    sed -E 's/^\| //g' |
    sort
}

main() {
  QUERY="$(
      printf %b "Cancel\nEnter specific POI name" |
      PROMPT="Nominatim Search" mepo_ui_helper_menu.sh |
      sed 's/ /%20/g'
  )"
  [ "$QUERY" = "Cancel" ] && exit
  if echo "$QUERY" | grep -qv . ; then
    echo "Invalid search query for nominatim: $QUERY" >&2
    exit 1
  fi

  VIEWBOX="$MEPO_TL_LON,$MEPO_TL_LAT,$MEPO_BR_LON,$MEPO_BR_LAT"
  JSONRESULTS="$(
    curl "https://nominatim.openstreetmap.org/search?format=json&q=$QUERY&viewbox=$VIEWBOX&bounded=1&limit=50&extratags=1"
  )"

  echo "
    prefset_n pingroup_0_ordered 0;
    pin_groupactivate 0;
    pin_purge;
  "

  # Add pin
  echo "$JSONRESULTS" |
    jq '
       map(
         .osm_id as $osmid |
         with_entries(
           if .key=="display_name" then
             .value = (.value | split(",")[0]) else
             .value = .value
           end
         ) | 
         "pin_add -1 0 \(.lat) \(.lon) [\($osmid)]; pin_meta -1 [\($osmid)] name [\(.display_name)];"
       )  | .[]
    ' |
    tr -d '"'

  # Add pin metadata
  echo "$JSONRESULTS" | jq '
    [
      map(
      .osm_id as $osmid | 
      with_entries(
        if .key=="display_name" then 
          .value = (.value | split(",")[0]) else 
          .value = .value 
        end
      ) |
      .display_name as $displayname |
      .extratags | with_entries(.value="pin_meta -1 [\($osmid)] [\(.key)] [\(.value)];") | map(.)
    ) | .[] ]  | flatten(3) | .[]
  ' |
  tr -d '",'

}

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