From 1c91cc1a5c9ea6daf79d4d1c568a543cd5dce540 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Wed, 2 Oct 2024 14:08:56 +0200 Subject: [PATCH] refactor(entwineSource): read crs from metadata.srs --- src/Source/EntwinePointTileSource.js | 19 ++++++--- test/unit/entwine.js | 58 ++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/Source/EntwinePointTileSource.js b/src/Source/EntwinePointTileSource.js index 97a83dcb44..59621f4cfc 100644 --- a/src/Source/EntwinePointTileSource.js +++ b/src/Source/EntwinePointTileSource.js @@ -40,12 +40,20 @@ class EntwinePointTileSource extends Source { this.parse = metadata.dataType === 'laszip' ? LASParser.parse : PotreeBinParser.parse; this.extension = metadata.dataType === 'laszip' ? 'laz' : 'bin'; - if (metadata.srs && metadata.srs.authority && metadata.srs.horizontal) { - this.crs = `${metadata.srs.authority}:${metadata.srs.horizontal}`; - if (!proj4.defs(this.crs)) { - proj4.defs(this.crs, metadata.srs.wkt); + if (metadata.srs) { + if (metadata.srs.authority && metadata.srs.horizontal) { + this.crs = `${metadata.srs.authority}:${metadata.srs.horizontal}`; + if (!proj4.defs(this.crs)) { + proj4.defs(this.crs, metadata.srs.wkt); + } + } else if (metadata.srs.wkt) { + proj4.defs('unknown', metadata.srs.wkt); + const projCS = proj4.defs('unknown'); + this.crs = projCS.title || projCS.name; + if (!proj4.defs(this.crs)) { + proj4.defs(this.crs, projCS); + } } - if (metadata.srs.vertical && metadata.srs.vertical !== metadata.srs.horizontal) { console.warn('EntwinePointTileSource: Vertical coordinates system code is not yet supported.'); } @@ -58,6 +66,7 @@ class EntwinePointTileSource extends Source { + Math.abs(metadata.boundsConforming[4] - metadata.boundsConforming[1])) / (2 * metadata.span); this.boundsConforming = metadata.boundsConforming; + this.bounds = metadata.bounds; this.span = metadata.span; return this; diff --git a/test/unit/entwine.js b/test/unit/entwine.js index 7a96be6bdd..7a022d82e9 100644 --- a/test/unit/entwine.js +++ b/test/unit/entwine.js @@ -10,16 +10,24 @@ import sinon from 'sinon'; import Fetcher from 'Provider/Fetcher'; import Renderer from './bootstrap'; -import ept from '../data/entwine/ept.json'; -import eptHierarchy from '../data/entwine/ept-hierarchy/0-0-0-0.json'; +import eptFile from '../data/entwine/ept.json'; +import eptHierarchyFile from '../data/entwine/ept-hierarchy/0-0-0-0.json'; -const baseurl = 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds'; -const urlEpt = `${baseurl}/entwine/ept.json`; -const urlEptHierarchy = `${baseurl}/entwine/ept-hierarchy/0-0-0-0.json`; +// LASParser need to be mocked instead of calling it +LASParser.enableLazPerf('./examples/libs/laz-perf'); + +const baseurl = 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine'; + +const eptSsAuthority = JSON.parse(eptFile); +eptSsAuthority.srs = { + wkt: 'PROJCS["RGF93 v1 / Lambert-93",GEOGCS["RGF93 v1",DATUM["Reseau_Geodesique_Francais_1993_v1",SPHEROID["GRS 1980",6378137,298.257222101],TOWGS84[0,0,0,0,0,0,0]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4171"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",46.5],PARAMETER["central_meridian",3],PARAMETER["standard_parallel_1",49],PARAMETER["standard_parallel_2",44],PARAMETER["false_easting",700000],PARAMETER["false_northing",6600000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","2154"]]', + // wkt: 'PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]]', +}; const resources = { - [urlEpt]: ept, - [urlEptHierarchy]: eptHierarchy, + [`${baseurl}/ept.json`]: JSON.parse(eptFile), + 'withoutAutority/ept.json': eptSsAuthority, + [`${baseurl}/ept-hierarchy/0-0-0-0.json`]: JSON.parse(eptHierarchyFile), }; describe('Entwine Point Tile', function () { @@ -29,15 +37,12 @@ describe('Entwine Point Tile', function () { before(function () { stubFetcherJson = sinon.stub(Fetcher, 'json') - .callsFake(url => Promise.resolve(JSON.parse(resources[url]))); + .callsFake(url => Promise.resolve(resources[url])); stubFetcherArrayBuf = sinon.stub(Fetcher, 'arrayBuffer') .callsFake(() => Promise.resolve(new ArrayBuffer())); // currently no test on data fetched... LASParser.enableLazPerf('./examples/libs/laz-perf'); - source = new EntwinePointTileSource({ - url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine', - }); }); after(async function () { @@ -46,11 +51,32 @@ describe('Entwine Point Tile', function () { await LASParser.terminate(); }); - it('loads the EPT structure', (done) => { - source.whenReady - .then(() => { - done(); - }).catch(done); + describe('Entwine Point Tile Source', function () { + describe('data type', function () { + // TO DO dataType in [laszip, binary, zstandard] + }); + describe('retrieving crs from srs information', function () { + it('No srs authority', (done) => { + source = new EntwinePointTileSource({ + url: 'withoutAutority', + }); + source.whenReady + .then(() => { + assert.equal(source.crs, 'RGF93 v1 / Lambert-93'); + done(); + }).catch(done); + }); + it('With srs authority', (done) => { + source = new EntwinePointTileSource({ + url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine', + }); + source.whenReady + .then(() => { + assert.equal(source.crs, 'EPSG:3857'); + done(); + }).catch(done); + }); + }); }); describe('Layer', function () {