The libLAS Project

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 [1], 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 = …

liblas::Reader reader(ifs);

const liblas::Header& header = reader.GetHeader();

uint32 numPoints = header.GetPointRecordsCount();

while (reader.ReadNextPoint())

{

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::Reader reader(ifs);
 liblas::Writer writer(ofs, reader.GetHeader());

 while (reader.ReadNextPoint())
 {
 writer.WritePoint(reader.GetPoint());
 }

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

–output out.las

–drop-intensity ">=1000"

–keep-scan-angle "<=15"

–keep-classes 2

las2las –input epsg26915.las

–output wgs84.las

–scale 0.000001 0.000001 0.01

–a_srs EPSG:26915

–t_srs EPSG:4326

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 [2], 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.

Credits

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 [3], with contributions from Mateusz Loskot [4] and a number of developers (disclaimer: Im one of them). Funding for the project has come from the Iowa Department of Natural Resources [5] and the U.S. Army Cold Regions Research and Engineering Laboratory [6].

Links

[1] http://www.liblas.org/

[2] http://2011.foss4g.org/

[3] http://hobu.biz/

[4] http://mateusz.loskot.net/

[5] http://www.igsb.uiowa.edu/

[6] http://www.crrel.usace.army.mil/

About the Author

Michael P. Gerlek

Michael P. Gerlek... Michael is an independent consultant at Flaxen Geo. Prior to starting Flaxen Geo in 2010, Michael spent over a decade working at LizardTech in various capacities, including Director of Engineering, working on image processing, image compression (MrSID, JPEG 2000), and OGC standards. Michael is very active in the open source geospatial community; he was a founding member of the Open Geospatial Foundation OSGeo and helps to run its Seattle chapter. Prior his geospatial career, he worked in the high performance computing and compiler industry, including jobs at both Tera and Intel and an MS degree at the Oregon Graduate Institute. Michael and his family live on a minor US outlying island in the Puget Sound.
Contact Michael Article List Below