-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforest_hillshade.sh
executable file
·184 lines (158 loc) · 3.92 KB
/
forest_hillshade.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
# ksh or bash or ...
# forest_hillshade.sh
#
# Copyright 2024 Karjalan ATK-Awot Oy
# Jukka Inkeri
# https://github.com/kshji/awgeo
# https://awot.fi
#
# Make hillshade tiff from LAZ and forest "spike free" png
# ground hillshade and forest "hillshade"
#
# $AWGEO/forest_hillshade.sh -z ZNUM -o outputdir inputlazfile(s)
# $AWGEO/forest_hillshade.sh -o tulos ../P*.laz
# $AWGEO/forest_hillshade.sh -z 3 -o tulos ../P*.laz
# $AWGEO/forest_hillshade.sh -z 3 -o tulos -d 1 ../P*.laz
#
VER="2024-11-17.a"
#
#
#
PRG="$0"
BINDIR="${PRG%/*}"
[ "$PRG" = "$BINDIR" ] && BINDIR="." # - same dir as program
PRG="${PRG##*/}"
DEBUG=0
########################################################
usage()
{
cat <<EOF >&2
usage:$PRG [ -z NUM ] [ -o outputdir ] lazfile(s)
- z NUM , default is 3
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/}"
}
########################################################
clear_result()
{
rm -f "$result".tif "$result".ground.laz 2>/dev/null
}
################################################################
# defaults
set_def()
{
z=3
}
########################################################
# MAIN
########################################################
inf=""
set_def
mkdir -p tmp 2>/dev/null
id=$$ # process number = unique id for tempfiles
TEMP="tmp/$id"
outputdir="."
force=0
# parse cmdline options
while [ $# -gt 0 ]
do
arg="$1"
case "$arg" in
-d) DEBUG="$2"; shift ;;
-z) z="$2"; shift ;;
-o) outputdir="$2" ; shift ;;
-f) force=1;;
-v) echo "$PRG Ver:$VER" >&2 ;;
-h) usage ; exit 1 ;;
-*) usage ; exit 1 ;;
*) break ;; # filenames
esac
shift
done
mkdir -p "$outputdir" 2>/dev/null
[ $# -lt 1 ] && usage && exit 1
# for loop input files
for lazf in $@
do
dbg "$lazf"
[ ! -f "$lazf" ] && continue
fname=$(getfile "$lazf")
name=$(getbase "$fname" .laz)
dbg " file:$lazf fname:$fname name:$name outputdir:$outputdir"
cp -f "$lazf" $id.tmp.laz
inf="$id.tmp.laz"
# if not exists result file or force = do it
(( force > 0 )) && rm -f "$outputdir/$name.hillshade.tif" 2>/dev/null
dbg "$name hillshade"
if [ ! -f "$outputdir/$name.hillshade.tif" ] ; then
dbg $AWGEO/hillshade.sh -i "$inf" -o "$id.tmp" -z "$z"
((DEBUG<2)) && $AWGEO/hillshade.sh -i "$inf" -o "$id.tmp" -z "$z"
((DEBUG<2)) && cp -f "$id.tmp.tif" "$outputdir/$name.hillshade.tif" 2>/dev/null
fi
# if not exists result file or force = do it
dbg "$name forest"
(( force > 0 )) && rm -f "$outputdir/$name.forest.png" 2>/dev/null
if [ ! -f "$outputdir/$name.forest.png" ] ; then
dbg $AWGEO/forest.sh -i "$lazf" -o "$outputdir" -d $DEBUG
((DEBUG<2)) && $AWGEO/forest.sh -i "$lazf" -o "$outputdir" -d $DEBUG
fi
rm -f "$id.tmp.*" 2>/dev/null
done
status "done, $outputdir/*.hillshade.tif"