Python-PDAL: error reading Format 1.4 LAS File – (readers.las Error) Global encoding WKT flag not set for point format 6 – 10

gdallaspdalwell-known-text

I am using python-pdal 2.4.2 to read a LAS 1.4 in PointFormat 8, with the objective or using different writers stages afterwards.
The pipeline is simple:

import json
import pdal
filepath = "path/to/file.las"
pipeline = {"pipeline" : [{
        "type":"readers.las",
        "filename":filepath,
    }]}
pipeline = json.dumps(pipeline)
pipeline = pdal.Pipeline(pipeline)
count = pipeline.execute()

But I get the following error:

(readers.las Error) Global encoding WKT flag not set for point format 6 - 10.

Is this a format issue? According to the reader.las doc, pdal supports LAS 1.4. I have troubles understanding what this WKT (Well-Known Text) is about.

I read in the las specifications (see "COORDINATE REFERENCE SYSTEM (CRS) REPRESENTATION" section) that:

GeoTIFF is being replaced by Well Known Text (WKT) as the required Coordinate Reference
System (CRS) representation for the new point types (6-10) introduced by LAS 1.4.

So I am guessing the CRS is missing in my LAS file (maybe it is still in GeoTIFF format ?).

I am looking for a way to either:

  • Make the pipeline work with the current las data that I have
  • Modify the las with LASPY (or another python package) in order to have afterwards a pipeline that starts with a PDAL reader.las.
  • Alternatively : read the LAS with laspy and then feed it (or the np.array) to pdal for subsequent operations.

Does anyone have a clue of what is going on? I am still discovering point cloud formats.

Best Answer

I hope this provides a bit more context for the original question and helps anyone who comes here in the future:

For LAS 1.4 using Point Data Record Format 6 - 10, the Global Encoding (GE) flag must be set to "WKT", otherwise it will raise an error. See heading 2.2 Coordinate Reference System (CRS) Representation p. 6 in the ASPRS LAS Specification v1.4.

The flags are represented as bytes, so to set the WKT flag only, the GE value should be set to 16. However, the GPS Time of the Point Records should be formatted in Adjusted Standard GPS Time (ASPRS LAS Spec Table 4. p. 10), which is set using a GE value of 1. So the correct GE value of a LAS 1.4 file with PDRF 6 - 10 is 17 (16 + 1). This GeoCue page does a good job of summing up Global Encoding.

I recently had a similar issue to this question, some of my las files had the GE bit flag incorrectly set to 1 instead of 17 and readers.las threw the same runtime error. I opened an issue#116 on the python-pdal GitHub and turns out I was away overcomplicating it. The header can be edited simply by using open(). Andrew's solution below:

filename = "4_6.las"
f = open(filename, "rb+")
f.seek(6)
f.write(bytes([17, 0, 0, 0]));
f.close()

I hope this helps OP and anyone who might come looking.

Related Question