Skip to content

Commit

Permalink
Reproject other projections to Mercator
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjak committed Jan 29, 2024
1 parent c1c1dc4 commit e1080d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/layer/AbstractSentinelHubV3Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
payload: ProcessingPayload,
datasetSeqNo: number = 0, // eslint-disable-line @typescript-eslint/no-unused-vars
reqConfig?: RequestConfiguration, // eslint-disable-line @typescript-eslint/no-unused-vars
params?: GetMapParams, // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<ProcessingPayload> {
// Subclasses should override this method if they wish to supply additional
// parameters to Processing API.
Expand Down Expand Up @@ -214,7 +215,7 @@ export class AbstractSentinelHubV3Layer extends AbstractLayer {
this.downsampling,
);
// allow subclasses to update payload with their own parameters:
const updatedPayload = await this._updateProcessingGetMapPayload(payload, 0, innerReqConfig);
const updatedPayload = await this._updateProcessingGetMapPayload(payload, 0, innerReqConfig, params);
const shServiceHostname = this.getShServiceHostname();
let blob = await processingGetMap(shServiceHostname, updatedPayload, innerReqConfig);

Expand Down
20 changes: 15 additions & 5 deletions src/layer/BYOCLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { ensureTimeout } from '../utils/ensureTimeout';
import { CACHE_CONFIG_30MIN } from '../utils/cacheHandlers';
import { StatisticsProviderType } from '../statistics/StatisticsProvider';
import { getSHServiceRootUrl } from './utils';
import { CRS_EPSG3857 } from '../crs';
import proj4 from 'proj4';

interface ConstructorParameters {
instanceId?: string | null;
Expand Down Expand Up @@ -143,13 +145,14 @@ export class BYOCLayer extends AbstractSentinelHubV3Layer {
payload: ProcessingPayload,
datasetSeqNo: number = 0,
reqConfig?: RequestConfiguration,
params?: GetMapParams,
): Promise<ProcessingPayload> {
await this.updateLayerFromServiceIfNeeded(reqConfig);

if (
this.lowResolutionCollectionId !== undefined &&
this.lowResolutionMetersPerPixelThreshold !== undefined &&
this.metersPerPixel(payload) > this.lowResolutionMetersPerPixelThreshold
this.metersPerPixel(params, payload) > this.lowResolutionMetersPerPixelThreshold
) {
payload.input.data[datasetSeqNo].type = this.getTypeIdLowRes();
} else {
Expand All @@ -160,11 +163,18 @@ export class BYOCLayer extends AbstractSentinelHubV3Layer {
return payload;
}

private metersPerPixel(payload: ProcessingPayload): number {
const bbox = payload.input.bounds.bbox;
private metersPerPixel(params: GetMapParams, payload: ProcessingPayload): number {
let bbox: BBox = params.bbox;

if (bbox.crs.authId !== CRS_EPSG3857.authId) {
[bbox.minX, bbox.minY] = proj4(bbox.crs.authId, CRS_EPSG3857.authId, [bbox.minX, bbox.minY]);
[bbox.maxX, bbox.maxY] = proj4(bbox.crs.authId, CRS_EPSG3857.authId, [bbox.maxX, bbox.maxY]);
bbox.crs = CRS_EPSG3857;
}

const width = payload.output.width;
const widthInMeters = Math.abs(bbox[2] - bbox[0]);
const latitude = (bbox[1] + bbox[3]) / 2;
const widthInMeters = Math.abs(bbox.maxX - bbox.minX);
const latitude = (bbox.minY + bbox.maxY) / 2;

return (widthInMeters / width) * Math.cos(this.lat(latitude));
}
Expand Down

0 comments on commit e1080d9

Please sign in to comment.