1

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

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Mohamed Hedeya
  • 153
  • 5
  • 22
  • 1
    If you're working with pointclouds i can not recommend CloudCompare enough. Try using it to load the .las file, you can also use it to export. Maybe it can help you during debugging – MorningDewd Oct 27 '20 at 18:45
  • But, as highlighted in the following links converting from .las to .pcd is not preserving the original coordinates: https://www.danielgm.net/cc/forum/viewtopic.php?t=3805, http://www.danielgm.net/cc/forum/viewtopic.php?t=2001 – Mohamed Hedeya Oct 27 '20 at 20:18
  • I see, interesting. Is it possible to make the .las file available so i can take a look at it? Your pcl code seems fine to me. – MorningDewd Oct 27 '20 at 20:21
  • Thanks for your help and support. The las file is available here: https://www.dropbox.com/s/p0vkfjb8q25ee07/20180524_i65_nb_roadsurface_9_54.5.las?dl=0 – Mohamed Hedeya Oct 27 '20 at 22:46
  • Thanks for the las file. I forgot to ask, can you also upload your converted .pcd file? – MorningDewd Oct 28 '20 at 11:52
  • Please include the command you used to convert the data using PDAL so that we can rule out a potential error there. – chambbj Oct 28 '20 at 12:07
  • This is the command that I used for conversion from the Anaconda prompt (later, I renamed the file after it was converted to pcd). – Mohamed Hedeya Oct 28 '20 at 17:21
  • This is the link to the pcd file: https://www.dropbox.com/s/mxht7f9fpgtroiz/20180524_I65_NB_RoadSurface_9_54.5.zip?dl=0 – Mohamed Hedeya Oct 28 '20 at 17:22

1 Answers1

2

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).

chambbj
  • 168
  • 1
  • 1
  • 5
  • About loss of precision, I'd say that the precision loss is so big in this kind of data that offsetting is a requirement. Otherwise, depending on the location, the points cloud is likely to become unusable. – JRR Oct 30 '20 at 10:45
  • Thanks a lot @chambbj for your detailed answer. The points are now being read after rerunning pdal translate with the order option. I'm new to the field, and I need your help to guide me, or refer me to a practical guide about how to offset the data? – Mohamed Hedeya Nov 07 '20 at 12:18
  • Thanks for your comment @JRR. Could you pls suggest how to do the offsetting, as I'm new to the field? – Mohamed Hedeya Nov 07 '20 at 12:22
  • I found this link about auto offsetting: https://pdal.io/tutorial/las.html#auto-offset-example. However, I can't find pdal command to do the offsetting. Also, I'm not sure if auto offsetting is what you were referering to or not. – Mohamed Hedeya Nov 07 '20 at 12:46
  • There is nothing automatic here (the example you found applies specifically to the LAS writer). You could read up on [pdal info](https://pdal.io/apps/info.html) which will provide the bounds of the original file as part of the output. The transformation filter has a whole section on [translations](https://pdal.io/stages/filters.transformation.html#translation). One possible solution would be to translate by subtracting the minimum XYZ values. PCD won't store these offsets though, so if you ever need to get back to the original coordinates, you'll obviously have to translate again. – chambbj Nov 09 '20 at 15:41