-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownsample.sh
executable file
·112 lines (95 loc) · 2.31 KB
/
downsample.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
#!/bin/sh
dbName=
step=1;
while getopts "d:s:" arg
do
case $arg in
d)
dbName=$OPTARG
;;
s)
step=$OPTARG
;;
?)
echo "unkonw argument"
exit 1
;;
esac
done
if [ -z "$dbName" ]; then
echo "You must specify the database name with -d option"
exit
fi
if psql -lqt | cut -d \| -f 1 | grep -qw ${dbName}; then
# database exists
entries=`psql -At -U ericrussell -d ${dbName} -c "SELECT COUNT(*) FROM lidar;"`;
entry_step=$(($entries/32));
gain=$(($entry_step-1));
file_record="";
for j in `seq 1 ${entry_step} ${entries}`; do
{
jsonfile=${dbName}_$j.json;
lazfile=${dbName}_temp_$j.laz;
echo '{
"pipeline":[' > ${jsonfile};
if [ "$(($j + $gain))" -le "${entries}" ]; then
echo ' {
"type":"readers.pgpointcloud",
"connection":"host='"'"'localhost'"'"' dbname='"'${dbName}'"' user='"'"'ericrussell'"'"'",
"table":"lidar",
"column":"pa",
"where":"id between '"${j}"' and '"$(($j + $gain))"'"
},
{
"type":"filters.decimation",
"step":"'"${step}"'"
},' >> ${jsonfile};
else
echo ' {
"type":"readers.pgpointcloud",
"connection":"host='"'"'localhost'"'"' dbname='"'${dbName}'"' user='"'"'ericrussell'"'"'",
"table":"lidar",
"column":"pa",
"where":"id between '"${j}"' and '"${entries}"'"
},
{
"type":"filters.decimation",
"step":"'"${step}"'"
},' >> ${jsonfile};
fi
echo ' "'"${lazfile}"'"
]
}' >> ${jsonfile};
pdal pipeline ${jsonfile};
rm ${jsonfile};
} &
done
wait
for temp_file in `ls ${dbName}_temp_*.laz`; do
file_record=${file_record}'"'${temp_file}'",\n';
done
file_record=${file_record%,\n};
jsonfile=${dbName}.json;
pcdfile=${dbName}_${step}th.pcd;
echo '{
"pipeline":[
'"${file_record}"'
{
"type": "filters.merge"
},
{
"type":"writers.pcd",
"compression":"true",
"filename":"'"${pcdfile}"'"
}
]
}' > ${jsonfile};
pdal pipeline ${jsonfile};
rm ${jsonfile};
rm ${dbName}_temp_*.laz;
echo "Finished downsample "${dbName};
else
# ruh-roh
echo "Database ""'"${dbName}"'"" does not exist."
exit
fi