From 69ed2f474cc39241d43c8eca6734471238bcced2 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Mon, 7 Oct 2024 15:49:48 +0200 Subject: [PATCH] refactor(CopcSource): use metadata.wkt to set source.crs --- src/Source/CopcSource.js | 18 ++++++++++++++++-- test/unit/copc.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/unit/copc.js diff --git a/src/Source/CopcSource.js b/src/Source/CopcSource.js index 905c600803..9f91f27f57 100644 --- a/src/Source/CopcSource.js +++ b/src/Source/CopcSource.js @@ -1,3 +1,4 @@ +import proj4 from 'proj4'; import { Binary, Info, Las } from 'copc'; import Extent from 'Core/Geographic/Extent'; import Fetcher from 'Provider/Fetcher'; @@ -102,8 +103,21 @@ class CopcSource extends Source { this.header = metadata.header; this.info = metadata.info; this.eb = metadata.eb; - // TODO: use wkt definition in `metadata.wkt` to infer/define crs - this.crs = config.crs || 'EPSG:4326'; + + proj4.defs('unknown', metadata.wkt); + let projCS; + + if (proj4.defs('unknown').type === 'COMPD_CS') { + console.warn('CopcSource: compound coordinate system is not yet supported.'); + projCS = proj4.defs('unknown').PROJCS; + } else { + projCS = proj4.defs('unknown'); + } + + this.crs = projCS.title || projCS.name || 'EPSG:4326'; + if (!(this.crs in proj4.defs)) { + proj4.defs(this.crs, projCS); + } const bbox = new THREE.Box3(); bbox.min.fromArray(this.info.cube, 0); diff --git a/test/unit/copc.js b/test/unit/copc.js new file mode 100644 index 0000000000..c4d9286d34 --- /dev/null +++ b/test/unit/copc.js @@ -0,0 +1,31 @@ +import assert from 'assert'; +import { HttpsProxyAgent } from 'https-proxy-agent'; +import CopcSource from 'Source/CopcSource'; + +const copcUrl = 'https://s3.amazonaws.com/hobu-lidar/autzen-classified.copc.laz'; + +describe('COPC', function () { + let source; + + describe('Copc Source', function () { + describe('retrieving crs from wkt information', function () { + it('wkt.srs.type is COMPD_CS', function (done) { + const networkOptions = process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}; + source = new CopcSource({ + url: copcUrl, + networkOptions, + }); + source.whenReady + .then((headers) => { + assert.ok(headers.header.pointCount); + assert.ok(headers.info.spacing); + assert.ok(Array.isArray(headers.eb)); + assert.equal(source.crs, 'NAD83 / Oregon GIC Lambert (ft)'); + // when the proj4 PR will be merged we should change to : + // assert.equal(source.crs, 'EPSG:2992'); + done(); + }).catch(done); + }).timeout(5000); + }); + }); +});