Skip to content

Add filtering by s3:type #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 95 additions & 1 deletion src/layer/S3SYNL2CDASLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,45 @@ import { DATASET_CDAS_S3SYNERGYL2 } from './dataset';
import { AbstractSentinelHubV3WithCCLayer } from './AbstractSentinelHubV3WithCCLayer';
import { RequestConfiguration } from '../utils/cancelRequests';

import { PaginatedTiles, Link, LinkType, FindTilesAdditionalParameters } from './const';
import { PaginatedTiles, Link, LinkType, FindTilesAdditionalParameters, DataProductId } from './const';
import { ProcessingPayload } from './processing';

interface ConstructorParameters {
instanceId?: string | null;
layerId?: string | null;
evalscript?: string | null;
evalscriptUrl?: string | null;
dataProduct?: DataProductId | null;
title?: string | null;
description?: string | null;
legendUrl?: string | null;
maxCloudCoverPercent?: number | null;
highlights?: AbstractSentinelHubV3WithCCLayer['highlights'];
s3Type?: string | null;
}

type S3SYNL2FindTilesDatasetParameters = {
type?: string;
s3Type?: string | null;
};

export class S3SYNL2CDASLayer extends AbstractSentinelHubV3WithCCLayer {
public readonly dataset = DATASET_CDAS_S3SYNERGYL2;
public s3Type: string | null;

public constructor(props: ConstructorParameters) {
super(props);
this.s3Type = props.s3Type;
}

public async _updateProcessingGetMapPayload(
payload: ProcessingPayload,
datasetSeqNo: number = 0,
): Promise<ProcessingPayload> {
payload = await super._updateProcessingGetMapPayload(payload);
payload.input.data[datasetSeqNo].dataFilter.s3Type = this.s3Type;
return payload;
}

protected convertResponseFromSearchIndex(response: {
data: { tiles: any[]; hasMore: boolean };
Expand All @@ -27,9 +58,32 @@ export class S3SYNL2CDASLayer extends AbstractSentinelHubV3WithCCLayer {
};
}

protected extractFindTilesMeta(tile: any): Record<string, any> {
return {
...super.extractFindTilesMeta(tile),
s3Type: tile.s3Type,
};
}

protected extractFindTilesMetaFromCatalog(feature: Record<string, any>): Record<string, any> {
let result: Record<string, any> = {};

if (!feature) {
return result;
}

result = {
...super.extractFindTilesMetaFromCatalog(feature),
s3Type: feature.properties['s3:type'],
};

return result;
}

protected getFindTilesAdditionalParameters(): FindTilesAdditionalParameters {
const findTilesDatasetParameters: S3SYNL2FindTilesDatasetParameters = {
type: this.dataset.shProcessingApiDatasourceAbbreviation,
s3Type: this.s3Type,
};

return {
Expand All @@ -47,6 +101,10 @@ export class S3SYNL2CDASLayer extends AbstractSentinelHubV3WithCCLayer {
},
};

if (this.s3Type) {
result.datasetParameters.s3Type = this.s3Type;
}

if (this.maxCloudCoverPercent !== null) {
result.maxCloudCoverage = this.maxCloudCoverPercent / 100;
}
Expand Down Expand Up @@ -79,4 +137,40 @@ export class S3SYNL2CDASLayer extends AbstractSentinelHubV3WithCCLayer {
}
return result;
}

protected createCatalogFilterQuery(
maxCloudCoverPercent?: number | null,
datasetParameters?: Record<string, any> | null,
): Record<string, any> {
let result = { ...super.createCatalogFilterQuery(maxCloudCoverPercent, datasetParameters) };

let conditions = [];
if (result) {
conditions.push(result);
}

if (this.s3Type) {
conditions.push({
op: '=',
args: [
{
property: 's3:type',
},
this.s3Type,
],
});
}

// combine multiple conditions with AND
if (conditions.length > 1) {
result = {
op: 'and',
args: conditions,
};
} else if (conditions.length === 1) {
result = conditions[0];
}

return result && Object.keys(result).length > 0 ? result : null;
}
}