-
Notifications
You must be signed in to change notification settings - Fork 10
/
lidario_test.go
113 lines (98 loc) · 2.2 KB
/
lidario_test.go
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
package lidario
import (
"fmt"
"os"
"testing"
)
func TestReadLasFile(t *testing.T) {
fileName := "testdata/sample.las"
var lf *LasFile
var err error
lf, err = NewLasFile(fileName, "r")
if err != nil {
fmt.Println(err)
t.Fail()
}
defer lf.Close()
fmt.Printf("%v\n", lf.Header)
// Print the VLR data
fmt.Println("Printing VLRs:")
for _, vlr := range lf.VlrData {
fmt.Println(vlr)
}
fmt.Println("\nPrinting Geokeys:")
fmt.Println(lf.PrintGeokeys())
fmt.Println()
j := 1000000
x, y, z, err := lf.GetXYZ(j)
fmt.Printf("Point %v: (%f, %f, %f) Error: %v\n", j, x, y, z, err)
var p LasPointer
p, err = lf.LasPoint(j)
if err != nil {
fmt.Println(err)
t.Fatal()
}
fmt.Println("Point format:", p.Format())
oldProgress := -1
progress := 0
for i := 0; i < int(lf.Header.NumberPoints); i++ {
if p, err := lf.LasPoint(i); err != nil {
fmt.Println(err)
t.Fatal()
} else {
if i < 10 {
pd := p.PointData()
fmt.Printf("Point %v: (%f, %f, %f, %v, %v, %f)\n", i, pd.X, pd.Y, pd.X, pd.Intensity, pd.ClassBitField.ClassificationString(), p.GpsTimeData())
}
progress = int(100.0 * float64(i) / float64(lf.Header.NumberPoints))
if progress != oldProgress {
oldProgress = progress
if progress%10 == 0 {
fmt.Printf("Progress: %v\n", progress)
}
}
}
}
}
func TestWriteLasFile(t *testing.T) {
fileName := "testdata/sample.las"
var lf *LasFile
var err error
lf, err = NewLasFile(fileName, "r")
if err != nil {
fmt.Println(err)
t.Fail()
}
defer lf.Close()
newFileName := "testdata/newFile.las"
newLf, err := InitializeUsingFile(newFileName, lf)
if err != nil {
fmt.Println(err)
t.Fail()
}
progress := 0
oldProgress := -1
for i := 0; i < int(lf.Header.NumberPoints); i++ {
if p, err := lf.LasPoint(i); err != nil {
fmt.Println(err)
t.Fatal()
} else {
if p.PointData().Z < 100.0 {
newLf.AddLasPoint(p)
}
}
progress = int(100.0 * float64(i) / float64(lf.Header.NumberPoints))
if progress != oldProgress {
oldProgress = progress
if progress%10 == 0 {
fmt.Printf("Progress: %v\n", progress)
}
}
}
newLf.Close()
// now delete the file
if err = os.Remove(newFileName); err != nil {
fmt.Println(err)
t.Fail()
}
}