txt2las - convert all txt-files within one directory

673 views
Skip to first unread message

Christian

unread,
May 3, 2011, 4:00:16 PM5/3/11
to LAStools - efficient command line tools for LIDAR processing
Hello Martin,

first of all thank you for those powerful LAStools.

At the moment I am toying around with the txt2las converter. I was
wondering if it is possible to process all txt-files within a single
directory using only one command line. I noticed that, for instance,
the las2dem routine does provide an option (-ilof) that enables you to
process all files that are listed in a corresponding txt-file. But
unfortunately that is not the case for the txt2las converter.

Do you have any ideas on how I could use txt2las in order to process
all txts in a certain dir?

Greetings from Germany,
Christian

Martin Isenburg

unread,
May 4, 2011, 1:40:07 PM5/4/11
to LAStools - efficient command line tools for LIDAR processing
[Christian and I exchanged a few emails off-list to answer his
question.]

> At the moment I am toying around with the txt2las converter. I was
> wondering if it is possible to process all txt-files within a single
> directory using only one command line. I noticed that, for instance,
> the las2dem routine does provide an option (-lof) that enables you to
> process all files that are listed in a corresponding txt-file. But
> unfortunately that is not the case for the txt2las converter.

Do you need to convert all ASCII file into a single LAS file? Because
that is what the '-lof' option does. It merges all listed files (be it
LAS or ASCII) into one.

> Do you have any ideas on how I could use txt2las in order to process
> all txts in a certain dir?

There was a previous posts in the mailing list that pointed out that
all LAStools can now read ASCII. hence you can use

las2las -i files_names.txt -lof -iparse xyzta -skip 2 -o output.las

and all text files listed in "files_names.txt" will be merged into one
"output.las" file with the first two lines of each individual ASCII
file being skipped (simply omit '-skip 2' if skipping is not
necessary).

Christian successfully did that. He wrote that he is currently
converting 2802 ASCII files (> 66 GB) with one command line similar to
the above in one "output.laz" file. I am, however, a bit worried about
the result in case those 66 GB of ASCII contain more points than the
4,294,967,295 points LAS currently allows ... |-:

He also wrote that "the examples in the README files were very
helpful".

He asks whether "txt2las" is redundant given that all tools can read
ASCII and given that las2las can do the conversion as well. Almost,
except reading ASCII from a pipe is only possible with txt2las. For
example when you have some (imagined) classification tool called
classify that outputs ASCII then you can use txt2las to directly pipe
it into a LAS file.

classify -i ASCII.xyztirn -otxt | txt2las -itxt -scale_intensity 65535
-parse xyztirn-o lidar.las

Christian also pointed out a small bug: The list of files option '-i
files_names.txt -lof' does not allow for white spaces or tabs at the
end of
each line in 'files_names.txt' because those will be considered as
part of the file name. I will fix that soon.

cheers,

martin @lastools

Martin Isenburg

unread,
May 5, 2011, 1:41:50 PM5/5/11
to LAStools - efficient command line tools for LIDAR processing
Hi,

I got a message from Tommy who pointed out that "you can write a small
C++ program that traverses every file in a for loop and call
system("txt2las -i currentfile.txt -o currentfile.las -parameters"). I
made it in Linux, but the method should be similar in windows. This
way, the resulting las files will not be merged."

Alternatively you can write a batch script. For Linux it's DIY and for
Windows you will find "batch_txt2las.bat" in the next release in the
"bin/batch_files" folder. Below an example run of "batch_txt2las.bat"
followed by its source code.

Cheers,

Martin @lastools

C:\released_code\lastools\bin>batch_files\batch_txt2las.bat ..\data
\dallas*.gz xyzcirn
usage:
either run "batch_txt2las.bat" and enter arguments when
prompted or provide them as follows in the command line:
"wild_card", "parse_string", and optional "skip_lines".
here are some examples:
C:\bin) batch_txt2las.bat data\*.las xyzt
C:\bin) batch_txt2las.bat data\test00?.las sxyzia 3
C:\bin) batch_txt2las.bat data\path\*.laz tsxyzrn
C:\bin) batch_txt2las.bat data\flight\flight00*.laz xyzi
txt2las -parse xyzcirn -i ..\data\dallas1.xyzcirn.gz
txt2las -parse xyzcirn -i ..\data\dallas2.xyzcirn.gz
txt2las -parse xyzcirn -i ..\data\dallas3.xyzcirn.gz
txt2las -parse xyzcirn -i ..\data\dallas4.xyzcirn.gz
done. press ENTER


C:\released_code\lastools\bin>more batch_files\batch_txt2las.bat
ECHO OFF
ECHO usage:
ECHO either run "batch_txt2las.bat" and enter arguments when
ECHO prompted or provide them as follows in the command line:
ECHO "wild_card", "parse_string", and optional "skip_lines".
ECHO here are some examples:
ECHO C:\bin) batch_txt2las.bat data\*.las xyzt
ECHO C:\bin) batch_txt2las.bat data\test00?.las sxyzia 3
ECHO C:\bin) batch_txt2las.bat data\path\*.laz tsxyzrn
ECHO C:\bin) batch_txt2las.bat data\flight\flight00*.laz xyzi
IF "%1%" == "" GOTO GET_ALL
IF "%2%" == "" GOTO GET_PARSE_STRING
IF "%3%" == "" GOTO ACTION
IF "%4%" == "" GOTO ACTION_WITH_SKIP
:GET_ALL
SET /P F=input file (or wild card):
SET /P V=parse string:
FOR %%D in (%F%) DO START /wait txt2las -parse %V% -i %%D
FOR %%D in (%F%) DO ECHO txt2las -parse %V% -i %%D
GOTO END
:GET_PARSE_STRING
SET /P V=parse string:
FOR %%D in (%1) DO START /wait txt2las -parse %V% -i %%D
FOR %%D in (%1) DO ECHO txt2las -parse %V% -i %%D
GOTO END
:ACTION
ECHO OFF
FOR %%D in (%1) DO START /wait txt2las -parse %2 -i %%D
FOR %%D in (%1) DO ECHO txt2las -parse %2 -i %%D
GOTO END
:ACTION_WITH_SKIP
ECHO OFF
FOR %%D in (%1) DO START /wait txt2las -parse %2 -skip %3 -i %%D
FOR %%D in (%1) DO ECHO txt2las -parse %2 -skip %3 -i %%D
:END
SET /P F=done. press ENTER
Reply all
Reply to author
Forward
Message has been deleted
0 new messages