PDAL / python

PDAL's Python Support
Other
116 stars 34 forks source link

readers.las: Set Global encoding WKT flag upon reading #116

Closed peterwjacko closed 2 years ago

peterwjacko commented 2 years ago

Hi everyone, I hope this is the right place for this question. It sort of straddles the line between "something is wrong" and "what am I doing wrong". I want to avoid opening a GitHub issue for the latter.

I'm trying to generate the boundaries of many las files individually using filters.hexbin. The Global Encoding is set incorrectly as 1 for some of the files when it should be 17. Also, note that all files have a GeoTIFF CRS in the header. Ultimately the data will be delivered to the client as LAS 1.4, GE = 17, SRS = WKT, PDRF = 7 (with colour values).

However, when I attempt to read the las to create the boundary I get the following RuntimeError:

RuntimeError: readers.las: Global encoding WKT flag not set for point format 6 - 10

So I figured I'll just tidy up the header, fix the GE, SRS, etc... but unfortunately, the error occurs in the readers.las Stage. So there's no way for me to read the file, and change the header with writers.las.

Is it possible to use readers.las and override GE bit flags? Or maybe use readers.las and ignore errors? Otherwise, I'm thinking the next best option is to catch the error, use laspy to set the GE for the file, and then read the fixed file. I would prefer to use PDAL so some other parts of my process can go into the single pipeline.

My (simplified) code is as follows:

input_pipeline = pdal.Reader(filename=str(las_file)) | pdal.Filter.hexbin()
input_pipeline.execute() 
metadata = input_pipeline.metadata 
boundary = wkt.loads(metadata['metadata']['filters.hexbin']['boundary'])

Environment

Edition: Windows 10 Business Version: 21H1 OS build: 19043.1469 Python: 3.9 (in conda env) python-pdal: 3.1.2

Cheers!

Peter

abellgithub commented 2 years ago

Here are five lines of python that will correct your file.

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

Here are five lines of python that will correct your file.

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

Cheers! I was overthinking it apparently... it didn't even occur to me to simply open the file.