-
Notifications
You must be signed in to change notification settings - Fork 1
/
bboxshow
executable file
·54 lines (48 loc) · 1.4 KB
/
bboxshow
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
#!/usr/bin/env bash
PROGRAM_NAME=$(basename "$0")
# shellcheck disable=SC2124
BBOX="${@}"
BBOX="${BBOX:--}"
BBOX="${BBOX//[[:space:]]/}"
function usage {
echo "Display bounding box in browser using bboxfinder.com"
echo ""
echo "usage: $PROGRAM_NAME <bbox>"
echo " arguments:"
echo " - <bbox>: \$minx,\$miny,\$maxx,\$maxy[,\$epsg] default in EPSG:4326 (arg or stdin)"
exit 1
}
set -euo pipefail
function open_url() {
local bbox min_x max_x min_y max_y url
bbox=$1
epsg_code=$(echo "$bbox" | awk -F, '{print $5}')
if [[ -n $epsg_code ]]; then
bbox=$(echo "$bbox" | awk -F, '{print $1,$2,$3,$4}' | tr ' ' ',')
bbox=$(bboxproj "$epsg_code" 4326 "$bbox")
fi
min_x=$(echo "$bbox" | awk -F, '{print $1}')
min_y=$(echo "$bbox" | awk -F, '{print $2}')
max_x=$(echo "$bbox" | awk -F, '{print $3}')
max_y=$(echo "$bbox" | awk -F, '{print $4}')
url="http://bboxfinder.com/#${min_y},${min_x},${max_y},${max_x}"
echo "$url"
if command -v xdg-open &>/dev/null; then
xdg-open "$url"
elif command -v gnome-open &>/dev/null; then
gnome-open "$url"
fi
}
if [[ $BBOX == "-" ]]; then
# BBOX passed on stdin
if [ -t 0 ]; then
# if do not allow interactive tty
usage
fi
while read -r line; do
open_url "$line"
done <"/dev/stdin"
else
# BBOX passed as argument
open_url "$BBOX"
fi