-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI LandTrendr Change Mapper
390 lines (317 loc) · 13 KB
/
UI LandTrendr Change Mapper
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
//########################################################################################################
//# #\\
//# LANDTRENDR CHANGE MAPPER GUI #\\
//# #\\
//########################################################################################################
// date: 2018-06-11
// author: Justin Braaten | [email protected]
// Zhiqiang Yang | [email protected]
// Robert Kennedy | [email protected]
// website: https://github.com/eMapR/LT-GEE
//#### this is how you make comments####
var ltgee = require('users/emaprlab/public:Modules/LandTrendr.js');
//####################################################################################
//########### ACTION HANDLER FUNCTION ################################################
//####################################################################################
var mapDisturbance = function(){
// get landtrendr run parameters
var runParams = ltgee.getParams(paramPanel);
var startYear = ltgee.getYears(yearPanel).startYear;
var endYear = ltgee.getYears(yearPanel).endYear;
var startDay = ltgee.getDays(datePanel).startDay;
var endDay = ltgee.getDays(datePanel).endDay;
var index = ltgee.getIndexSelect(indexPanel);
var maskThese = ltgee.getMaskSelect(maskPanel);
var lon = ltgee.getCoords(coordsPanel).lon;
var lat = ltgee.getCoords(coordsPanel).lat;
var buffer = ltgee.getBuffer(bufferPanel);
var aoi = ee.Geometry.Point(lon, lat)
.buffer(buffer*1000)
.bounds();
// center the map on the point
map.centerObject(aoi, 11);
// run landtrendr and get the segmenation information
var lt = ltgee.runLT(startYear, endYear, startDay, endDay, aoi, index, [], runParams, maskThese); //maskThese
//var segInfo = ltgee.getSegmentData(lt, index);
// get disturbance mapping parameters
var distParams = {};
distParams.index = index;
//distParams.segInfo = segInfo;
distParams.delta = changeTypeFilter.widgets().get(1).getValue();
distParams.sort = distTypeFilter.widgets().get(1).getValue();
var distYearsFilter = ltgee.getYears(yearFilter);
distParams.year = {
checked: yearFilter.widgets().get(0).getValue(),
start: parseInt(distYearsFilter.startYear),
end: parseInt(distYearsFilter.endYear)
};
distParams.mag = {
checked: magFilter.widgets().get(0).getValue(),
value: parseFloat(magFilter.widgets().get(1).widgets().get(1).getValue()),
operator: magFilter.widgets().get(1).widgets().get(3).getValue().toString()
};
distParams.dur = {
checked: durFilter.widgets().get(0).getValue(),
value: parseFloat(durFilter.widgets().get(1).widgets().get(1).getValue()),
operator: durFilter.widgets().get(1).widgets().get(3).getValue().toString()
};
distParams.preval = {
checked: prevalFilter.widgets().get(0).getValue(),
value: parseFloat(prevalFilter.widgets().get(1).widgets().get(1).getValue()),
operator: prevalFilter.widgets().get(1).widgets().get(3).getValue().toString()
};
distParams.mmu = {
checked: mmuFilter.widgets().get(0).getValue(),
value: parseInt(mmuFilter.widgets().get(1).getValue())
};
// get the disturbance map layers
var distImg = ltgee.getChangeMap(lt, distParams);
// set visualization dictionaries
var yodVizParms = {
min: 1985, //distParams.year.start+1,
max: 2019, //distParams.year.end,
palette: ['#9400D3', '#4B0082', '#0000FF', '#00FF00', '#FFFF00', '#FF7F00', '#FF0000']
};
var magVizParms = {
min: 0, //distParams.mag.year1,
max: 1000,
palette: ['#0000FF', '#00FF00', '#FFFF00', '#FF7F00', '#FF0000']
};
var durVizParms = {
min: 1,
max: 10,
palette: ['#FF0000', '#FF7F00', '#FFFF00', '#00FF00', '#0000FF']
};
var preValVizParms = {
min: 200, //distParams.preval.value,
max: 800,
palette: ['#F1F1F1', '#FFC9B8', '#FFC183', '#E1BB4E', '#B4B61A', '#7EAF12', '#26A63A']
};
// display the disturbance attribute maps
//map.layers().set(0, ui.Map.Layer(distImg.select(['preval']), preValVizParms, 'Pre-dist Value')); // add pre-disturbacne spectral index value to map
map.layers().set(0, ui.Map.Layer(distImg.select(['dur']), durVizParms, 'Duration')); // add disturbance duration to map
map.layers().set(1, ui.Map.Layer(distImg.select(['mag']), magVizParms, 'Magnitude')); // add magnitude to map
map.layers().set(2, ui.Map.Layer(distImg.select(['yod']), yodVizParms, 'Year of Detection')); // add disturbance year of detection to map
return {lt:lt, distImg:distImg, index:index};
};
var chartPoint = function(lt, pixel, index, indexFlip) {
var pixelTimeSeriesData = ltgee.ltPixelTimeSeriesArray(lt, pixel, indexFlip);
return ui.Chart(pixelTimeSeriesData.ts, 'LineChart',
{
'title' : 'Index: '+index + ' | Fit RMSE:'+ (Math.round(pixelTimeSeriesData.rmse * 100) / 100).toString(),
'hAxis':
{
'format':'####'
},
'vAxis':
{
'maxValue': 1000,
'minValue': -1000
}
},
{'columns': [0, 1, 2]}
);
};
//####################################################################################
//########### UI ELEMENT CONSTRUCTION ################################################
//####################################################################################
// SET UP PRIMARY PANELS
// control panel
var controlPanel = ui.Panel({
layout: ui.Panel.Layout.flow('vertical'),
style: {width: '340px'}
});
// map panel
var map = ui.Map();
map.style().set({cursor:'crosshair'});
map.setOptions('HYBRID');
// plot panel
var plotsPanelLabel = ui.Panel([
ui.Label('Instructions', {fontWeight: 'bold'}),
ui.Label('1) Define mapping options in control panel'),
ui.Label('2) Click a point or enter & submit coordinates'),
ui.Label('3) Check the "Inspector" box and click a point for info'),
ui.Label('* Wait patiently for map and point info to load'),
ui.Label('* Click here for more information', {}, 'https://goo.gl/uDk4GY'),
ui.Label('____________________________________________________'),
]);
var inspectorCheck = ui.Checkbox({label:'Inspector', value:0, style:{fontWeight: 'bold'}});
var yodLabel = ui.Label('');
var magLabel = ui.Label('');
var durLabel = ui.Label('');
var prevaLabel = ui.Label('');
var rateLabel = ui.Label('');
var plotPanel = ui.Panel(null, null, {stretch: 'horizontal'});
var warningPanel = ui.Label('');
var plotPanelParent = ui.Panel([
plotsPanelLabel,
inspectorCheck,
yodLabel,
magLabel,
durLabel,
prevaLabel,
rateLabel,
plotPanel,
warningPanel], null, {width: '350px'});
// SET UP SECONDARY PANELS
var yearPanel = ltgee.yearPanel();
var datePanel = ltgee.datePanel();
var indexPanel = ltgee.indexSelectPanel();
var maskPanel = ltgee.maskSelectPanel();
var bufferPanel = ltgee.bufferPanel();
var coordsPanel = ltgee.coordsPanel();
//var inspectorCheck = ui.Checkbox({label:'Inspector mode', value:0, style:{fontWeight: 'bold', position:'top-left'}});
var paramPanel = ltgee.paramPanel();
// disturbance mapping panel
var changeTypeList = ['Loss','Gain'];
var changeTypeFilter = ui.Panel(
[ui.Label({value:'Select Vegetation Change Type:', style:{color:'blue'}}),ui.Select({items:changeTypeList, value:'Loss', style:{stretch: 'horizontal'}})], ui.Panel.Layout.Flow('horizontal')
);
var distTypeList = ['Greatest','Least','Newest','Oldest','Fastest','Slowest'];
var distTypeFilter = ui.Panel(
[ui.Label({value:'Select Vegetation Change Sort:', style:{color:'blue'}}),ui.Select({items:distTypeList, value:'Greatest', style:{stretch: 'horizontal'}})], ui.Panel.Layout.Flow('horizontal')
);
var yearFilter = ltgee.yearPanel();
yearFilter.remove(yearFilter.widgets().get(0));
yearFilter.insert(0, ui.Checkbox({label:'Filter by Year:', style:{color:'blue'}}));
yearFilter.widgets().get(1).style().set('padding', '0px 0px 0px 20px');
yearFilter.widgets().get(2).style().set('padding', '0px 0px 0px 20px');
var opList = ['>', '<'];
var magFilter = ui.Panel(
[
ui.Checkbox({label:'Filter by Magnitude:', style:{color:'blue'}}),
ui.Panel(
[
ui.Label('Value:'),
ui.Textbox({value:100, style:{stretch: 'horizontal'}}),
ui.Label('Operator:'),
ui.Select({items:opList, value:'>', style:{stretch: 'horizontal'}})
], ui.Panel.Layout.Flow('horizontal'), {stretch: 'horizontal', padding: '0px 0px 0px 20px'})
],
null,
{stretch: 'horizontal'}
);
var durFilter = ui.Panel(
[
ui.Checkbox({label:'Filter by Duration:', style:{color:'blue'}}),
ui.Panel(
[
ui.Label('Value:'),
ui.Textbox({value:4, style:{stretch: 'horizontal'}}),
ui.Label('Operator:'),
ui.Select({items:opList, value:'<', style:{stretch: 'horizontal'}})
], ui.Panel.Layout.Flow('horizontal'), {stretch: 'horizontal', padding: '0px 0px 0px 20px'})
],
null,
{stretch: 'horizontal'}
);
var prevalFilter = ui.Panel(
[
ui.Checkbox({label:'Filter by Pre-Dist Value:', style:{color:'blue'}}),
ui.Panel(
[
ui.Label('Value:'),
ui.Textbox({value:400, style:{stretch: 'horizontal'}}),
ui.Label('Operator:'),
ui.Select({items:opList, value:'>', style:{stretch: 'horizontal'}})
], ui.Panel.Layout.Flow('horizontal'), {stretch: 'horizontal', padding: '0px 0px 0px 20px'})
],
null,
{stretch: 'horizontal'}
);
var mmuFilter = ui.Panel(
[
ui.Checkbox({label:'Filter by MMU:', style:{color:'blue'}}),
ui.Textbox({value:11, style:{stretch: 'horizontal'}})
],
ui.Panel.Layout.Flow('horizontal'),
{stretch: 'horizontal'}
);
var distParams = ui.Panel(
[
ui.Label('Define Change Mapping Parameters',{fontWeight: 'bold'}),
changeTypeFilter,
distTypeFilter,
yearFilter,
magFilter,
durFilter,
prevalFilter,
mmuFilter
]
);
var submitButton = ltgee.submitButton();
//####################################################################################
//########### BIND FUNCTIONS TO ACTIONS ##############################################
//####################################################################################
var changeMap;
var ltMap;
var ltIndex;
var dirty = 0;
map.onClick(function(coords) {
// if in inspector mode, don't do anything - just get out
if(inspectorCheck.getValue() === true){
if(dirty === 0){
plotPanelParent.widgets().get(8).clear();
plotPanelParent.widgets().get(8).setValue('Warning: No change has been mapped. Turn "Inspector" off & click a point on the map, or enter & sumbit a coordinates to map change');
return;
}
var point = ee.Geometry.Point(coords.lon, coords.lat);
var pixel = point.buffer(15).bounds();
var result = ltgee.getPixelInfo(changeMap, pixel);
plotPanelParent.widgets().get(2).setValue('Year: '+result.yod);
plotPanelParent.widgets().get(3).setValue('Magnitude: '+Math.round(result.mag));
plotPanelParent.widgets().get(4).setValue('Duration: '+Math.round(result.dur));
plotPanelParent.widgets().get(5).setValue('Pre-value: '+Math.round(result.preval));
plotPanelParent.widgets().get(6).setValue('Rate: '+Math.round(result.rate));
var indexFlip = ltgee.indexFlipper(ltIndex);
var chart = chartPoint(ltMap, pixel, ltIndex, indexFlip);
plotPanel = plotPanel.clear();
plotPanel.add(chart);
} else{
// change the coords in the box
coordsPanel.widgets().get(1).widgets().get(1).setValue(coords.lon);
coordsPanel.widgets().get(1).widgets().get(3).setValue(coords.lat);
// draw disturbance layers
var changeObj = mapDisturbance();
changeMap = changeObj.distImg;
ltMap = changeObj.lt;
ltIndex = changeObj.index;
dirty = 1;
}
});
submitButton.onClick(function(){
var changeObj = mapDisturbance();
changeMap = changeObj.distImg;
ltMap = changeObj.lt;
ltIndex = changeObj.index;
dirty = 1;
});
//####################################################################################
//########### UI DRAWING #############################################################
//####################################################################################
// add panels to interface
controlPanel.add(yearPanel);
controlPanel.add(datePanel);
controlPanel.add(indexPanel);
controlPanel.add(maskPanel);
controlPanel.add(coordsPanel);
//controlPanel.add(inspectorCheck);
controlPanel.add(bufferPanel);
controlPanel.add(distParams);
controlPanel.add(paramPanel);
controlPanel.add(submitButton);
//map.add(inspectorCheck)
/*
map.add(ui.Label({
value: 'Click a point',
style: {position: 'top-center'}
}));
map.add(ui.Label({
value: 'Info: https://goo.gl/gGL3Dd',
style: {position: 'bottom-right'}
}));
*/
ui.root.clear();
ui.root.add(controlPanel);
ui.root.add(map);
ui.root.add(plotPanelParent);