Hello,
I am working on some C++ code to generate custom tiles containing points of interest, the short version of my question would be:
"How can I correctly and preferably with minimal loss of accuracy represent the x, y and z coordinates an original LAS point to new LAS file and header?"
I run into a situation I do not know how to solve; I want existing points from one LAS to be correctly represented for another LAS file.
When I just 'copy' points from one LAS to another with the same header, this is not an issue. (as per the classical LASlib example)
When I create new points, I can use the .init() function for the header I create; however; this erases all prior information in the point.
The principle is as follows:
I have a set of LAS input tiles, and a set of predicates that describe a polygon which are to be populated with points from the LAS input tiles.
However, I notice (screenshot attached) that upon writing my LAS file, the points that came from different source-LAS files, are shifted.
(The screenshot depicts a QGIS screenshot, where my 4 artificially constructed original LAS tiles contain 'source' points, the green polygon named 905 represents the target tile to generate, however, the green, outputted points, are not correctly positioned after writing.)
This is the header with which I try to write my points:
LASheader lasheader;
lasheader.x_scale_factor = 0.00001;
lasheader.y_scale_factor = 0.00001;
lasheader.z_scale_factor = 0.00001;
lasheader.x_offset = predicate->boundingBox.averageX();
lasheader.y_offset = predicate->boundingBox.averageY();
lasheader.z_offset = 0.0;
lasheader.point_data_format = same_data_format;
lasheader.point_data_record_length = same_data_length;
I choose a nice origin (x,y,z_offset), for the best numerical stability of the points.
The //Todo in the code below is likely where my problem and solution are to be found.
while (lasreader->read_point()) //I read the point from one the source las file
{
const auto &point = &lasreader->point;
if (predicate->operator()(static_cast<point3>(*point))) //If the point is inside interest polygon.
{
//Todo: how do I get the point to contain the correct representation for its X/Y in the new header, which lasWriter uses? - the point comes from a file with a different x/y/z_offset.
lasWriter->write_point(point); //Here I write the point.
lasWriter->update_inventory(point);
pointNumber++;
}
}
How can I correctly and preferably with minimal loss of accuracy represent the x, y and z coordinates of the original LAS point to another header?
Ideally however, I would like to see a simple method to accurately 'reproject' a LASpoint to another 'LASheader', perhaps I have overlooked it.
Thank you for any insight/help.
Kind Regards,
Joep Lijnen