Writing LAS header with PDAL in C++

618 views Asked by At

I am working on an application that writes LAS files from scratch based on lidar data. Previously, the application was built with LibLAS and it worked quite well. However, LibLAS has been discontinued and they recommend to replace it with PDAL, which is a more generalized library for handling point cloud data.

So far, mostly everything has been easy to translate from LibLAS to PDAL except for the LAS headers. Previously, in LibLAS, we would define a liblas::header, in which we would add data such as the LAS version, etc. We would then use that header while writing the file and it would partly define how the file was written. Like this:

liblas::Header header;
header.SetVersionMajor(1);
header.SetVersionMinor(2);
// ... Add more header data, add some points to the las file, etc.
liblas::Writer writer;
writer.SetHeader(header);
writer.WriteHeader();
// Write the rest of the file

Now, with PDAL, I can't seem to find anything to add a header to a file that I'm writing. After numerous google searches I can't seem to find anything to help me with this.

I found this tutorial, but it doesn't mention headers: https://pdal.io/development/writing.html

And I found this tutorial, but it uses the header of a file that is being read, which is not what I want: https://pdal.io/api/transition/index.html

1

There are 1 answers

0
Scott On

I'm a total beginner, but here's what I've learned:

I think "Options" are the key. Look at the tutorial you mentioned, it has Options but all it does it set the file name:

Options options;
options.add("filename", "myfile.las");
writer->setOptions(options);

There is more you can do with the options. For example, in some code I created:

options.add("scale_x",0.001);
options.add("scale_y",0.001);
options.add("scale_z",0.001);
options.add("offset_x","auto");
options.add("offset_y","auto");
options.add("offset_z","auto");
options.add("a_srs","EPSG:32611");

So, I think if you look further into that, you may be able to set all the parameters of the header that you wish.