-
Notifications
You must be signed in to change notification settings - Fork 0
/
forest.sh
executable file
·151 lines (132 loc) · 3.09 KB
/
forest.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
# ksh or bash or ...
# forest.sh
#
# Copyright 2024 Karjalan ATK-Awot Oy
# Jukka Inkeri
#
# Make spike free digital surface model
# hillshade "forest"
#
VER="2024-11-17.a"
#
# using las2dem
#
#
# forest.sh -i lazfile -o outputdir -s step -d $DEBUG
# forest.sh -i P5331A4.laz
# - result file is ./P5331A4.forest.png
# forest.sh -i P5331A4.laz -o results
# - output to the dir results
#
# forest.sh -i P5331A4.laz -o results -s 0.25 -d 1
# - step 0.25, look las2dem option -step document
#
PRG="$0"
BINDIR="${PRG%/*}"
[ "$PRG" = "$BINDIR" ] && BINDIR="." # - same dir as program
PRG="${PRG##*/}"
DEBUG=0
########################################################
usage()
{
cat <<EOF >&2
$*
usage:$PRG -i input.laz [ -s STEP ] [ -o outputdir ] [ -d 0|1 ]
-d 0|1 debug, default is 0
-s NUM # step, default 0.5
-o outputdir, default is current
EOF
}
########################################################
step()
{
dbg "-step:$*"
}
########################################################
status()
{
dbg "-status:$*"
}
########################################################
err()
{
echo "err:$*" >&2
}
########################################################
dbg()
{
[ $DEBUG -lt 1 ] && return
echo " $*" >&2
}
################################################################
last_slash()
{
str="$*"
len=${#str}
((len-=1))
last=${str:$len:1}
[ "$last" = "/" ] && str=${str:0:len}
echo "$str"
}
################################################################
getdir()
{
str="$*"
strorg="$str"
[ "$str" = "/" ] && str=""
str=$(last_slash "$str")
# ei saa poistaa jos on jo hakemisto !!!
[ -d "$str" ] && print -- "$str" && return
#[ "$strorg" = "$str" ] && print -- "." && return
echo "${str%/*}"
}
################################################################
getfile()
{
str="$*"
echo "${str##*/}"
}
################################################################
getbase()
{
str="$1"
remove="$2"
echo "${str%$remove}"
#eval echo "\${str//$2/}"
}
########################################################
# MAIN
########################################################
inf=""
result=""
#step=0.25
step=0.5
outputdir="."
mkdir -p tmp "$outputdir" 2>/dev/null
id=$$ # process number = unique id for tempfiles
TEMP="tmp/$id"
# parse cmdline options
while [ $# -gt 0 ]
do
arg="$1"
case "$arg" in
-i) inf="$2"; shift ;;
-d) DEBUG="$2"; shift ;;
-o) outputdir="$2" ; shift ;;
-s) step="$2" ;: shift ;;
-v) echo "$PRG Ver:$VER" >&2 ;;
-h) usage ; exit 1 ;;
-*) usage ; exit 1 ;;
esac
shift
done
[ "$inf" = "" ] && usage "input laz?" && exit 1
mkdir -p tmp "$outputdir" 2>/dev/null
[ ! -f "$inf" ] && err "no file:$inf" && exit 3
fname=$(getfile "$inf")
name=$(getbase "$fname" ".laz")
result="${name}.forest.png"
dbg las2dem64 -i "$inf" -spike_free 0.9 -step "$step" -hillshade -o "$outputdir/$result"
las2dem64 -i "$inf" -spike_free 0.9 -step "$step" -hillshade -o "$outputdir/$result"
echo "result: $outputdir/$result"