Skip to content

Commit

Permalink
refactor(CopcSource): use metadata.wkt to set source.crs
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff authored and Desplandis committed Dec 20, 2024
1 parent 1ecc6aa commit 69ed2f4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Source/CopcSource.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 31 additions & 0 deletions test/unit/copc.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit 69ed2f4

Please sign in to comment.