Skip to content

Commit e0a8c75

Browse files
Merge pull request #34 from sentinel-hub/fix/flyovers-landsat8
Fix findTiles() for Landsat8 on AWS
2 parents cb04037 + eff93d8 commit e0a8c75

File tree

8 files changed

+258
-95
lines changed

8 files changed

+258
-95
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ S3OLCI_LAYER_ID=
1212
BYOC_LAYER_ID=
1313
BYOC_COLLECTION_ID=
1414
S5PL2_LAYER_ID=
15+
LANDSAT8_LAYER_ID=
1516

1617
EOC_INSTANCE_ID=
1718
EOC_S1GRDIW_LAYER_ID=

src/layer/AbstractSentinelHubV3Layer.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios, { AxiosRequestConfig } from 'axios';
22

33
import { getAuthToken, isAuthTokenSet } from 'src/auth';
44
import { BBox } from 'src/bbox';
5-
import { GetMapParams, ApiType } from 'src/layer/const';
5+
import { GetMapParams, ApiType, PaginatedTiles } from 'src/layer/const';
66
import { fetchCached } from 'src/layer/utils';
77
import { wmsGetMapUrl } from 'src/layer/wms';
88
import { processingGetMap, createProcessingPayload, ProcessingPayload } from 'src/layer/processing';
@@ -148,6 +148,24 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
148148
return requestConfig;
149149
}
150150

151+
public async findTiles(
152+
bbox: BBox,
153+
fromTime: Date,
154+
toTime: Date,
155+
maxCount?: number,
156+
offset?: number,
157+
): Promise<PaginatedTiles> {
158+
const response = await this.fetchTiles(bbox, fromTime, toTime, maxCount, offset);
159+
return {
160+
tiles: response.data.tiles.map(tile => ({
161+
geometry: tile.dataGeometry,
162+
sensingTime: new Date(tile.sensingTime),
163+
meta: {},
164+
})),
165+
hasMore: response.data.hasMore,
166+
};
167+
}
168+
151169
protected fetchTiles(
152170
bbox: BBox,
153171
fromTime: Date,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { BBox } from 'src/bbox';
2+
import { PaginatedTiles } from 'src/layer/const';
3+
import { AbstractSentinelHubV3Layer } from './AbstractSentinelHubV3Layer';
4+
5+
// same as AbstractSentinelHubV3Layer, but with maxCloudCoverPercent (for layers which support it)
6+
export class AbstractSentinelHubV3WithCCLayer extends AbstractSentinelHubV3Layer {
7+
public maxCloudCoverPercent: number;
8+
9+
public constructor(
10+
instanceId: string | null,
11+
layerId: string | null = null,
12+
evalscript: string | null = null,
13+
evalscriptUrl: string | null = null,
14+
dataProduct: string | null = null,
15+
title: string | null = null,
16+
description: string | null = null,
17+
maxCloudCoverPercent: number | null = 100,
18+
) {
19+
super(instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description);
20+
this.maxCloudCoverPercent = maxCloudCoverPercent;
21+
}
22+
23+
public async findTiles(
24+
bbox: BBox,
25+
fromTime: Date,
26+
toTime: Date,
27+
maxCount?: number,
28+
offset?: number,
29+
): Promise<PaginatedTiles> {
30+
const response = await this.fetchTiles(
31+
bbox,
32+
fromTime,
33+
toTime,
34+
maxCount,
35+
offset,
36+
this.maxCloudCoverPercent,
37+
);
38+
return {
39+
tiles: response.data.tiles.map(tile => ({
40+
geometry: tile.dataGeometry,
41+
sensingTime: new Date(tile.sensingTime),
42+
meta: {
43+
cloudCoverPercent: tile.cloudCoverPercentage,
44+
},
45+
})),
46+
hasMore: response.data.hasMore,
47+
};
48+
}
49+
}

src/layer/Landsat8AWSLayer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DATASET_AWS_L8L1C } from 'src/layer/dataset';
2-
import { AbstractSentinelHubV3Layer } from 'src/layer/AbstractSentinelHubV3Layer';
2+
import { AbstractSentinelHubV3WithCCLayer } from './AbstractSentinelHubV3WithCCLayer';
33

4-
export class Landsat8AWSLayer extends AbstractSentinelHubV3Layer {
4+
export class Landsat8AWSLayer extends AbstractSentinelHubV3WithCCLayer {
55
public readonly dataset = DATASET_AWS_L8L1C;
66
}

src/layer/S2L1CLayer.ts

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
1-
import { BBox } from 'src/bbox';
2-
import { PaginatedTiles } from 'src/layer/const';
31
import { DATASET_S2L1C } from 'src/layer/dataset';
4-
import { AbstractSentinelHubV3Layer } from 'src/layer/AbstractSentinelHubV3Layer';
2+
import { AbstractSentinelHubV3WithCCLayer } from './AbstractSentinelHubV3WithCCLayer';
53
import { ProcessingPayload } from 'src/layer/processing';
64

7-
export class S2L1CLayer extends AbstractSentinelHubV3Layer {
5+
export class S2L1CLayer extends AbstractSentinelHubV3WithCCLayer {
86
public readonly dataset = DATASET_S2L1C;
9-
public maxCloudCoverPercent: number;
10-
11-
public constructor(
12-
instanceId: string | null,
13-
layerId: string | null = null,
14-
evalscript: string | null = null,
15-
evalscriptUrl: string | null = null,
16-
dataProduct: string | null = null,
17-
title: string | null = null,
18-
description: string | null = null,
19-
maxCloudCoverPercent: number | null = 100,
20-
) {
21-
super(instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description);
22-
this.maxCloudCoverPercent = maxCloudCoverPercent;
23-
}
247

258
protected async updateProcessingGetMapPayload(payload: ProcessingPayload): Promise<ProcessingPayload> {
269
payload.input.data[0].dataFilter.maxCloudCoverage = this.maxCloudCoverPercent;
@@ -32,31 +15,4 @@ export class S2L1CLayer extends AbstractSentinelHubV3Layer {
3215
maxcc: this.maxCloudCoverPercent,
3316
};
3417
}
35-
36-
public async findTiles(
37-
bbox: BBox,
38-
fromTime: Date,
39-
toTime: Date,
40-
maxCount?: number,
41-
offset?: number,
42-
): Promise<PaginatedTiles> {
43-
const response = await this.fetchTiles(
44-
bbox,
45-
fromTime,
46-
toTime,
47-
maxCount,
48-
offset,
49-
this.maxCloudCoverPercent,
50-
);
51-
return {
52-
tiles: response.data.tiles.map(tile => ({
53-
geometry: tile.dataGeometry,
54-
sensingTime: new Date(tile.sensingTime),
55-
meta: {
56-
cloudCoverPercent: tile.cloudCoverPercentage,
57-
},
58-
})),
59-
hasMore: response.data.hasMore,
60-
};
61-
}
6218
}

src/layer/S2L2ALayer.ts

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
1-
import { BBox } from 'src/bbox';
2-
import { PaginatedTiles } from 'src/layer/const';
31
import { DATASET_S2L2A } from 'src/layer/dataset';
4-
import { AbstractSentinelHubV3Layer } from 'src/layer/AbstractSentinelHubV3Layer';
2+
import { AbstractSentinelHubV3WithCCLayer } from './AbstractSentinelHubV3WithCCLayer';
53
import { ProcessingPayload } from 'src/layer/processing';
64

7-
export class S2L2ALayer extends AbstractSentinelHubV3Layer {
5+
export class S2L2ALayer extends AbstractSentinelHubV3WithCCLayer {
86
public readonly dataset = DATASET_S2L2A;
9-
public maxCloudCoverPercent: number;
10-
11-
public constructor(
12-
instanceId: string | null,
13-
layerId: string | null = null,
14-
evalscript: string | null = null,
15-
evalscriptUrl: string | null = null,
16-
dataProduct: string | null = null,
17-
title: string | null = null,
18-
description: string | null = null,
19-
maxCloudCoverPercent: number | null = 100,
20-
) {
21-
super(instanceId, layerId, evalscript, evalscriptUrl, dataProduct, title, description);
22-
this.maxCloudCoverPercent = maxCloudCoverPercent;
23-
}
247

258
protected async updateProcessingGetMapPayload(payload: ProcessingPayload): Promise<ProcessingPayload> {
269
payload.input.data[0].dataFilter.maxCloudCoverage = this.maxCloudCoverPercent;
@@ -32,31 +15,4 @@ export class S2L2ALayer extends AbstractSentinelHubV3Layer {
3215
maxcc: this.maxCloudCoverPercent,
3316
};
3417
}
35-
36-
public async findTiles(
37-
bbox: BBox,
38-
fromTime: Date,
39-
toTime: Date,
40-
maxCount?: number,
41-
offset?: number,
42-
): Promise<PaginatedTiles> {
43-
const response = await this.fetchTiles(
44-
bbox,
45-
fromTime,
46-
toTime,
47-
maxCount,
48-
offset,
49-
this.maxCloudCoverPercent,
50-
);
51-
return {
52-
tiles: response.data.tiles.map(tile => ({
53-
geometry: tile.dataGeometry,
54-
sensingTime: new Date(tile.sensingTime),
55-
meta: {
56-
cloudCoverPercent: tile.cloudCoverPercentage,
57-
},
58-
})),
59-
hasMore: response.data.hasMore,
60-
};
61-
}
6218
}

stories/index.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export const S1GRDFindTiles = () => {
244244
wrapperEl.insertAdjacentElement("beforeend", containerEl);
245245

246246
const perform = async () => {
247+
await setAuthTokenWithOAuthCredentials();
247248
const data = await layerS1.findTiles(
248249
bbox,
249250
new Date(Date.UTC(2020, 1 - 1, 10, 0, 0, 0)),

0 commit comments

Comments
 (0)