Skip to content

Commit 69de5c1

Browse files
committed
add stories for new landsat datasets
1 parent 5f74e00 commit 69de5c1

File tree

3 files changed

+1059
-0
lines changed

3 files changed

+1059
-0
lines changed
Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,353 @@
1+
import { createFindDatesUTCStory, renderTilesList } from './storiesUtils';
2+
3+
import {
4+
Landsat15AWSLMSSL1Layer,
5+
CRS_EPSG3857,
6+
CRS_EPSG4326,
7+
BBox,
8+
MimeTypes,
9+
ApiType,
10+
LayersFactory,
11+
DATASET_AWS_LMSSL1,
12+
setAuthToken,
13+
CacheTarget,
14+
} from '../dist/sentinelHub.esm';
15+
16+
import { setAuthTokenWithOAuthCredentials } from './storiesUtils';
17+
18+
if (!process.env.INSTANCE_ID) {
19+
throw new Error('INSTANCE_ID environment variable is not defined!');
20+
}
21+
22+
if (!process.env.LANDSAT15_LMSSL1_LAYER_ID) {
23+
throw new Error('LANDSAT15_LMSSL1_LAYER_ID environment variable is not defined!');
24+
}
25+
26+
if (!process.env.LANDSAT15_LMSSL1_NDVI_LAYER_ID) {
27+
throw new Error('LANDSAT15_LMSSL1_NDVI_LAYER_ID environment variable is not defined!');
28+
}
29+
30+
const instanceId = process.env.INSTANCE_ID;
31+
const layerId = process.env.LANDSAT15_LMSSL1_LAYER_ID;
32+
const layerIdNdvi = process.env.LANDSAT15_LMSSL1_NDVI_LAYER_ID;
33+
const bbox = new BBox(CRS_EPSG3857, 1487158.82, 5322463.15, 1565430.34, 5400734.67);
34+
const bbox4326 = new BBox(CRS_EPSG4326, 11.9, 42.05, 12.95, 43.09);
35+
const fromTime = new Date(Date.UTC(1980, 10 - 1, 22, 0, 0, 0));
36+
const toTime = new Date(Date.UTC(1981, 11 - 1, 22, 23, 59, 59));
37+
38+
export default {
39+
title: 'Landsat 1-5 - MSS L1',
40+
};
41+
42+
export const getMapURL = () => {
43+
const img = document.createElement('img');
44+
img.width = '512';
45+
img.height = '512';
46+
47+
const wrapperEl = document.createElement('div');
48+
wrapperEl.innerHTML = '<h2>GetMapUrl (WMS)</h2>';
49+
wrapperEl.insertAdjacentElement('beforeend', img);
50+
51+
const layer = new Landsat15AWSLMSSL1Layer({ instanceId, layerId });
52+
53+
const getMapParams = {
54+
bbox: bbox,
55+
fromTime: fromTime,
56+
toTime: toTime,
57+
width: 512,
58+
height: 512,
59+
format: MimeTypes.JPEG,
60+
};
61+
const imageUrl = layer.getMapUrl(getMapParams, ApiType.WMS);
62+
img.src = imageUrl;
63+
64+
return wrapperEl;
65+
};
66+
67+
export const getMapWMS = () => {
68+
const img = document.createElement('img');
69+
img.width = '512';
70+
img.height = '512';
71+
72+
const wrapperEl = document.createElement('div');
73+
wrapperEl.innerHTML = '<h2>GetMap with WMS</h2>';
74+
wrapperEl.insertAdjacentElement('beforeend', img);
75+
76+
const perform = async () => {
77+
const layer = new Landsat15AWSLMSSL1Layer({ instanceId, layerId });
78+
79+
const getMapParams = {
80+
bbox: bbox,
81+
fromTime: fromTime,
82+
toTime: toTime,
83+
width: 512,
84+
height: 512,
85+
format: MimeTypes.JPEG,
86+
};
87+
const imageBlob = await layer.getMap(getMapParams, ApiType.WMS);
88+
img.src = URL.createObjectURL(imageBlob);
89+
};
90+
perform().then(() => {});
91+
92+
return wrapperEl;
93+
};
94+
95+
export const getMapWMSLayersFactory = () => {
96+
const img = document.createElement('img');
97+
img.width = '512';
98+
img.height = '512';
99+
100+
const wrapperEl = document.createElement('div');
101+
wrapperEl.innerHTML = '<h2>GetMap with WMS</h2>';
102+
wrapperEl.insertAdjacentElement('beforeend', img);
103+
104+
const perform = async () => {
105+
const layer = (
106+
await LayersFactory.makeLayers(
107+
`${DATASET_AWS_LMSSL1.shServiceHostname}ogc/wms/${instanceId}`,
108+
(lId, datasetId) => layerId === lId,
109+
)
110+
)[0];
111+
112+
const getMapParams = {
113+
bbox: bbox,
114+
fromTime: fromTime,
115+
toTime: toTime,
116+
width: 512,
117+
height: 512,
118+
format: MimeTypes.JPEG,
119+
};
120+
const imageBlob = await layer.getMap(getMapParams, ApiType.WMS);
121+
img.src = URL.createObjectURL(imageBlob);
122+
};
123+
perform().then(() => {});
124+
125+
return wrapperEl;
126+
};
127+
128+
export const getMapWMSEvalscript = () => {
129+
const img = document.createElement('img');
130+
img.width = '512';
131+
img.height = '512';
132+
133+
const wrapperEl = document.createElement('div');
134+
wrapperEl.innerHTML = '<h2>GetMap with WMS - evalscript</h2>';
135+
wrapperEl.insertAdjacentElement('beforeend', img);
136+
137+
const perform = async () => {
138+
const layer = new Landsat15AWSLMSSL1Layer({
139+
instanceId,
140+
layerId,
141+
evalscript: `
142+
return [2.5 * B04, 1.5 * B03, 0.5 * B02];
143+
`,
144+
});
145+
146+
const getMapParams = {
147+
bbox: bbox,
148+
fromTime: fromTime,
149+
toTime: toTime,
150+
width: 512,
151+
height: 512,
152+
format: MimeTypes.JPEG,
153+
};
154+
const imageBlob = await layer.getMap(getMapParams, ApiType.WMS);
155+
img.src = URL.createObjectURL(imageBlob);
156+
};
157+
perform().then(() => {});
158+
159+
return wrapperEl;
160+
};
161+
162+
export const GetMapProcessing = () => {
163+
if (!process.env.CLIENT_ID || !process.env.CLIENT_SECRET) {
164+
return "<div>Please set OAuth Client's id and secret for Processing API (CLIENT_ID, CLIENT_SECRET env vars)</div>";
165+
}
166+
167+
const img = document.createElement('img');
168+
img.width = '512';
169+
img.height = '512';
170+
171+
const wrapperEl = document.createElement('div');
172+
wrapperEl.innerHTML = '<h2>GetMap with processing api</h2>';
173+
wrapperEl.insertAdjacentElement('beforeend', img);
174+
175+
// getMap is async:
176+
const perform = async () => {
177+
await setAuthTokenWithOAuthCredentials();
178+
179+
const layer = new Landsat15AWSLMSSL1Layer({
180+
instanceId,
181+
layerId,
182+
evalscript: `
183+
//VERSION=3
184+
function setup() {
185+
return {
186+
input: ["B01", "B02", "B03"],
187+
output: { bands: 3 }
188+
};
189+
}
190+
191+
function evaluatePixel(sample) {
192+
return [2.5*sample.B03, 2.5*sample.B02, 2.5*sample.B01];
193+
}
194+
`,
195+
});
196+
const reqConfig = {
197+
cache: {
198+
expiresIn: 5000,
199+
targets: [CacheTarget.MEMORY],
200+
},
201+
};
202+
203+
const getMapParams = {
204+
bbox: bbox,
205+
fromTime: fromTime,
206+
toTime: toTime,
207+
width: 512,
208+
height: 512,
209+
format: MimeTypes.JPEG,
210+
};
211+
const imageBlob = await layer.getMap(getMapParams, ApiType.PROCESSING, reqConfig);
212+
img.src = URL.createObjectURL(imageBlob);
213+
};
214+
perform().then(() => {});
215+
216+
return wrapperEl;
217+
};
218+
219+
export const findTilesSearchIndex = () => {
220+
const layer = new Landsat15AWSLMSSL1Layer({ instanceId, layerId });
221+
const containerEl = document.createElement('pre');
222+
223+
const wrapperEl = document.createElement('div');
224+
wrapperEl.innerHTML = '<h2>findTiles</h2>';
225+
wrapperEl.insertAdjacentElement('beforeend', containerEl);
226+
227+
const perform = async () => {
228+
setAuthToken(null);
229+
const data = await layer.findTiles(bbox4326, fromTime, toTime, 5, 0, { cache: { expiresIn: 0 } });
230+
renderTilesList(containerEl, data.tiles);
231+
};
232+
perform().then(() => {});
233+
234+
return wrapperEl;
235+
};
236+
237+
export const findTilesCatalog = () => {
238+
const layer = new Landsat15AWSLMSSL1Layer({ instanceId, layerId });
239+
const containerEl = document.createElement('pre');
240+
241+
const wrapperEl = document.createElement('div');
242+
wrapperEl.innerHTML = '<h2>findTiles</h2>';
243+
wrapperEl.insertAdjacentElement('beforeend', containerEl);
244+
245+
const perform = async () => {
246+
await setAuthTokenWithOAuthCredentials();
247+
const data = await layer.findTiles(bbox4326, fromTime, toTime, 5, 0, { cache: { expiresIn: 0 } });
248+
renderTilesList(containerEl, data.tiles);
249+
};
250+
perform().then(() => {});
251+
252+
return wrapperEl;
253+
};
254+
255+
export const findFlyovers = () => {
256+
const layer = new Landsat15AWSLMSSL1Layer({ instanceId, layerId });
257+
258+
const wrapperEl = document.createElement('div');
259+
wrapperEl.innerHTML = '<h2>findFlyovers</h2>';
260+
261+
const flyoversContainerEl = document.createElement('pre');
262+
wrapperEl.insertAdjacentElement('beforeend', flyoversContainerEl);
263+
264+
const img = document.createElement('img');
265+
img.width = '512';
266+
img.height = '512';
267+
wrapperEl.insertAdjacentElement('beforeend', img);
268+
269+
const perform = async () => {
270+
const flyovers = await layer.findFlyovers(bbox4326, fromTime, toTime, 50, 50);
271+
flyoversContainerEl.innerHTML = JSON.stringify(flyovers, null, true);
272+
273+
// prepare an image to show that the number makes sense:
274+
const getMapParams = {
275+
bbox: bbox4326,
276+
fromTime: fromTime,
277+
toTime: toTime,
278+
width: 512,
279+
height: 512,
280+
format: MimeTypes.JPEG,
281+
};
282+
const imageBlob = await layer.getMap(getMapParams, ApiType.WMS);
283+
img.src = URL.createObjectURL(imageBlob);
284+
};
285+
perform().then(() => {});
286+
287+
return wrapperEl;
288+
};
289+
290+
export const findDatesUTCSearchIndex = () =>
291+
createFindDatesUTCStory(
292+
new Landsat15AWSLMSSL1Layer({ instanceId, layerId, maxCloudCoverPercent: 40 }),
293+
bbox4326,
294+
fromTime,
295+
toTime,
296+
false,
297+
);
298+
export const findDatesUTCCatalog = () =>
299+
createFindDatesUTCStory(
300+
new Landsat15AWSLMSSL1Layer({ instanceId, layerId, maxCloudCoverPercent: 40 }),
301+
bbox4326,
302+
fromTime,
303+
toTime,
304+
true,
305+
);
306+
307+
export const stats = () => {
308+
const wrapperEl = document.createElement('div');
309+
const containerEl = document.createElement('pre');
310+
wrapperEl.innerHTML = '<h2>getStats</h2>';
311+
wrapperEl.insertAdjacentElement('beforeend', containerEl);
312+
313+
const layer = new Landsat15AWSLMSSL1Layer({ instanceId, layerId: layerIdNdvi, maxCloudCoverPercent: 100 });
314+
315+
const params = {
316+
fromTime: fromTime,
317+
toTime: toTime,
318+
resolution: 350,
319+
bins: 10,
320+
geometry: bbox4326.toGeoJSON(),
321+
};
322+
323+
const perform = async () => {
324+
const stats = await layer.getStats(params);
325+
containerEl.innerHTML = JSON.stringify(stats, null, true);
326+
};
327+
perform().then(() => {});
328+
return wrapperEl;
329+
};
330+
331+
export const statsBBOX3857 = () => {
332+
const wrapperEl = document.createElement('div');
333+
const containerEl = document.createElement('pre');
334+
wrapperEl.innerHTML = '<h2>getStats for EPSG:3857</h2>';
335+
wrapperEl.insertAdjacentElement('beforeend', containerEl);
336+
337+
const layer = new Landsat15AWSLMSSL1Layer({ instanceId, layerId: layerIdNdvi, maxCloudCoverPercent: 100 });
338+
339+
const params = {
340+
fromTime: fromTime,
341+
toTime: toTime,
342+
resolution: 350,
343+
bins: 10,
344+
geometry: bbox.toGeoJSON(),
345+
};
346+
347+
const perform = async () => {
348+
const stats = await layer.getStats(params);
349+
containerEl.innerHTML = JSON.stringify(stats, null, true);
350+
};
351+
perform().then(() => {});
352+
return wrapperEl;
353+
};

0 commit comments

Comments
 (0)