Skip to content

Commit

Permalink
refactor(entwineSource): read crs from metadata.srs
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Oct 10, 2024
1 parent f7d1bce commit 1c91cc1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
19 changes: 14 additions & 5 deletions src/Source/EntwinePointTileSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand All @@ -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;
Expand Down
58 changes: 42 additions & 16 deletions test/unit/entwine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand Down

0 comments on commit 1c91cc1

Please sign in to comment.