Skip to content

Commit

Permalink
refactor(lasParser): remove import coord
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Feb 28, 2024
1 parent 8cf1e5d commit 41b9727
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/Parser/LASLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LazPerf } from 'laz-perf';
import { Las } from 'copc';
import Coordinates from 'Core/Geographic/Coordinates';
import proj4 from 'proj4';

/**
* @typedef {Object} Header - Partial LAS header.
Expand Down Expand Up @@ -75,30 +75,25 @@ class LASLoader {
*/
const scanAngles = new Float32Array(view.pointCount);

const coord = new Coordinates(options.crsIn, 0, 0, 0);
const coordProj = new Coordinates(options.crsOut, 0, 0, 0);

const projection = proj4.defs(options.crsOut);
for (let i = 0; i < view.pointCount; i++) {
// `getPosition` apply scale and offset transform to the X, Y, Z
// values. See https://github.com/connormanning/copc.js/blob/master/src/las/extractor.ts.
const [x, y, z] = getPosition.map(f => f(i));
positions[i * 3] = x;
positions[i * 3 + 1] = y;
positions[i * 3 + 2] = z;
elevations[i] = z;

if (projection) {
// Calculate positions on view.crs
coord.setFromValues(
positions[i * 3],
positions[i * 3 + 1],
positions[i * 3 + 2],
);
coord.as(options.crsOut, coordProj);
positionsProj[i * 3] = coordProj.x;
positionsProj[i * 3 + 1] = coordProj.y;
positionsProj[i * 3 + 2] = coordProj.z;
elevations[i] = coordProj.z;
// geocentric height to elevation
if (options.crsOut === 'EPSG:4978') { elevations[i] = positions[i * 3 + 2]; }
const [xProj, yProj, zProj] = proj4(options.crsIn, options.crsOut).forward([x, y, z]);
positionsProj[i * 3] = xProj;
positionsProj[i * 3 + 1] = yProj;
positionsProj[i * 3 + 2] = zProj;
// geocentric height to elevation
if (projection.projName !== 'geocent') { elevations[i] = zProj; }
}

intensities[i] = getIntensity(i);
returnNumbers[i] = getReturnNumber(i);
Expand Down

0 comments on commit 41b9727

Please sign in to comment.