Skip to content

Commit

Permalink
Add support for mosaickingOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
sinergise-anze committed Apr 23, 2020
1 parent 5f411d1 commit c7dfda7
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BBox } from 'src/bbox';
import { CRS_EPSG4326, CRS_EPSG3857, CRS_WGS84, SUPPORTED_CRS_OBJ } from 'src/crs';
import { setAuthToken, isAuthTokenSet, requestAuthToken } from 'src/auth';
import { ApiType, MimeTypes, OrbitDirection, PreviewMode } from 'src/layer/const';
import { ApiType, MimeTypes, OrbitDirection, PreviewMode, MosaickingOrder } from 'src/layer/const';
import { setDebugEnabled } from 'src/utils/debug';

import { LayersFactory } from 'src/layer/LayersFactory';
Expand Down Expand Up @@ -102,6 +102,7 @@ export {
Resolution,
OrbitDirection,
PreviewMode,
MosaickingOrder,
S3SLSTRView,
BBox,
setDebugEnabled,
Expand Down
17 changes: 15 additions & 2 deletions src/layer/ProcessingDataFusionLayer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { BBox } from 'src/bbox';
import { GetMapParams, Interpolator, PreviewMode, ApiType, PaginatedTiles } from 'src/layer/const';
import {
GetMapParams,
Interpolator,
PreviewMode,
ApiType,
PaginatedTiles,
MosaickingOrder,
} from 'src/layer/const';
import {
createProcessingPayload,
convertPreviewToString,
processingGetMap,
MosaickingOrder,
ProcessingPayloadDatasource,
} from 'src/layer/processing';
import { AbstractSentinelHubV3Layer } from 'src/layer/AbstractSentinelHubV3Layer';
Expand All @@ -27,6 +33,7 @@ export type DataFusionLayerInfo = {
fromTime?: Date;
toTime?: Date;
preview?: PreviewMode;
mosaickingOrder?: MosaickingOrder;
upsampling?: Interpolator;
downsampling?: Interpolator;
};
Expand Down Expand Up @@ -74,6 +81,12 @@ export class ProcessingDataFusionLayer extends AbstractSentinelHubV3Layer {
datasource.dataFilter.previewMode = convertPreviewToString(params.preview);
}

if (layerInfo.mosaickingOrder !== undefined) {
datasource.dataFilter.mosaickingOrder = layerInfo.mosaickingOrder;
} else if (params.mosaickingOrder !== undefined) {
datasource.dataFilter.mosaickingOrder = params.mosaickingOrder;
}

if (layerInfo.upsampling !== undefined) {
payload.input.data[0].processing.upsampling = layerInfo.upsampling;
} else if (params.upsampling !== undefined) {
Expand Down
7 changes: 7 additions & 0 deletions src/layer/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type GetMapParams = {
height?: number;
// optional additional parameters:
preview?: PreviewMode;
mosaickingOrder?: MosaickingOrder;
geometry?: Polygon | MultiPolygon;
quality?: number;
gain?: number;
Expand All @@ -44,6 +45,12 @@ export enum PreviewMode {
EXTENDED_PREVIEW = 2,
}

export enum MosaickingOrder {
MOST_RECENT = 'mostRecent',
LEAST_RECENT = 'leastRecent',
LEAST_CC = 'leastCC',
}

export enum ApiType {
WMS = 'wms',
PROCESSING = 'processing',
Expand Down
11 changes: 4 additions & 7 deletions src/layer/processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import axios, { AxiosRequestConfig } from 'axios';
import { Polygon, BBox as BBoxTurf, MultiPolygon } from '@turf/helpers';

import { getAuthToken } from 'src/auth';
import { MimeType, GetMapParams, Interpolator, PreviewMode } from 'src/layer/const';
import { MimeType, GetMapParams, Interpolator, PreviewMode, MosaickingOrder } from 'src/layer/const';
import { Dataset } from 'src/layer/dataset';

export enum MosaickingOrder {
MOST_RECENT = 'mostRecent',
LEAST_RECENT = 'leastRecent',
LEAST_CC = 'leastCC',
}

enum PreviewModeString {
DETAIL = 'DETAIL',
PREVIEW = 'PREVIEW',
Expand Down Expand Up @@ -143,6 +137,9 @@ export function createProcessingPayload(
if (params.preview !== undefined) {
payload.input.data[0].dataFilter.previewMode = convertPreviewToString(params.preview);
}
if (params.mosaickingOrder !== undefined) {
payload.input.data[0].dataFilter.mosaickingOrder = params.mosaickingOrder;
}

//dataProduct should not be set if evalscript is passed as parameter
if (evalscript) {
Expand Down
6 changes: 5 additions & 1 deletion src/layer/wms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import moment from 'moment';
import WKT from 'terraformer-wkt-parser';

import { CRS_EPSG4326, CRS_IDS } from 'src/crs';
import { GetMapParams, MimeTypes, MimeType } from 'src/layer/const';
import { GetMapParams, MimeTypes, MimeType, MosaickingOrder } from 'src/layer/const';

export enum ServiceType {
WMS = 'WMS',
Expand Down Expand Up @@ -32,6 +32,7 @@ type OgcGetMapOptions = {
evalscript?: string;
evalscripturl?: string;
preview?: number;
priority?: MosaickingOrder;
geometry?: string;
quality?: number;
evalsource?: string;
Expand Down Expand Up @@ -130,6 +131,9 @@ export function wmsGetMapUrl(
if (params.preview !== undefined) {
queryParams.preview = params.preview;
}
if (params.mosaickingOrder !== undefined) {
queryParams.priority = params.mosaickingOrder;
}
if (params.geometry) {
queryParams.geometry = WKT.convert(params.geometry);
}
Expand Down
3 changes: 3 additions & 0 deletions stories/datafusion.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ApiType,
S2L1CLayer,
S2L2ALayer,
MosaickingOrder,
} from '../dist/sentinelHub.esm';

if (!process.env.INSTANCE_ID) {
Expand Down Expand Up @@ -60,6 +61,7 @@ export const getMapProcessing = () => {
id: 'l2a',
fromTime: new Date(Date.UTC(2020, 1 - 1, 1, 0, 0, 0)),
toTime: new Date(Date.UTC(2020, 2 - 1, 26, 0, 0, 0)),
mosaickingOrder: MosaickingOrder.LEAST_RECENT,
},
{
layer: layerS2L1C,
Expand Down Expand Up @@ -100,6 +102,7 @@ export const getMapProcessing = () => {
width: 300,
height: 300,
format: MimeTypes.JPEG,
mosaickingOrder: MosaickingOrder.LEAST_CC,
};
const imageBlob = await layer.getMap(getMapParams, ApiType.PROCESSING);
img.src = URL.createObjectURL(imageBlob);
Expand Down
96 changes: 96 additions & 0 deletions stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BBox,
MimeTypes,
ApiType,
MosaickingOrder,
} from '../dist/sentinelHub.esm';

if (!process.env.INSTANCE_ID) {
Expand Down Expand Up @@ -293,3 +294,98 @@ export const S2FindFlyovers = () => {

return wrapperEl;
};

export const MosaickingOrderWMS = () => {
const img1 = document.createElement('img');
img1.width = '512';
img1.height = '512';
const img2 = document.createElement('img');
img2.width = '512';
img2.height = '512';
const img3 = document.createElement('img');
img3.width = '512';
img3.height = '512';

const wrapperEl = document.createElement('div');
wrapperEl.innerHTML = '<h2>WMS mosaicking order - mostRecent, leastRecent and leastCC</h2>';
wrapperEl.insertAdjacentElement('beforeend', img1);
wrapperEl.insertAdjacentElement('beforeend', img2);
wrapperEl.insertAdjacentElement('beforeend', img3);

const perform = async () => {
await setAuthTokenWithOAuthCredentials();

const layerS2L2A = new S2L2ALayer({
instanceId,
layerId: s2l2aLayerId,
evalscript: 'return [2.5 * B04, 2.5 * B03, 2.5 * B02]',
});
const getMapParams = {
bbox: bbox4326,
fromTime: new Date(Date.UTC(2018, 11 - 1, 22, 0, 0, 0)),
toTime: new Date(Date.UTC(2018, 12 - 1, 22, 23, 59, 59)),
width: 512,
height: 512,
format: MimeTypes.JPEG,
};
getMapParams.mosaickingOrder = MosaickingOrder.MOST_RECENT;
img1.src = URL.createObjectURL(await layerS2L2A.getMap(getMapParams, ApiType.WMS));
getMapParams.mosaickingOrder = MosaickingOrder.LEAST_RECENT;
img2.src = URL.createObjectURL(await layerS2L2A.getMap(getMapParams, ApiType.WMS));
getMapParams.mosaickingOrder = MosaickingOrder.LEAST_CC;
img3.src = URL.createObjectURL(await layerS2L2A.getMap(getMapParams, ApiType.WMS));
};
perform().then(() => {});

return wrapperEl;
};

export const MosaickingOrderProcessing = () => {
if (!process.env.CLIENT_ID || !process.env.CLIENT_SECRET) {
return "<div>Please set OAuth Client's id and secret for Processing API (CLIENT_ID, CLIENT_SECRET env vars)</div>";
}

const img1 = document.createElement('img');
img1.width = '512';
img1.height = '512';
const img2 = document.createElement('img');
img2.width = '512';
img2.height = '512';
const img3 = document.createElement('img');
img3.width = '512';
img3.height = '512';

const wrapperEl = document.createElement('div');
wrapperEl.innerHTML = '<h2>Processing mosaicking order - mostRecent, leastRecent and leastCC</h2>';
wrapperEl.insertAdjacentElement('beforeend', img1);
wrapperEl.insertAdjacentElement('beforeend', img2);
wrapperEl.insertAdjacentElement('beforeend', img3);

// getMap is async:
const perform = async () => {
await setAuthTokenWithOAuthCredentials();

const layerS2L2A = new S2L2ALayer({
instanceId,
layerId: s2l2aLayerId,
evalscript: 'return [2.5 * B04, 2.5 * B03, 2.5 * B02]',
});
const getMapParams = {
bbox: bbox4326,
fromTime: new Date(Date.UTC(2018, 11 - 1, 22, 0, 0, 0)),
toTime: new Date(Date.UTC(2018, 12 - 1, 22, 23, 59, 59)),
width: 512,
height: 512,
format: MimeTypes.JPEG,
};
getMapParams.mosaickingOrder = MosaickingOrder.MOST_RECENT;
img1.src = URL.createObjectURL(await layerS2L2A.getMap(getMapParams, ApiType.PROCESSING));
getMapParams.mosaickingOrder = MosaickingOrder.LEAST_RECENT;
img2.src = URL.createObjectURL(await layerS2L2A.getMap(getMapParams, ApiType.PROCESSING));
getMapParams.mosaickingOrder = MosaickingOrder.LEAST_CC;
img3.src = URL.createObjectURL(await layerS2L2A.getMap(getMapParams, ApiType.PROCESSING));
};
perform().then(() => {});

return wrapperEl;
};

0 comments on commit c7dfda7

Please sign in to comment.