-
Notifications
You must be signed in to change notification settings - Fork 3
/
list.go
92 lines (84 loc) · 2.47 KB
/
list.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
package sepa
import (
"fmt"
"math"
"strconv"
"github.com/whitewater-guide/gorge/core"
)
const epsg27700 = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs"
type csvRaw struct {
sepaHydrologyOffice string
stationName string
locationCode string
nationalGridReference string
catchmentName string
riverName string
gaugeDatum string
catchmentArea string
startDate string
endDate string
systemID string
lowestValue string
low string
maxValue string
high string
maxDisplay string
mean string
units string
webMessage string
nrfaLink string
}
func gaugeFromRow(row []string) csvRaw {
return csvRaw{
sepaHydrologyOffice: row[0],
stationName: row[1],
locationCode: row[2],
nationalGridReference: row[3],
catchmentName: row[4],
riverName: row[5],
gaugeDatum: row[6],
catchmentArea: row[7],
startDate: row[8],
endDate: row[9],
systemID: row[10],
lowestValue: row[11],
low: row[12],
maxValue: row[13],
high: row[14],
maxDisplay: row[15],
mean: row[16],
units: row[17],
webMessage: row[18],
nrfaLink: row[19],
}
}
func (s *scriptSepa) getGauge(raw csvRaw) (result core.Gauge, err error) {
ref, err := parseGridRef(raw.nationalGridReference)
if err != nil {
return result, core.WrapErr(err, "failed to parse location").With("code", raw.locationCode)
}
x, y, err := core.ToEPSG4326(float64(ref.easting), float64(ref.northing), epsg27700)
if err != nil {
return
}
alt, err := strconv.ParseFloat(raw.gaugeDatum, 64)
if err != nil {
return
}
result = core.Gauge{
GaugeID: core.GaugeID{
Code: raw.locationCode,
Script: s.name,
},
Name: fmt.Sprintf("%s - %s", raw.riverName, raw.stationName),
URL: "http://apps.sepa.org.uk/waterlevels/default.aspx?sd=t&lc=" + raw.locationCode,
LevelUnit: raw.units, // all the data is supposed to be in m
FlowUnit: "",
Location: &core.Location{
Longitude: x,
Latitude: y,
Altitude: math.Trunc(alt),
},
}
return
}