-
Notifications
You must be signed in to change notification settings - Fork 1
/
NZCCD.html
270 lines (247 loc) · 9.33 KB
/
NZCCD.html
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<html>
<head>
<title>NZCCD</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
crossorigin=""></script>
<script src="https://unpkg.com/leaflet.glify@3.3.0/dist/glify-browser.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js"></script>
<script src="https://unpkg.com/leaflet-spin@1.1.0/leaflet.spin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://unpkg.com/leaflet-geosearch@latest/dist/bundle.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-geosearch@latest/assets/css/leaflet.css">
<script src="https://unpkg.com/leaflet-providers@1.3.0/leaflet-providers.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chroma-js/2.4.2/chroma.min.js"
integrity="sha512-zInFF17qBFVvvvFpIfeBzo7Tj7+rQxLeTJDmbxjBz5/zIr89YVbTNelNhdTT+/DCrxoVzBeUPVFJsczKbB7sew=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
body,
html,
#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.legend {
color: white;
padding: 10px;
background-color: rgba(0, 0, 0, 0.8);
border-radius: 5px;
max-width: 500px;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
clear: left;
}
.legend h4 {
margin-top: 0px;
}
.link {
text-decoration: underline;
cursor: pointer;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
var map = L.map('map', {
center: [-42, 172],
zoom: 6,
//worldCopyJump: true
})
var baseMaps = {
"OSM": L.tileLayer.provider("OpenStreetMap.Mapnik"),
"CartoDB Positron": L.tileLayer.provider('CartoDB.Positron'),
"CartoDB Dark Matter": L.tileLayer.provider("CartoDB.DarkMatter"),
"ESRI WorldImagery": L.tileLayer.provider("Esri.WorldImagery").addTo(map),
"Google Hybrid": L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
})
}
var overlayMaps = {
}
L.control.layers(baseMaps, overlayMaps, { position: "topleft" }).addTo(map);
var cmap = chroma.scale('RdYlBu').domain([-3, 3])
map.spin(true);
const parquet = await import("https://unpkg.com/@dsnp/parquetjs@1.7.0/dist/browser/parquet.esm.js");
const buffer_library = await import("https://esm.sh/buffer");
const URL = "rates_with_timeseries.parquet";
let resp = await fetch(URL)
let buffer = await resp.arrayBuffer()
buffer = buffer_library.Buffer.from(buffer);
const reader = await parquet.ParquetReader.openBuffer(buffer);
//const reader = await parquet.ParquetReader.openUrl(URL);
var startTime = performance.now()
let cursor = reader.getCursor();
let record = null;
var results = []
while (record = await cursor.next()) {
results.push(record)
}
await reader.close();
var endTime = performance.now()
console.log(`Took ${(endTime - startTime)/1000}s to read ${results.length} rows from ${URL}`)
console.log(results)
for (var r of results) {
r.LRR = parseFloat(r.LRR)
r.LR2 = parseFloat(r.LR2)
}
var points = results.map(r => [parseFloat(r.lat), parseFloat(r.lon)])
L.glify.points({
map: map,
data: points,
size: 10,
fragmentShaderSource: L.glify.shader.fragment.simpleCircle,
sensitivity: 5,
sensitivityHover: 5,
color: function(index, point) {
var r = results[index]
if (r.LR2 < .1) {
return {r:0, g:0, b:0}
}
var c = cmap(r.LRR).gl()
return { r: c[0], g: c[1], b: c[2] };
},
click: function (e, point, xy) {
var i = points.indexOf(point);
var r = results[i];
console.log(r);
$("#plot").remove()
if (window.popup) map.closePopup(window.popup)
window.popup = L.popup({minWidth: 800})
.setContent(`Region: ${r.Region}<br>
Net shoreline movement: ${r.NSM}m<br>
Shoreline change envelope: ${r.SCE}m<br>
End point rate: ${r.EPR}m ± ${r.EPRunc}m<br>
Rate of change: ${r.LRR} m/yr ± ${r.LCI} m/yr<br>
R² score: ${r.LR2}<br>
Standard error: ${r.LSE}<br>
Weighted rate of change: ${r.WLR} m/yr ± ${r.WCI} m/yr<br>
Weighted R² score: ${r.WR2}<br>
Weighted standard error: ${r.WSE}<br>
Shoreline count: ${r.ShrCount}<br>
Start date: ${r.Dates.list[0].element}<br>
End date: ${r.Dates.list[r.Dates.list.length - 1].element}<br>
Duration (yrs): ${r.Duration}<br>
UniqueID: ${r.UniqueID}<br>
<div id="plot"></div>
`)
.setLatLng(point)
.addTo(map);
var dates = r.Dates.list.map(d => d.element)
var values = r.Distances.list.map(d => d.element)
var mean = Plotly.d3.mean(values)
var LRI = parseFloat(r.LRI) - mean
var WLI = parseFloat(r.WLI) - mean
r.WLR = parseFloat(r.WLR)
r.WCI = parseFloat(r.WCI)
r.LCI = parseFloat(r.LCI)
values = values.map(v => v ? v - mean : v)
console.log(dates,values)
var min_date = new Date(dates[0])
var max_date = new Date(dates[dates.length - 1])
var datediff = (max_date - min_date) / 1000 / 60 / 60 / 24 / 365.25
var data = [{
type: "scatter",
mode: "lines+markers",
name: "chainage",
x: dates,
y: values,
//line: {color: '#17BECF'}
}, {
type: "line",
x: [min_date, max_date],
y: [LRI, r.LRR * datediff + LRI],
name: "Rate of change",
hoverinfo: "none",
legendgroup: "LRR"
}, {
x: [min_date, min_date, max_date, max_date],
y: [LRI + r.LCI, LRI - r.LCI, r.LRR * datediff + LRI - r.LCI, r.LRR * datediff + LRI + r.LCI],
name: "Rate of change",
fill: 'toself',
type: 'scatter',
mode: 'none',
hoverinfo: "none",
legendgroup: "LRR"
}, {
type: "line",
x: [min_date, max_date],
y: [WLI, r.WLR * datediff + WLI],
name: "Weighted rate of change",
hoverinfo: "none",
visible: "legendonly",
legendgroup: "WRR"
}, {
x: [min_date, min_date, max_date, max_date],
y: [WLI + r.WCI, WLI - r.WCI, r.WLR * datediff + WLI - r.WCI, r.WLR * datediff + WLI + r.WCI],
name: "Weighted rate of change",
fill: 'toself',
type: 'scatter',
mode: 'none',
hoverinfo: "none",
visible: "legendonly",
legendgroup: "WRR"
}];
console.log(data)
var layout = {
title: `Time series for ${r.UniqueID}`,
xaxis: {
title: "Date/Time"
},
yaxis: {
title: "cross-shore change [m]",
hoverformat: '.1f'
}
};
Plotly.newPlot("plot", data, layout, {responsive: true});
var px = map.project(e.latlng);
console.log(px)
px.y -= 400;
map.panTo(map.unproject(px),{animate: true});
},
});
map.spin(false);
var geoSearch = new GeoSearch.GeoSearchControl({
provider: new GeoSearch.OpenStreetMapProvider(),
style: 'button',
autoComplete: true,
autoCompleteDelay: 250,
autoClose: true,
position: "topleft"
}).addTo(map);
var legend = L.control({ position: 'bottomright' });
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend');
div.innerHTML += "<h4>Trend (m / year)</h4>"
for (var i = -3; i <= 3; i++) {
var prefix = ""
if (i == -3) {
prefix = "≤ "
} else if (i == 3) {
prefix = "≥ "
}
div.innerHTML += `<i style="background:${cmap(i).css()}"></i>${prefix + i}<br>`
}
div.innerHTML += `<i style="background:black"></i>Uncertain<br>`
div.innerHTML += `Rate of coastal change (m/yr) derived from analysis of aerial photos and satellite imagery. Red colours (negative values) indicate erosion. Blue colours (positive values) indicate accretion. Click on points to see rates with confidence intervals. For more details visit <a href="http://coastalchange.nz" target="_blank" rel="noopener noreferrer" tabindex="-1">coastalchange.nz</a>`
return div;
};
legend.addTo(map);
</script>
</body>
</html>