forked from slawler/gdal
-
Notifications
You must be signed in to change notification settings - Fork 2
/
algorithms_test.go
80 lines (74 loc) · 1.64 KB
/
algorithms_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
package gdal
import (
"errors"
"fmt"
"io/ioutil"
"math"
"strconv"
"strings"
"testing"
)
func readGridFile(filename string) (x, y, z []float64, err error) {
var b []byte
if b, err = ioutil.ReadFile(filename); err != nil {
return
}
arr := strings.Split(string(b), "\n")
x, y, z = make([]float64, len(arr)), make([]float64, len(arr)), make([]float64, len(arr))
for i, el := range arr {
xyz := strings.Split(el, ",")
if len(xyz) != 3 {
err = errors.New("wrong input file format, should be CSV with 3 columns: y,x,z")
}
if y[i], err = strconv.ParseFloat(xyz[0], 64); err != nil {
return
}
if x[i], err = strconv.ParseFloat(xyz[1], 64); err != nil {
return
}
if z[i], err = strconv.ParseFloat(xyz[2], 64); err != nil {
return
}
}
return
}
func TestGridCreate(t *testing.T) {
x, y, z, err := readGridFile("testdata/grid.csv")
if err != nil {
t.Fatalf("failed to readGridFile: %v", err)
return
}
var nX, nY uint = 420, 470
// finding max and min values
var xMin, xMax, yMin, yMax = math.MaxFloat64, -math.MaxFloat64, math.MaxFloat64, -math.MaxFloat64
for i := range x {
if x[i] < xMin {
xMin = x[i]
}
if x[i] > xMax {
xMax = x[i]
}
if y[i] < yMin {
yMin = y[i]
}
if y[i] > yMax {
yMax = y[i]
}
}
fmt.Println("Calling gdal.GridCreate")
data, err := GridCreate(
GA_Linear,
GridLinearOptions{Radius: -1, NoDataValue: 0},
x, y, z,
xMin, xMax, yMin, yMax,
nX, nY,
DummyProgress,
nil,
)
if err != nil {
t.Errorf("GridCreate: %v", err)
}
if expectedDataLen := int(nX * nY); len(data) != expectedDataLen {
t.Errorf("expected length of data equal to %d", expectedDataLen)
}
}