Skip to content

Commit

Permalink
Merge pull request #31 from sentinel-hub/feature/flyovers-cc
Browse files Browse the repository at this point in the history
Return meta.averageCloudCoverPercent from findFlyovers()
  • Loading branch information
zcernigoj authored Feb 25, 2020
2 parents 4f9b90d + 1a373d0 commit 4104bc7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/layer/AbstractLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ export class AbstractLayer {

let flyoverIndex = 0;
let currentFlyoverGeometry = null;
let nTilesInFlyover = 0;
let sumCloudCoverPercent = undefined;
for (let tileIndex = 0; tileIndex < tiles.length; tileIndex++) {
if (tileIndex === 0) {
flyoverIntervals[flyoverIndex] = {
fromTime: tiles[tileIndex].sensingTime,
toTime: tiles[tileIndex].sensingTime,
coveragePercent: 0,
meta: {},
};
currentFlyoverGeometry = tiles[tileIndex].geometry;
sumCloudCoverPercent = tiles[tileIndex].meta.cloudCoverPercent;
nTilesInFlyover = 1;
continue;
}

Expand All @@ -109,25 +114,41 @@ export class AbstractLayer {
if (diffMS < orbitTimeMS) {
flyoverIntervals[flyoverIndex].toTime = tiles[tileIndex].sensingTime;
currentFlyoverGeometry = union(currentFlyoverGeometry, tiles[tileIndex].geometry);
sumCloudCoverPercent =
sumCloudCoverPercent !== undefined
? sumCloudCoverPercent + tiles[tileIndex].meta.cloudCoverPercent
: undefined;
nTilesInFlyover++;
} else {
flyoverIntervals[flyoverIndex].coveragePercent = this.calculateCoveragePercent(
bbox,
currentFlyoverGeometry,
);
if (sumCloudCoverPercent !== undefined) {
flyoverIntervals[flyoverIndex].meta.averageCloudCoverPercent =
sumCloudCoverPercent / nTilesInFlyover;
}

flyoverIndex++;
flyoverIntervals[flyoverIndex] = {
fromTime: tiles[tileIndex].sensingTime,
toTime: tiles[tileIndex].sensingTime,
coveragePercent: 0,
meta: {},
};
currentFlyoverGeometry = tiles[tileIndex].geometry;
sumCloudCoverPercent = tiles[tileIndex].meta.cloudCoverPercent;
nTilesInFlyover = 1;
}
}
if (flyoverIntervals.length > 0) {
flyoverIntervals[flyoverIndex].coveragePercent = this.calculateCoveragePercent(
bbox,
currentFlyoverGeometry,
);
if (sumCloudCoverPercent !== undefined) {
flyoverIntervals[flyoverIndex].meta.averageCloudCoverPercent = sumCloudCoverPercent / nTilesInFlyover;
}
}
return flyoverIntervals;
}
Expand Down
1 change: 1 addition & 0 deletions src/layer/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type FlyoverInterval = {
fromTime: Date;
toTime: Date;
coveragePercent: number;
meta: Record<string, any>;
};

export type MimeType =
Expand Down
46 changes: 46 additions & 0 deletions stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,52 @@ export const S1GRDFindTiles = () => {
return wrapperEl;
};

export const findFlyovers = () => {
const layer = new S2L2ALayer(instanceId, s2l2aLayerId);
const bbox = new BBox(CRS_EPSG4326, 11.9, 42.05, 12.95, 43.09);

const wrapperEl = document.createElement('div');
wrapperEl.innerHTML = "<h2>findFlyovers</h2>";

const img = document.createElement('img');
img.width = '512';
img.height = '512';
wrapperEl.insertAdjacentElement("beforeend", img);

const flyoversContainerEl = document.createElement('pre');
wrapperEl.insertAdjacentElement("beforeend", flyoversContainerEl);

const perform = async () => {
await setAuthTokenWithOAuthCredentials();
const fromTime = new Date(Date.UTC(2020, 1 - 1, 1, 0, 0, 0));
const toTime = new Date(Date.UTC(2020, 1 - 1, 15, 6, 59, 59));
const flyovers = await layer.findFlyovers(
bbox,
fromTime,
toTime,
20,
50,
);
flyoversContainerEl.innerHTML = JSON.stringify(flyovers, null, true)

// prepare an image to show that the number makes sense:
const getMapParams = {
bbox: bbox,
fromTime: fromTime,
toTime: toTime,
width: 512,
height: 512,
format: MimeTypes.JPEG,
};
const imageBlob = await layer.getMap(getMapParams, ApiType.WMS);
img.src = URL.createObjectURL(imageBlob);
};
perform().then(() => {});

return wrapperEl;
};


function renderTilesList(containerEl, list) {
list.forEach(tile => {
const ul = document.createElement('ul');
Expand Down

0 comments on commit 4104bc7

Please sign in to comment.