|
1 | 1 | import { LazPerf } from 'laz-perf';
|
2 | 2 | import { Las } from 'copc';
|
3 |
| -import Coordinates from 'Core/Geographic/Coordinates'; |
| 3 | +import proj4 from 'proj4'; |
4 | 4 |
|
5 | 5 | /**
|
6 | 6 | * @typedef {Object} Header - Partial LAS header.
|
@@ -75,30 +75,25 @@ class LASLoader {
|
75 | 75 | */
|
76 | 76 | const scanAngles = new Float32Array(view.pointCount);
|
77 | 77 |
|
78 |
| - const coord = new Coordinates(options.crsIn, 0, 0, 0); |
79 |
| - const coordProj = new Coordinates(options.crsOut, 0, 0, 0); |
80 |
| - |
| 78 | + const projection = proj4.defs(options.crsOut); |
81 | 79 | for (let i = 0; i < view.pointCount; i++) {
|
82 | 80 | // `getPosition` apply scale and offset transform to the X, Y, Z
|
83 | 81 | // values. See https://github.com/connormanning/copc.js/blob/master/src/las/extractor.ts.
|
84 | 82 | const [x, y, z] = getPosition.map(f => f(i));
|
85 | 83 | positions[i * 3] = x;
|
86 | 84 | positions[i * 3 + 1] = y;
|
87 | 85 | positions[i * 3 + 2] = z;
|
| 86 | + elevations[i] = z; |
88 | 87 |
|
| 88 | + if (projection) { |
89 | 89 | // Calculate positions on view.crs
|
90 |
| - coord.setFromValues( |
91 |
| - positions[i * 3], |
92 |
| - positions[i * 3 + 1], |
93 |
| - positions[i * 3 + 2], |
94 |
| - ); |
95 |
| - coord.as(options.crsOut, coordProj); |
96 |
| - positionsProj[i * 3] = coordProj.x; |
97 |
| - positionsProj[i * 3 + 1] = coordProj.y; |
98 |
| - positionsProj[i * 3 + 2] = coordProj.z; |
99 |
| - elevations[i] = coordProj.z; |
100 |
| - // geocentric height to elevation |
101 |
| - if (options.crsOut === 'EPSG:4978') { elevations[i] = positions[i * 3 + 2]; } |
| 90 | + const [xProj, yProj, zProj] = proj4(options.crsIn, options.crsOut).forward([x, y, z]); |
| 91 | + positionsProj[i * 3] = xProj; |
| 92 | + positionsProj[i * 3 + 1] = yProj; |
| 93 | + positionsProj[i * 3 + 2] = zProj; |
| 94 | + // geocentric height to elevation |
| 95 | + if (projection.projName !== 'geocent') { elevations[i] = zProj; } |
| 96 | + } |
102 | 97 |
|
103 | 98 | intensities[i] = getIntensity(i);
|
104 | 99 | returnNumbers[i] = getReturnNumber(i);
|
|
0 commit comments