www.xbdev.net
xbdev - software development
Wednesday February 5, 2025
Home | Contact | Support | LIDAR (LAS) File Formats Point Cloud Data
>>
     
 

LIDAR (LAS) File Formats

Point Cloud Data

 


LiDAR DATA! It's the universal format for 3D point cloud data!



Simple web-based LAS file reader/parser - viewer - loads the file and dumps the values to the output.

Great little learning tool for understanding the format.


LiDAR parser output - for the listing shown below. Reads in a test file and dumps the coordinates to the output window.
LiDAR parser output - for the listing shown below. Reads in a test file and dumps the coordinates to the output window.


<html>
<
head>
  <
title>LAS File Parser xbdev.net</title>
</
head>
<
body>
  <
h1>LAS File Parser</h1>
  <
input type="file" id="fileInput" />
  <
button id="parseButton">Parse LAS File</button>
  <
pre id="output"></pre>

  <
script>
    
document.getElementById('parseButton').addEventListener('click', () => {
      const 
fileInput document.getElementById('fileInput');
      if (
fileInput.files.length === 0) {
        
alert('Please select a LAS file.');
        return;
      }
      
      const 
file fileInput.files[0];
      
parseLasFile(file);
    });

    
async function parseLasFile(file) {
      const 
arrayBuffer await file.arrayBuffer();
      const 
buffer = new DataView(arrayBuffer);

      
// Extract header information
      
const header = {};
      
header.fileSignature String.fromCharCode(...new Uint8Array(arrayBuffer.slice(04)));
      if (
header.fileSignature !== 'LASF') {
        
alert('Not a valid LAS file.');
        return;
      }
      
header.versionMajor buffer.getUint8(24);
      
header.versionMinor buffer.getUint8(25);
      
header.pointDataOffset buffer.getUint32(96true);
      
header.numberOfPointRecords buffer.getUint32(107true);
      
header.pointDataRecordFormat buffer.getUint8(104);
      
header.pointDataRecordLength buffer.getUint16(105true);
      
header.xScaleFactor buffer.getFloat64(131true);
      
header.yScaleFactor buffer.getFloat64(139true);
      
header.zScaleFactor buffer.getFloat64(147true);
      
header.xOffset buffer.getFloat64(155true);
      
header.yOffset buffer.getFloat64(163true);
      
header.zOffset buffer.getFloat64(171true);

      
console.log('Header:'header);

      const 
points = [];

      
// Read point data
      
const pointDataStart header.pointDataOffset;
      for (
let i 0header.numberOfPointRecordsi++) {
        const 
offset pointDataStart header.pointDataRecordLength;

        const 
xRaw buffer.getInt32(offsettrue);
        const 
yRaw buffer.getInt32(offset 4true);
        const 
zRaw buffer.getInt32(offset 8true);

        const 
xRaw header.xScaleFactor header.xOffset;
        const 
yRaw header.yScaleFactor header.yOffset;
        const 
zRaw header.zScaleFactor header.zOffset;

        if (
10) { // Only log the first 10 points to avoid excessive logging
          
console.log(`Point ${i}: raw(${xRaw}${yRaw}${zRaw}) -> scaled(${x}${y}${z})`);
        }

        
points.push({ xy});
      }

      
displayPoints(points);
    }

    function 
displayPoints(points) {
      const 
outputElement document.getElementById('output');
      
outputElement.textContent JSON.stringify(pointsnull2);
    }
  </
script>
</
body>
</
html>


Little looksy at what the output would look like:

log:["Header:",{"fileSignature":"LASF","versionMajor":1,"versionMinor":2,"pointDataOffset":331,"numberOfPointRecords":21932,
"pointDataRecordFormat":0,"pointDataRecordLength":20,"xScaleFactor":0.01,"yScaleFactor":0.01,"zScaleFactor":0.001,
"xOffset":2000000,"yOffset":200000,"zOffset":0}]
log:["Point 0: raw(23084422, 5208093, -26) -> scaled(2230844.22, 252080.93, -0.026000000000000002)"]
log:["Point 1: raw(23081793, 5208206, 226) -> scaled(2230817.93, 252082.06, 0.226)"]
log:["Point 2: raw(23084437, 5208092, 204) -> scaled(2230844.37, 252080.91999999998, 0.20400000000000001)"]
log:["Point 3: raw(23105369, 5207193, 1613) -> scaled(2231053.69, 252071.93, 1.613)"]
log:["Point 4: raw(23104803, 5207218, 1493) -> scaled(2231048.03, 252072.18, 1.493)"]
log:["Point 5: raw(23104880, 5207214, 1673) -> scaled(2231048.8, 252072.14, 1.673)"]
log:["Point 6: raw(23094007, 5207681, 74) -> scaled(2230940.07, 252076.81, 0.074)"]
log:["Point 7: raw(23079978, 5208284, 88) -> scaled(2230799.78, 252082.84, 0.088)"]
log:["Point 8: raw(23074573, 5208528, -37) -> scaled(2230745.73, 252085.28, -0.037)"]
log:["Point 9: raw(23107424, 5207117, 2261) -> scaled(2231074.24, 252071.16999999998, 2.261)"]
...


The example extracts and displays the x,y,z coordinates from the LiDAR (LAS) file. However, the file also contains other information, such as colors, which can be checked for with the
pointDataRecordFormat
information from the header.


Things to Try


• LAZ (.laz) compressed version of the LiDAR form (data is compressed)


Resources and Links


• LAS Specification 1.4 - R15 [LINK]
• plas.io viewer [LINK]





























Ray-Tracing with WebGPU kenwright WebGPU Development Cookbook - coding recipes for all your webgpu needs! WebGPU by Example: Fractals, Image Effects, Ray-Tracing, Procedural Geometry, 2D/3D, Particles, Simulations WebGPU Games WGSL 2d 3d interactive web-based fun learning WebGPU Compute WebGPU API - Owners WebGPU & WGSL Essentials: A Hands-On Approach to Interactive Graphics, Games, 2D Interfaces, 3D Meshes, Animation, Security and Production Kenwright graphics and animations using the webgpu api 12 week course kenwright learn webgpu api kenwright programming compute and graphics applications with html5 and webgpu api kenwright real-time 3d graphics with webgpu kenwright webgpu for dummies kenwright webgpu api develompent a quick start guide kenwright webgpu by example 2022 kenwright webgpu gems kenwright webgpu interactive compute and graphics visualization cookbook kenwright wgsl webgpu shading language cookbook kenwright WebGPU Shader Language Development: Vertex, Fragment, Compute Shaders for Programmers Kenwright wgsl webgpugems shading language cookbook kenwright WGSL Fundamentals book kenwright WebGPU Data Visualization Cookbook kenwright Special Effects Programming with WebGPU kenwright WebGPU Programming Guide: Interactive Graphics and Compute Programming with WebGPU & WGSL kenwright



 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.