Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ecc6aa

Browse files
ftoromanoffDesplandis
authored andcommitted
refactor(entwineSource): read crs from metadata.srs
1 parent 628ed94 commit 1ecc6aa

File tree

2 files changed

+55
-21
lines changed

2 files changed

+55
-21
lines changed

src/Source/EntwinePointTileSource.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,20 @@ class EntwinePointTileSource extends Source {
4040
this.parse = metadata.dataType === 'laszip' ? LASParser.parse : PotreeBinParser.parse;
4141
this.extension = metadata.dataType === 'laszip' ? 'laz' : 'bin';
4242

43-
if (metadata.srs && metadata.srs.authority && metadata.srs.horizontal) {
44-
this.crs = `${metadata.srs.authority}:${metadata.srs.horizontal}`;
45-
if (!proj4.defs(this.crs)) {
46-
proj4.defs(this.crs, metadata.srs.wkt);
43+
if (metadata.srs) {
44+
if (metadata.srs.authority && metadata.srs.horizontal) {
45+
this.crs = `${metadata.srs.authority}:${metadata.srs.horizontal}`;
46+
if (!proj4.defs(this.crs)) {
47+
proj4.defs(this.crs, metadata.srs.wkt);
48+
}
49+
} else if (metadata.srs.wkt) {
50+
proj4.defs('unknown', metadata.srs.wkt);
51+
const projCS = proj4.defs('unknown');
52+
this.crs = projCS.title || projCS.name;
53+
if (!(this.crs in proj4.defs)) {
54+
proj4.defs(this.crs, projCS);
55+
}
4756
}
48-
4957
if (metadata.srs.vertical && metadata.srs.vertical !== metadata.srs.horizontal) {
5058
console.warn('EntwinePointTileSource: Vertical coordinates system code is not yet supported.');
5159
}
@@ -58,6 +66,7 @@ class EntwinePointTileSource extends Source {
5866
+ Math.abs(metadata.boundsConforming[4] - metadata.boundsConforming[1])) / (2 * metadata.span);
5967

6068
this.boundsConforming = metadata.boundsConforming;
69+
this.bounds = metadata.bounds;
6170
this.span = metadata.span;
6271

6372
return this;

test/unit/entwine.js

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@ import sinon from 'sinon';
1010
import Fetcher from 'Provider/Fetcher';
1111
import Renderer from './bootstrap';
1212

13-
import ept from '../data/entwine/ept.json';
14-
import eptHierarchy from '../data/entwine/ept-hierarchy/0-0-0-0.json';
13+
import eptFile from '../data/entwine/ept.json';
14+
import eptHierarchyFile from '../data/entwine/ept-hierarchy/0-0-0-0.json';
1515

16-
const baseurl = 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds';
17-
const urlEpt = `${baseurl}/entwine/ept.json`;
18-
const urlEptHierarchy = `${baseurl}/entwine/ept-hierarchy/0-0-0-0.json`;
16+
// LASParser need to be mocked instead of calling it
17+
LASParser.enableLazPerf('./examples/libs/laz-perf');
18+
19+
const baseurl = 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine';
20+
21+
const eptSsAuthority = JSON.parse(eptFile);
22+
eptSsAuthority.srs = {
23+
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"]]',
24+
};
1925

2026
const resources = {
21-
[urlEpt]: ept,
22-
[urlEptHierarchy]: eptHierarchy,
27+
[`${baseurl}/ept.json`]: JSON.parse(eptFile),
28+
'withoutAutority/ept.json': eptSsAuthority,
29+
[`${baseurl}/ept-hierarchy/0-0-0-0.json`]: JSON.parse(eptHierarchyFile),
2330
};
2431

2532
describe('Entwine Point Tile', function () {
@@ -29,15 +36,12 @@ describe('Entwine Point Tile', function () {
2936

3037
before(function () {
3138
stubFetcherJson = sinon.stub(Fetcher, 'json')
32-
.callsFake(url => Promise.resolve(JSON.parse(resources[url])));
39+
.callsFake(url => Promise.resolve(resources[url]));
3340
stubFetcherArrayBuf = sinon.stub(Fetcher, 'arrayBuffer')
3441
.callsFake(() => Promise.resolve(new ArrayBuffer()));
3542
// currently no test on data fetched...
3643

3744
LASParser.enableLazPerf('./examples/libs/laz-perf');
38-
source = new EntwinePointTileSource({
39-
url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine',
40-
});
4145
});
4246

4347
after(async function () {
@@ -46,11 +50,32 @@ describe('Entwine Point Tile', function () {
4650
await LASParser.terminate();
4751
});
4852

49-
it('loads the EPT structure', (done) => {
50-
source.whenReady
51-
.then(() => {
52-
done();
53-
}).catch(done);
53+
describe('Entwine Point Tile Source', function () {
54+
describe('data type', function () {
55+
// TO DO dataType in [laszip, binary, zstandard]
56+
});
57+
describe('retrieving crs from srs information', function () {
58+
it('No srs authority', (done) => {
59+
source = new EntwinePointTileSource({
60+
url: 'withoutAutority',
61+
});
62+
source.whenReady
63+
.then(() => {
64+
assert.equal(source.crs, 'RGF93 v1 / Lambert-93');
65+
done();
66+
}).catch(done);
67+
});
68+
it('With srs authority', (done) => {
69+
source = new EntwinePointTileSource({
70+
url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/entwine',
71+
});
72+
source.whenReady
73+
.then(() => {
74+
assert.equal(source.crs, 'EPSG:3857');
75+
done();
76+
}).catch(done);
77+
});
78+
});
5479
});
5580

5681
describe('Layer', function () {

0 commit comments

Comments
 (0)