c++point-cloud-librarylas

Reading Point Clouds from .las files


I'm working on a project that's using .las lidar files.

I googled and found that PDAL can be used to convert .las to .pcd files, so that I can use the PCL library.

I converted files from .las to .pcd using PDAL.

When I tried to read the pcd files using the following code:

    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ>("C:/Users/hedey/OneDrive/Documents/Research_papers/STDF/10_4231_MFQF-Q141/I-65/LiDAR/RoadSurface/PCD/20180524_I65_NB_RoadSurface_7_53.5.pcd", *cloud) == -1) //* load the file
{
    PCL_ERROR("Couldn't read file test_pcd.pcd \n");
    return (-1);
}
std::cout << "Loaded "
    << cloud->width * cloud->height
    << " data points from test_pcd.pcd with the following fields: "
    << std::endl;
for (const auto& point : *cloud)
    std::cout << "    " << point.x
    << " " << point.y
    << " " << point.z << std::endl;
return (0);

The result was as follows, and I'm surprised that all the coordinates in the converted file are all (0,0,0). What might be wrong with this? enter image description here


Solution

  • I would suggest that you take a close look at the PCD writer documentation for a number of helpful pointers for this particular conversion.

    The issue here is that, while double precision floats are valid PCD, they are not supported by PCL's default point types. You could hand edit the PCD file you've already converted, changing the size of the x, y, and z dimensions from 8 to 4. Or you could just rerun pdal translate being sure to set the datatype and precision while selecting the fields you want converted with the order option. An example would look something like

    pdal translate input.las output.pcd --writers.pcd.order="X=Float:2,Y=Float:2,Z=Float:2"
    

    Furthermore, you probably don't need the extra fields like "ScanAngleRank". If you do, you'll need to provide PCL point type support to be able to handle them separately. To drop the extra fields, you can append

    --writers.pcd.keep_unspecified=false
    

    to the previously suggested command.

    The last thing to keep in mind is that dealing with large coordinates like those in UTM (which it appears your are) and storing them in single precision can cause some loss of precision. You should consider offsetting the data before converting to PCD (possibly with PDAL's transformation filter).