-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLandsatSceneFilter.java
executable file
·254 lines (224 loc) · 8.27 KB
/
LandsatSceneFilter.java
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
// This module implements a class to act as a scene filter for scenes that
// are navigated like the Landsat data.
//------------------------------------------------------------------------
class LandsatSceneFilter implements SceneFilter
{
private MosaicData md; // reference to mosaic data
private int firstFilteredDate; // index to first date for the selected
// scene that passes any filters
private int lastFilteredDate; // index to last date for the selected scene
// that passes any filters
// constructor for this filter
//----------------------------
LandsatSceneFilter(MosaicData md)
{
this.md = md;
}
// In the active cell, step forward one date that hasn't been filtered
//--------------------------------------------------------------------
public void nextDate()
{
nextDate(md.getCurrentCell());
}
// In the cell specified by the scene, step forward one date that hasn't
// been filtered
//----------------------------------------------------------------------
public void nextDate(Metadata scene)
{
nextDate(md.getCellForScene(scene));
}
// method with common parts of going to the next date
//---------------------------------------------------
private void nextDate(TOC cell)
{
if (cell.numImg >= 1)
{
// go forward one date, skipping scenes that are not visible.
// If it is the last date, don't do anything
int next = cell.currentDateIndex + 1;
while ((next < cell.numImg) && !cell.scenes[next].visible)
{
next++;
}
if (next < cell.numImg)
{
md.drawNewDate(cell.gridCol,cell.gridRow,next);
}
}
}
// In the active cell, step backward one date that hasn't been filtered
//----------------------------------------------------------------------
public void prevDate()
{
prevDate(md.getCurrentCell());
}
// In the cell specified by the scene, step backward one date that hasn't
// been filtered
//-----------------------------------------------------------------------
public void prevDate(Metadata scene)
{
prevDate(md.getCellForScene(scene));
}
// method with common parts of going to the prev date
//---------------------------------------------------
private void prevDate(TOC cell)
{
if (cell.numImg >= 1)
{
// go back one date, skipping over scenes that are not visible.
// When at the first scene, don't move any further
int next = cell.currentDateIndex - 1;
while ((next >= 0) && !cell.scenes[next].visible)
{
next--;
}
if (next >= 0)
{
md.drawNewDate(cell.gridCol,cell.gridRow,next);
}
}
}
// Jump to a date in or after the target year/month
//-------------------------------------------------
public void gotoDate(int targetYear, int targetMonth)
{
TOC cell = md.getCurrentCell();
// nothing to do if the current cell isn't valid
if (!cell.valid)
return;
// calculate target date
int targetDate = targetYear * 10000 + targetMonth * 100;
int last = lastFilteredDate;
// if target date is off end of available dates, make the last
// date the target date
if (targetDate > cell.scenes[last].date)
targetDate = cell.scenes[last].date;
// if target date is off start of available dates, make the first
// date the target date
if (targetDate < cell.scenes[0].date)
targetDate = cell.scenes[0].date;
int newIndex = 0;
// look for the target date or the next one after it
for (int index = 0; index <= last; index++)
{
if (cell.scenes[index].visible)
{
newIndex = index;
if (cell.scenes[index].date >= targetDate)
break;
}
}
md.drawNewDate(cell.gridCol,cell.gridRow,newIndex);
}
// filter the data for the indicated maximum cloud cover
//------------------------------------------------------
public void filter()
{
// initialize the filter results
firstFilteredDate = 0;
lastFilteredDate = 0;
TOC cell = md.getCurrentCell();
// if no scene selected or the selected scene doesn't have valid
// metadata, exit
if (!cell.valid)
return;
// default the first date that passes the filter to the last scene
// in case they all fail
firstFilteredDate = cell.numImg - 1;
// look through the list of scenes from first to last until one is
// found that doesn't have too much cloud cover to establish the first
// date available
for (int index = 0; index < cell.numImg; index++)
{
if (cell.scenes[index].visible)
{
firstFilteredDate = index;
break;
}
}
// look through the list of scenes from last until the first that
// passed the filter to find one that doesn't have too much cloud cover
// to establish the last date available
lastFilteredDate = 0;
for (int index = cell.numImg - 1; index >= firstFilteredDate; index--)
{
if (cell.scenes[index].visible)
{
lastFilteredDate = index;
break;
}
}
}
// returns true if another date is available after the current date
//-----------------------------------------------------------------
public boolean isNextDateAvailable()
{
TOC cell = md.getCurrentCell();
if (cell.currentDateIndex >= lastFilteredDate)
return false;
else
return true;
}
// returns true if another date is available before the current date
//------------------------------------------------=-----------------
public boolean isPrevDateAvailable()
{
TOC cell = md.getCurrentCell();
if (cell.currentDateIndex <= firstFilteredDate)
return false;
else
return true;
}
// returns true if another date is available after the current date for
// the indicated scene
//---------------------------------------------------------------------
public boolean isNextDateAvailable(Metadata scene)
{
TOC cell = md.getCellForScene(scene);
for (int index = cell.currentDateIndex + 1; index < cell.numImg;
index++)
{
if (cell.scenes[index].visible)
return true;
}
return false;
}
// returns true if another date is available before the current date for
// the indicated scene
//------------------------------------------------=---------------------
public boolean isPrevDateAvailable(Metadata scene)
{
TOC cell = md.getCellForScene(scene);
for (int index = cell.currentDateIndex - 1; index >= 0; index--)
if (cell.scenes[index].visible)
return true;
return false;
}
// jumps to the first date that hasn't been filtered
//--------------------------------------------------
public void gotoFirstDate()
{
TOC cell = md.getCurrentCell();
md.drawNewDate(cell.gridCol,cell.gridRow,firstFilteredDate);
}
// jumps to the last date that hasn't been filtered
//-------------------------------------------------
public void gotoLastDate()
{
TOC cell = md.getCurrentCell();
md.drawNewDate(cell.gridCol,cell.gridRow,lastFilteredDate);
}
// methods to return the first and last year available. Note that this
// includes all scene dates, even if they have been filtered out.
//---------------------------------------------------------------------
public int getFirstYear()
{
TOC cell = md.getCurrentCell();
return cell.scenes[0].date/10000;
}
public int getLastYear()
{
TOC cell = md.getCurrentCell();
return cell.scenes[cell.numImg-1].date/10000;
}
}