diff --git a/src/Parser/LASLoader.js b/src/Parser/LASLoader.js index cfec8080ac..7024a39469 100644 --- a/src/Parser/LASLoader.js +++ b/src/Parser/LASLoader.js @@ -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. @@ -75,9 +75,7 @@ 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. @@ -85,20 +83,17 @@ class LASLoader { 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);