If youre developing software for the lidar world, odds are good youre going to need to work with the LAS file format at some point most commonly youll need to read in LAS files, and some of you will need to generate LAS outputs as well. This month Id like to introduce you to the libLAS project , an open source library for reading, writing, and processing data in the LAS format.
Reading and writing LAS
The heart of libLAS is a C++ library that provides classes for reading and writing the various versions and point formats of the LAS standard. Heres a simple example, showing how to open a LAS file and read the points from it.
std::ifstream ifs = …
const liblas::Header& header = reader.GetHeader();
uint32 numPoints = header.GetPointRecordsCount();
const liblas::Point& p = reader.GetPoint();
double x = p.GetX();
double y = p.GetY();
double z = p.GetZ();
Writing LAS point data is just as easy; heres a LAS-to-LAS file copy operation:
liblas::Writer writer(ofs, reader.GetHeader());
The API documentation and more examples can be found on the website.
More libLAS features
Beyond LAS file I/O, libLAS has a number of other features for lidar developers:
additional formats, including ASCII/xyz and TerraSolid (.bin)
Oracle database support, via their Point Cloud feature
filtering, based on the LAS field types
spatial indexing, for fast random access
reprojection, via GDALs support for coordinate transformations
tiling and chipping
compression, via laszip
All these features come with the C++ library, which is typically compiled into a shared library and linked dynamically into your application. The library is portable across the Windows, Mac, and Linux platforms.
Python and C# users can also use libLAS, via the language bindings provided. Heres an example of reading a LAS file from Python:
from liblas import file
f = file.File(‘file.las’, mode=’r’)
for p in f:
print ‘X, Y, Z: ‘, p.x, p.y, p.z
libLAS is released under the permissive BSD open source license, allowing you to use the code within your own applications without imposing any requirements or restrictions on your own source code.
The libLAS tools
libLAS also comes with a set of command line tools that use the underlying libraries to provide LAS processing functionality without extra programming. The las2las tool can be used for point filtering and reprojection:
las2las –input in.las
las2las –input epsg26915.las
–scale 0.000001 0.000001 0.01
Other libLAS tools can be used for merging files, generating spatial indexes, and translating between file formats.
Whats not to like?
libLAS has been very successful and is in production use within a number of commercial applications. It might not be right for you, of course. With respect to the standard, libLAS doesnt support the standards recent addition of full waveform data. If your application cant interoperate with C/C++, Python, or C#, you will need some other package. And if extremely high performance within your own workflows is a requirement, youre probably better off writing custom code anyway.
One notable problem with libLAS is that it was designed around the point structures defined by the LAS standard. As lidar usage has grown over the past year, the libLAS team has recognized the need for an open source library that works with other lidar and point cloud formats, such as the new E57 format or the bathymetric BAG format. Next month, at the annual conference for geospatial open source , the initial public release of the PDAL (Point Data Abstraction Library) project will be announced. While not compatible with the libLAS APIs, PDAL can be viewed as the successor to libLAS: it will offer all the functionality of libLAS, but with the ability to support more file formats, a more extensible API for constructing processing workflows, and higher performance.
Like most open source projects, libLAS is supported by a combination of volunteer efforts and external funding sources, and so its important to publicly acknowledge and thank them when we can. The project is led by Howard Butler , with contributions from Mateusz Loskot  and a number of developers (disclaimer: Im one of them). Funding for the project has come from the Iowa Department of Natural Resources  and the U.S. Army Cold Regions Research and Engineering Laboratory .