-
Notifications
You must be signed in to change notification settings - Fork 0
/
xy2wkt.sh
executable file
·73 lines (63 loc) · 1.2 KB
/
xy2wkt.sh
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 bash
# ksh or bash or ...
# xy2wkt.sh
#
# Copyright 2024 Karjalan ATK-Awot Oy
# Jukka Inkeri
#
# Convert polyline x y coordinates textfile to the wkt polygon format
#
# Usage:
# cat area.txt | xy2wkt.sh > area.wkt
# xy2wkt.sh -i area.txt -o area.wkt
#
VER="2024-11-05.a"
#
#
PRG="$0"
BINDIR="${PRG%/*}"
[ "$PRG" = "$BINDIR" ] && BINDIR="." # - same dir as program
PRG="${PRG##*/}"
DEBUG=0
########################################################
usage()
{
cat <<EOF >&2
usage:$PRG -i input.txt -o outname.wkt
or using pipes:
cat input.txt | $PRG > outname.wkt
EOF
}
########################################################
make_wkt()
{
Zin="$1"
echo -n "POLYGON (("
delim=""
while read x y
do
echo -n "$delim$x $y"
delim=","
done < $Zin
echo "))"
}
########################################################
# MAIN
########################################################
# default is pipe
inf="/dev/stdin"
result="/dev/stdout"
# parse cmdline options
while [ $# -gt 0 ]
do
arg="$1"
case "$arg" in
-i) inf="$2"; shift ;;
-o) result="$2"; shift ;;
-v) echo "$PRG Ver:$VER" >&2 ;;
-h) usage ; exit 1 ;;
-*) usage ; exit 1 ;;
esac
shift
done
make_wkt "$inf" > "$result"