rewriting points' classification in .las file

616 views
Skip to first unread message

wenyuan yin

unread,
Mar 1, 2012, 12:14:30 AM3/1/12
to LAStools - efficient tools for LIDAR processing
Hi Martin,

I am a student in GIS major. I am new to laslib and intend to use it
in my programming project. I imported laslib in my project and used
lasreader's method to obtain the information of each point like
classification successfully But I have problem right now:

I'd like to rewrite the classificaiton information of each points in
the original .las file. But I don't know which function or method
shall I use. I tried the laswriter, correct me if I am wrong, but it
seemed laswrite is just for creating a copy of the orignal file. Also,
I noticed there is a lastransform class which seems good for me.
However, I have no idea how to use it.

So, could you please tell me how I am albe to rewirte the
classificaiton in the original file using laslib, or is there any
tutorial that I can refer to?

Many thanks

Best,

Wenyuan Yin

Martin Isenburg

unread,
Mar 1, 2012, 11:50:58 AM3/1/12
to LAStools - efficient tools for LIDAR processing
Hello Wenyuan,

either you use the '-change_classification_from_to 2 4' transform that
is built into all LAStools such as

las2las -i lidar1.las -o lidar2.laz -change_classification_from_to 2 4

or - if you want to program it yourself - you follow the example code
given in this file here

C:\lastools\laslib\example\lasexample.cpp

and that would be something like the code below.

cheers,

martin @lastools

int main(int argc, char *argv[])
{
int i;

LASreadOpener lasreadopener;
LASwriteOpener laswriteopener;

if (argc == 1)
{
fprintf(stderr,"lasexample.exe is better run in the command line
\n");
char file_name[256];
fprintf(stderr,"enter input file: "); fgets(file_name, 256,
stdin);
file_name[strlen(file_name)-1] = '\0';
lasreadopener.set_file_name(file_name);
fprintf(stderr,"enter output file: "); fgets(file_name, 256,
stdin);
file_name[strlen(file_name)-1] = '\0';
laswriteopener.set_file_name(file_name);
}
else
{
lasreadopener.parse(argc, argv);
laswriteopener.parse(argc, argv);
}

// check input & output
if (!lasreadopener.active())
{
fprintf(stderr,"ERROR: no input specified\n");
return 1;
}

if (!laswriteopener.active())
{
fprintf(stderr,"ERROR: no output specified\n");
return 1;
}

// open lasreader
LASreader* lasreader = lasreadopener.open();
if (lasreader == 0)
{
fprintf(stderr, "ERROR: could not open lasreader\n");
return 1;
}

// open laswriter
LASwriter* laswriter = laswriteopener.open(&lasreader->header);
if (laswriter == 0)
{
fprintf(stderr, "ERROR: could not open laswriter\n");
return 1;
}

// when there is a point to read
while (lasreader->read_point())
{
// modify the point
lasreader->point.point_source_ID = 1020;
if (lasreader->point.classification == 12) lasreader-
>point.classification = 1;
// write the modified point
laswriter->write_point(&lasreader->point);
// add it to the inventory
laswriter->update_inventory(&lasreader->point);
}

laswriter->update_header(&lasreader->header, TRUE);

laswriter->close();
delete laswriter;
lasreader->close();
delete lasreader;

wenyuan yin

unread,
Mar 9, 2012, 12:53:25 PM3/9/12
to last...@googlegroups.com
Hi Dear Martin,
 
I studied the code and example you gave me and tried to use it. However, it seemed to me that I still have to create a new file other than just overwirte the original file when specify the output for laswriteropener. I tried to use the same file_name for the lasreaderopener and laswriteropener but my project just didn't work out. Is there any way to alter and overwrite the classification information in the original file? Or is that possible to use new file to replace the old one while I am using the old one?
 
Perhaps there is something I misunderstand, please help me out.
 
Thanks,
 
Best,
 
Wenyuan Yin

On Fri, Mar 2, 2012 at 12:21 AM, wenyuan yin <yinwe...@gmail.com> wrote:
Hi Dear Martin,
 
Thanks a lot for your helpful response. I'll look into example that you gave me. I appreciate your help ;) 
 
Best,
 
Wenyuan
 
 

Martin Isenburg

unread,
Mar 11, 2012, 5:14:50 PM3/11/12
to LAStools - efficient tools for LIDAR processing
Hello Wenyuan,

> However, it
> seemed to me that I still have to create a new file other than just
> overwirte the original file when specify the output for laswriteropener. I
> tried to use the same file_name for the lasreaderopener and laswriteropener
> but my project just didn't work out. Is there any way to alter and
> overwrite the classification information in the original file? Or is that
> possible to use new file to replace the old one while I am using the old
> one?

No, it is not currently possible to do an "in-place" rewrite of the
point properties of a LAS file with the read and write functions of
LASlib. However, it would certainly be possible to add this without
much trouble. Since LASlib is open source you could try to do it
yourself and then contribute the changes back to me (as required by
the LGPL license). Otherwise you'll have to wait until I implement
this some day. It certainly would be a useful feature for folks that
have gigantic LAS holdings who need to fix certain attributes about
their LAS files (e.g. add a point source ID or fix a zero return
count) but want to avoid the I/O overhead of having to read and write
uncompressed LAS.

Cheers,

Martin

PS: Note that this would be impossible to do for a LAZ file, hence a
readwrite open would have to return FALSE if applied to a compressed
LAZ file.
Reply all
Reply to author
Forward
0 new messages