3

I am trying to write georeferencing information to a '.las' file using liblas and c++.

Here is my code:

   ofstream ofs;
   ofs.open("test.las", ios::out | ios::binary);
   liblas::Header header;
   liblas::Writer writer(ofs, header);

   liblas::Point point(&header);
   point.SetCoordinates(1.0, 2.0, 3.0);

   writer.WritePoint(point);
   header.SetPointRecordsCount(1);

   liblas::SpatialReference srs;
   srs.SetFromUserInput("EPSG:4326");
   header.SetSRS(srs);
   writer.SetHeader(header);
   writer.WriteHeader();

But, when I check the file using lasinfo tool I get:

 Spatial Reference:           None

If I check proj4, the information is stored, so I don't know why lasinfo doesn't print it:

Code  : std::cout << srs.GetProj4() << std::endl;
Output: +proj=longlat +datum=WGS84 +no_defs 

However, when I use lasinfo tool with others las files not written by me I can see the WKT and geotiff output.

What am I doing wrong?

4

If you want to write a lasfile with SRS information, you must create your liblas::Writer using a liblas::Header that has a defined SRS. Change your code to this:

ofstream ofs;
liblas::Header header;
liblas::SpatialReference srs;
srs.SetFromUserInput("EPSG:4326");
header.SetSRS(srs);
header.SetPointRecordsCount(1);
ofs.open("test.las", ios::out | ios::binary);
liblas::Writer writer(ofs, header);

liblas::Point point(&header);
point.SetCoordinates(1.0, 2.0, 3.0);

writer.WritePoint(point);
writer.WriteHeader();

Explanation

libLAS's header writer implementation does not modify any VLRs when in append mode. libLAS also writes the header immediately upon creating a new writer, which ensures that all subsequent calls to Header::write() are considered to be in append mode. Therefore, you must set up your header with the appropriate spatial reference system (and other VLRs) before creating the writer.

IMO this could be a bug. If you feel the same way, open an issue on libLAS and see what they have to say.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.