From aa350a8f8ac24f83bc1f19dee1b5b7db7e15eb1c Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 1 Nov 2023 14:57:32 +1300 Subject: [PATCH] Remove the projection loader as duplicated function. --- packages/cli/package.json | 1 + packages/cli/src/cog/builder.ts | 2 +- packages/shared/package.json | 1 - packages/shared/src/cog/projection.loader.ts | 28 -------------------- 4 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 packages/shared/src/cog/projection.loader.ts diff --git a/packages/cli/package.json b/packages/cli/package.json index 16456ae5f6..ad17105be7 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -55,6 +55,7 @@ "ansi-colors": "^4.1.1", "deep-diff": "^1.0.2", "flatgeobuf": "^3.23.1", + "node-fetch": "^3.2.3", "p-limit": "^4.0.0", "pretty-json-log": "^1.0.0", "slugify": "^1.6.5", diff --git a/packages/cli/src/cog/builder.ts b/packages/cli/src/cog/builder.ts index 67838313b4..6994ed3008 100644 --- a/packages/cli/src/cog/builder.ts +++ b/packages/cli/src/cog/builder.ts @@ -5,7 +5,7 @@ import { CogTiff, TiffTag, TiffTagGeo } from '@cogeotiff/core'; import pLimit, { LimitFunction } from 'p-limit'; import { basename } from 'path'; import { Cutline } from './cutline.js'; // -import { ProjectionLoader } from '@basemaps/shared/src/cog/projection.loader.js'; +import { ProjectionLoader } from '@basemaps/geo/src/proj/projection.loader.js'; import { CogBuilderMetadata, SourceMetadata } from '@basemaps/shared/src/cog/types.js'; export const InvalidProjectionCode = 32767; diff --git a/packages/shared/package.json b/packages/shared/package.json index 835124dd2e..d6bb721a89 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -32,7 +32,6 @@ "@linzjs/metrics": "^6.41.0", "aws-sdk": "^2.890.0", "entities": "^4.3.0", - "node-fetch": "^3.2.3", "pino": "^8.6.1", "source-map-support": "^0.5.19", "ulid": "^2.3.0" diff --git a/packages/shared/src/cog/projection.loader.ts b/packages/shared/src/cog/projection.loader.ts deleted file mode 100644 index 72cae9c9f3..0000000000 --- a/packages/shared/src/cog/projection.loader.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Epsg, Projection } from '@basemaps/geo'; -import fetch from 'node-fetch'; - -export class ProjectionLoader { - // Exposed for testing - static _fetch = fetch; - - /** - * Ensure that a projection EPSG code is avialable for use in Proj4js - * - * If its not already loaded, lookup definition from spatialreference.org - * @param code - */ - static async load(code: number): Promise { - if (Projection.tryGet(code) != null) return Epsg.get(code); - const url = `https://spatialreference.org/ref/epsg/${code}/ogcwkt/`; - - const res = await this._fetch(url); - if (!res.ok) throw new Error('Failed to load projection information for:' + code); - - let epsg = Epsg.tryGet(code); - if (epsg == null) epsg = new Epsg(code); - - const text = await res.text(); - Projection.define(epsg, text); - return epsg; - } -}