-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaz2tif.sh
executable file
·150 lines (126 loc) · 2.96 KB
/
laz2tif.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
#!/usr/bin/env bash
# ksh or bash or ...
# laz2tif.sh
#
# Copyright 2024 Karjalan ATK-Awot Oy
# Jukka Inkeri
# https://github.com/kshji/awgeo
# https://awot.fi
#
# Create GeoTiff from LAZ file
#
VER="2024-11-04.a"
#
# using PDAL
#
PRG="$0"
BINDIR="${PRG%/*}"
[ "$PRG" = "$BINDIR" ] && BINDIR="." # - same dir as program
PRG="${PRG##*/}"
DEBUG=0
########################################################
usage()
{
cat <<EOF >&2
usage:$PRG -i input.laz -o outname.tif [ -d 0|1 ]
-d 0|1 debug, default is 0
EOF
}
########################################################
step()
{
dbg "-step:$*"
}
########################################################
status()
{
dbg "-status:$*"
}
########################################################
err()
{
echo "err:$*" >&2
}
########################################################
dbg()
{
[ $DEBUG -lt 1 ] && return
echo " $*" >&2
}
########################################################
clear_result()
{
rm -f "$result" 2>/dev/null
}
################################################################
make_json_tiff()
{
# pdal json
cat <<JSON
{
"pipeline":[
"base.laz",
{
"type":"filters.range",
"limits": "Classification[2:2]"
},
{
"type":"writers.gdal",
"filename":"result.tif",
"resolution":1.0,
"output_type":"all",
"gdaldriver": "GTiff"
}
]
}
JSON
}
################################################################
laz2tif()
{
# if done, not again
IN="$1"
OUT="$2"
[ -f "$OUT" ] && return
#pdal pipeline --readers.las.filename="$IN" --writers.gdal.filename="$TEMP.$name.raw.tif" laz2tiff.json 2>/dev/null
dbg dbg:pdal pipeline --readers.las.filename="$IN" --writers.gdal.filename="$TEMP.$name.raw.tif" $laz2tiff
pdal pipeline --readers.las.filename="$IN" --writers.gdal.filename="$TEMP.$name.raw.tif" $laz2tiff 2>/dev/null
dbg dbg:gdal_fillnodata.py "$TEMP.$name".raw.tif "$OUT"
gdal_fillnodata.py "$TEMP.$name".raw.tif "$OUT"
}
########################################################
# MAIN
########################################################
inf=""
result=""
mkdir -p tmp 2>/dev/null
id=$$ # process number = unique id for tempfiles
TEMP="tmp/$id"
laz2tiff="$TEMP.laz2tif.json"
status laz2tiff $laz2tiff
make_json_tiff > $laz2tiff
# parse cmdline options
while [ $# -gt 0 ]
do
arg="$1"
case "$arg" in
-i) inf="$2"; shift ;;
-o) result="$2"; shift ;;
-d) DEBUG="$2"; shift ;;
-v) echo "$PRG Ver:$VER" >&2 ;;
-h) usage ; exit 1 ;;
-*) usage ; exit 1 ;;
esac
shift
done
[ "$inf" = "" ] && usage && exit 1
name=$(basename "$inf" .laz)
[ "$result" = "" ] && result="$name"
clear_result
step make tiff
dbg dbg:laz2tif "$inf" "$result"
laz2tif "$inf" "$result"
[ ! -f "$result" ] && err "nofile $result" && exit 5
dbg "dbg: $TEMP.* temporary files"
[ $DEBUG -lt 1 ] && rm -f $TEMP.* 2>/dev/null
echo "result $result"