-
Notifications
You must be signed in to change notification settings - Fork 0
/
srtm.go
51 lines (42 loc) · 774 Bytes
/
srtm.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
package srtm
import (
"encoding/binary"
"io"
)
var SRTMByteOrder = binary.BigEndian
type SRTMFormat int
const (
SRTM1Format = SRTMFormat(iota)
SRTM3Format
)
const (
SRTM1Size = 3601
SRTM3Size = 1201
)
func (f SRTMFormat) Size() int {
switch f {
case SRTM1Format:
return SRTM1Size
case SRTM3Format:
return SRTM3Size
}
return -1
}
func (f SRTMFormat) String() string {
switch f {
case SRTM1Format:
return "SRTM1"
case SRTM3Format:
return "SRTM3"
}
return "invalid format"
}
type SRTMImage struct {
Data []int16
Format SRTMFormat
}
func NewSRTMImage(r io.Reader, format SRTMFormat) (*SRTMImage, error) {
data := make([]int16, format.Size()*format.Size())
err := binary.Read(r, SRTMByteOrder, data)
return &SRTMImage{data, format}, err
}