I'm trying to change the header info for a LAS file using the python 2.7 (64-bit) laspy module (version 1.2.5). I'm attempting to follow the example shown here (in the section "Writing Data + EVLRS"): http://laspy.readthedocs.io/en/latest/tut_part_3.html
However, when I update the Extended Variable Length Record (EVLR) info with the new content, I get this error message:
Error text: ValueError: offset must be non-negative and no greater than >buffer length (1094)
This error shows up on line 151 of laspy/base.py:
self._pmap = np.frombuffer(self._mmap, self.pointfmt,
offset = self.manager.header.data_offset,
count = self.manager.header.point_records_count)
The "buffer length" value of 1094 seems to be the same as the length of the EVLR text record, while the "data_offset" value above is a much higher value of 4151.
import numpy as np
import laspy
import shutil
import datetime
print('Update started: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
# Set input / output filenames
evlrContentFile = "./LAS_DATA/evlrContentFile.txt"
inFileName = './LAS_DATA/infile.las'
outFileName = './LAS_DATA/outfile.las'
# Get EVLR string content
with open(evlrContentFile, "r") as evlrFile:
evlrString=evlrFile.read();
# make a copy
shutil.copy(inFileName,outFileName);
# open the outfile for modification
outFile_v14 = laspy.file.File(outFileName, mode = "rw")
# create a new EVLR header entry
new_evlr = laspy.header.EVLR(user_id = 10, record_id = 2,
VLR_body = evlrString)
# update the outfile EVLR header entries
old_evlrs = outFile_v14.header.evlrs
old_evlrs.append(new_evlr)
outFile_v14.header.evlrs = old_evlrs
outFile_v14.close()
print('Update Completed: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
I want to modify the existing files with the new header info with a minimum of processing, so I want to avoid using laspy to copy the contents of the LAS points to the new output file if possible. Hence why I am using the "rw" modify option instead of "w" to create the output file.