las2las drop specified time interval from start of file

57 views
Skip to first unread message

Ben Hocker

unread,
Apr 19, 2024, 3:56:42 AMApr 19
to LAStools - efficient tools for LiDAR processing
Hello,

I am trying to find a way to drop the first few seconds (or any specified time interval) from a set of las files (v1.4 PDRF6 airborne topo lidar). I see that there is a "-start_at_point" option that would do what I wanted by point number; but unfortunately the problem I am trying to remove is time related. Since this is a multiple return system the number of points per second vary considerably depending on the terrain.

I see that I can also specify a "-keep_gps_time_above" but I have almost a hundred files and would rather avoid manually figuring out what the start time of each one is.

Is there a way to either query the start time of each file in a loop and pass it to the "-keep_gps_time_above" function?

Thanks for any guidance!
Ben

Manoj Lnu

unread,
Apr 20, 2024, 8:28:53 AMApr 20
to last...@googlegroups.com
lasinfo gives you time. But still you need to separate the time from the output. Part of the output is shown below. 
...
  edge_of_flight_line 0          0
  scan_direction_flag 0          1
  classification      1          2
  scan_angle_rank   -19         18
  user_data         117        149
  point_source_ID  7326       7334
  gps_time 245370.417065 249783.162158
  Color R 39 249
        G 57 239
        B 56 249
number of first returns:        925
...

--
Download LAStools at
https://rapidlasso.de
Manage your settings at
https://groups.google.com/g/lastools/membership
---
You received this message because you are subscribed to the Google Groups "LAStools - efficient tools for LiDAR processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lastools+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lastools/930023b3-1d1e-4a07-8b41-a22584a4acf8n%40googlegroups.com.

Jochen Rapidlasso

unread,
Apr 20, 2024, 8:39:36 AMApr 20
to LAStools - efficient tools for LiDAR processing
Hi Ben,
here some scripts which will do the job:

The basic (Windows/DOS) script extract the gps seconds from lasinfo and crop the given amount of seconds at the beginning of the file:

@echo off
rem #############################################################
rem # small batch file to crop the first n (arg 2) seconds of 1 or many las files (arg 1)
rem # by rapidlasso (https://rapidlasso.de)
rem #############################################################
if ["%1"]==[""] goto help
if ["%2"]==[""] goto help
goto start
:help
echo Batch to crop the first n seconds of a LAS/LAZ file
echo.
echo crop_first_n_seconds file secs [args]
echo.
echo   file     LAS/LAZ file
echo   secs     seconds to crop from beginning
echo   args     args for las2las
goto eof

:start
set fnin=%1
set tmpfile=tmp.txt
set odix=_out
set olsz=laz
lasinfo64 -i %fnin% -stop_at_point 1000 -stdout > %tmpfile%
for /f "delims=" %%a in ('awk "/gps_time/{print int($2)}" %tmpfile%') do (
    set "gpsmin=%%a"
)
set /a gpsmin+=%2
las2las64 -i %fnin% -odix %odix% -o%olsz% -drop_gpstime_below %gpsmin% %3

set "fnout=%fnin:~0,-4%%odix%.%olsz%"
if not exist "%fnout%" (
    echo no file "%fnout%" written. maybe invalid gps offset.
)
:eof


lets call this script "crop_first_n_seconds.cmd".
Then you can use a loop-script to call this one for every file in your directory (recursive):

:: @echo off
rem #############################################################
rem # small batch file to call a script for every file found
rem # by rapidlasso (https://rapidlasso.de)
rem #############################################################
if ["%1"]==[""] goto help
if ["%2"]==[""] goto help
goto start
:help
echo Batch to call a batch for every file found in given directory
echo.
echo for_all_files dir call args
echo.
echo   dir      directory to scan
echo   call     command or batchfile
echo   args     arguments for call
goto eof

:start
FOR /f %%G IN ('dir /b /s %1') DO (call %2 %%G %3 %4 %5 %6 %7)
:eof

we name this script "for_all_files.cmd"

If we call 
    for_all_files.cmd *.laz crop_first_n_seconds.cmd 5 -v
we create copies of the original files with the suffix "_out.laz"
which contain all data exclude the first 5 seconds.

Notes:
See the las2las ... part in the script to modify your output (directory, suffix, file format).
We only parse the first 1000 points within your file to get the minimum timestamp for performance reasons.
Please adjust this ("-stop_at_point 1000") if your minimum timestamp may exceed this range.

Enjoy the scripts!

Jochen @rapidlasso

Ben Hocker

unread,
Apr 24, 2024, 11:56:46 AMApr 24
to LAStools - efficient tools for LiDAR processing
Thank you very much! That is perfect, and I can repurpose the lasinfo parse script for other needs as well. Very handy.

Thanks for such a great product and support, my favorite tool in the toolbox.

Ben
Reply all
Reply to author
Forward
0 new messages