Re: [LAStools] Reading .las/.laz files

790 views
Skip to first unread message

Berin Smaldon

unread,
Nov 20, 2012, 7:59:03 AM11/20/12
to last...@googlegroups.com, raz.m...@gmail.com
Hi Razvan,

Assuming you want to write a program doing this:

Off the top of my head I can give you some vague pointers, but (for now)
you will have to check with the laslib source code to work out exactly
how to use each function.

* You will need to create a LASReadOpener object and give it your file's
path.
* This will return an appropriate LASReader object.
* You should consult the header which should have been populated (unless
you are using ASCII files) for things like the number of points in the file.
* You should be able to interrogate the LASReader for individual,
unordered points.
* Each of these points should have an x, y, and z value that you should
be able to read.


Assuming you want to utilise an existing program:

Your other option is to run:
las2txt -i my_las_file.las -parse xyz -stdout
That would print out the xyz values of each point, which you could then
also pipe into any other program if you wish.


Hope this helps,
Berin Smaldon

On 20/11/12 12:21, Razvan George Mihalyi wrote:
> Hi all,
>
> I'm new to LAStools / LASlib and I have a very basic question that I
> could not find an answer to, searching this group or otherwise.
>
> Following the tutorial at:
> http://www.cs.unc.edu/~isenburg/lastools/download/laslib_README.txt I
> would like to read in a .las (or a .laz) file and retrieve e.g., the x,
> y, z coordinates of a point and print them to stdout. I couldn't easily
> find the API for doing this.
>
> Could you please provide some hints?
>
> Many thanks in advance,
> Razvan Mihalyi
>
> --
> Download LAStools at
> http://lastools.org/
> Visit the LAStools group at
> http://groups.google.com/group/lastools/
> Be social with LAStools at
> http://www.facebook.com/LAStools
> http://www.twitter.com/LAStools


--
*******************************************************************
Plymouth Marine Laboratory, Prospect Place, Plymouth, UK. PL4 9PN.
PML is a company limited by guarantee and a registered charity.
Registered England & Wales company no:4178503; charity no:1091222
http://www.pml.ac.uk/
This email is confidential and for the intended recipient(s) only.
Terms and legal disclaimers apply: http://rsg.pml.ac.uk/email.html
*******************************************************************

Berin Smaldon

unread,
Nov 20, 2012, 10:36:30 AM11/20/12
to Razvan George Mihalyi, last...@googlegroups.com
Hi again Razvan,

I cannot tell exactly at a glance and can't look into the matter any
further right now. The code you are showing me looks sound enough. But I
have doubts about how you are setting up your lasreader. Here is why:

besm@pmpc1322:~/scratch/lastools-patched/laslib/src# grep "cannot parse " *
lasreader_txt.cpp: fprintf(stderr, "WARNING: cannot parse '%s'
with '%s'. skipping ...\n", line, parse_less);
lasreader_txt.cpp: fprintf(stderr, "WARNING: cannot parse '%s'
with '%s'. skipping ...\n", line, parse_less);
lasreader_txt.cpp: fprintf(stderr, "WARNING: cannot parse '%s' with
'%s'. skipping ...\n", line, this->parse_string);
lasreader_txt.cpp: fprintf(stderr, "WARNING: cannot parse '%s'
with '%s'. skipping ...\n", line, this->parse_string);
lasreader_txt.cpp: fprintf(stderr, "WARNING: cannot parse '%s'
with '%s'. skipping ...\n", line, this->parse_string);
lasreader_txt.cpp: fprintf(stderr, "WARNING: cannot parse '%s' with
'%s'. skipping ...\n", line, parse_string);
besm@pmpc1322:~/scratch/lastools-patched/laslib/src#

This string can only originate from a text las reader.
(lasreader_txt.cpp should contain only the code for reading ascii
files). You should investigate why your lasreader is a LASreaderTXT
rather than a LASreaderLAS.

On 20/11/12 15:07, Razvan George Mihalyi wrote:
> I'm doing the following:
>
> while (lasreader->read_point()) {
> double point[3] = { lasreader->point.get_x(),
> lasreader->point.get_y(), lasreader->point.get_z() };
> std::cout << point[0] << " " << point[1] << " " << point[2] << "\n";
> // do something else with points
> }
>
> This should, in principle work, right? Assuming of course that there is
> xyz data in the .las/.laz file.
>
> However, I've tried multiple .las and .laz files and I get the same warning:
>
> WARNING: cannot parse '��' with 'xyz'. skipping ...
> WARNING: cannot parse '�' with 'xyz'. skipping ...
> WARNING: cannot parse '' with 'xyz'. skipping ...
>
> Am I doing something wrong, any thoughts?
>
> Thanks,
> Razvan Mihalyi

Berin Smaldon

unread,
Nov 21, 2012, 7:33:31 AM11/21/12
to last...@googlegroups.com, Razvan George Mihalyi
Hi Razvan,

Again, just at a glance, I note that an axes on your plots, specifically
the axis that is having problems, has the values 4.9741 on every value.
It looks to me like your data is very squashed up, which is fine,
nothing wrong with that.

So, at a guess, this isn't a laslib problem. Check what precision
las2txt outputs, and what precision your own program outputs. I'm
guessing the output precision of your program is too low.

Regards,
Berin

On 21/11/12 12:04, Razvan George Mihalyi wrote:
> Hi again,
>
> I figured my mistake out -- I was reading a file (with a non-las
> extension) that was a symbolic link to a .las file. Apparently, this
> caused the reader to go to the text reader.
>
> However, I've noticed another problem.
>
> When running txt2las -parse xyz -i mylasfile.las -o mytextfile.txt and
> plotting x, y, z from mytextfile.txt I get the following plot:
> https://dl.dropbox.com/u/4750637/las.png
>
> When using LASreader inside a small cpp program and dumping the x, y, z
> points to a file:
>
> *LASreadOpener lasreadopener;*
> * lasreadopener.set_file_name(data_path.c_str());*
> * LASreader* lasreader = lasreadopener.open();*
> *
> *
> * ofstream fout("output.log");*
> * while (lasreader->read_point()) {*
> * double point[3] = {lasreader->point.get_x(),
> lasreader->point.get_y(), lasreader->point.get_z()};*
> * fout << point[0] << " " << point[1] << " " << point[2] <<
> "\n";*
> * }*
> * fout.close();*
> **
> * lasreader->close();*
> * delete lasreader;*
>
>
> I get the following plot: https://dl.dropbox.com/u/4750637/txt.png
>
> The .las file used
> is: http://www.liblas.org/samples/format_permutations/las10_format0.las
>
>
> Is there anything I'm doing wrong?
>
> Thanks again for the help,
> Razvan

Andreas Schmidt

unread,
Nov 22, 2012, 3:13:17 AM11/22/12
to last...@googlegroups.com
If it is a precision/rounding thing, check this
http://en.cppreference.com/w/cpp/io/manip/setprecision

resulting in something like:
fout << std::setprecision(12) << [rest of ur stuff]

maybe ur output is in scientific notation (something with E within the
numbers) - check this too.
regards
Andreas
--
Dipl.-Ing. Andreas Schmidt
wiss. Mitarbeiter

Hochschule Anhalt (FH)
http://www.hs-anhalt.de

FB 3 (AFG) - Institut f�r Geoinformation und Vermessung

Bauhausstra�e 8, 06846 Dessau
Geb�ude: 07
Zimmer: 208
Tel: 0340/5197-1551

Martin Isenburg

unread,
Nov 24, 2012, 12:08:00 PM11/24/12
to last...@googlegroups.com
Hello,

because this is such a nice example of "resolution" and the impact of
large "offsets" on the precision of a floating point number I want to
follow-up on this question here and include the two very illustrative
images that Razvan had posted. A quick run with lasinfo on the file in
question [1] shows me this:

>> lasinfo las10_format0.las
[...]
scale factor x y z: 0.001 0.001 0.001
offset x y z: 0 4000000 0
min x y z: 356799.680 4974106.980 1298.060
max x y z: 356829.120 4974122.550 1332.570
[...]
reporting minimum and maximum for all LAS point record entries ...
X 356799680 356829120
Y 974106980 974122550
Z 1298060 1332570
[...]

If you compare the numbers on the Y axis in the "broken" picture with
the range 4974106.980 to 4974122.550 that the bounding box extend in Y
direction, you notice that only two Y increments that are represented
in the broken picture must correspond to 4974110 and 49741120 ... this
is because the cout command only printed the 7 highest digits. This
problem did not occur for the other numbers because there was no large
offset that moved these numbers into a range where the ASCII numbers
require many more digits to achieve the same precision because most of
them are wasted on constantly repeating the large offset.. txt2las
solves this by looking at the scalar offset when converting to ASCII
and always uses as many digits as required to represent the number at
the full resolution that is stored in the LAS/LAZ file.

Regards,

Martin @rapidlasso

[1] http://www.liblas.org/samples/format_permutations/las10_format0.las
> FB 3 (AFG) - Institut für Geoinformation und Vermessung
>
> Bauhausstraße 8, 06846 Dessau
> Gebäude: 07
> Zimmer: 208
> Tel: 0340/5197-1551
>
>
las_las2txt.png
las_cout.png
Reply all
Reply to author
Forward
0 new messages