Skip to content

Commit 14ca5e0

Browse files
committed
refactor(lasParser): remove import coord
1 parent 45e9fd9 commit 14ca5e0

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/Parser/LASLoader.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LazPerf } from 'laz-perf';
22
import { Las } from 'copc';
3-
import Coordinates from 'Core/Geographic/Coordinates';
3+
import proj4 from 'proj4';
44

55
/**
66
* @typedef {Object} Header - Partial LAS header.
@@ -75,30 +75,25 @@ class LASLoader {
7575
*/
7676
const scanAngles = new Float32Array(view.pointCount);
7777

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);
8179
for (let i = 0; i < view.pointCount; i++) {
8280
// `getPosition` apply scale and offset transform to the X, Y, Z
8381
// values. See https://github.com/connormanning/copc.js/blob/master/src/las/extractor.ts.
8482
const [x, y, z] = getPosition.map(f => f(i));
8583
positions[i * 3] = x;
8684
positions[i * 3 + 1] = y;
8785
positions[i * 3 + 2] = z;
86+
elevations[i] = z;
8887

88+
if (projection) {
8989
// 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+
}
10297

10398
intensities[i] = getIntensity(i);
10499
returnNumbers[i] = getReturnNumber(i);

0 commit comments

Comments
 (0)