📄 las2txt.cpp
字号:
/*
===============================================================================
FILE: las2txt.cpp
CONTENTS:
This tool converts LIDAR data from the binary LAS format to a human
readable ASCII format. The tool can create different formattings for
the textual representation that are controlable via the 'parse' and
'sep' commandline flags. Optionally the header can be placed at the
beginning of the file each line preceeded by some comment symbol.
PROGRAMMERS:
martin isenburg@cs.unc.edu
COPYRIGHT:
copyright (C) 2007 martin isenburg@cs.unc.edu
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
CHANGE HISTORY:
13 June 2007 -- added 'e' and 'd' for the parse string and fixed 'n'
6 June 2007 -- added lidardouble2string() after Vinton Valentine's bug report
4 May 2007 -- completed one month later because my mother passed away
4 April 2007 -- created in the ICE from Frankfurt Airport to Wuerzburg
===============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lasreader.h"
void usage()
{
fprintf(stderr,"usage:\n");
fprintf(stderr,"las2txt lidar.las\n");
fprintf(stderr,"las2txt -parse xyziar lidar.las lidar.txt\n");
fprintf(stderr,"las2txt -i lidar.las -o lidar.laz -parse xyz\n");
fprintf(stderr,"las2txt -parse xyzt -verbose lidar.las\n");
fprintf(stderr,"las2txt -parse xyz lidar.las.gz\n");
fprintf(stderr,"las2txt -h\n");
fprintf(stderr,"---------------------------------------------\n");
fprintf(stderr,"The '-parse txyz' flag specifies how to format each\n");
fprintf(stderr,"each line of the ASCII file. For example, 'txyzia'\n");
fprintf(stderr,"means that the first number of each line should be the\n");
fprintf(stderr,"gpstime, the next three numbers should be the x, y, and\n");
fprintf(stderr,"z coordinate, the next number should be the intensity\n");
fprintf(stderr,"and the next number should be the scan angle.\n");
fprintf(stderr,"The supported entries are a - scan angle, i - intensity,\n");
fprintf(stderr,"n - number of returns for given pulse, r - number of\n");
fprintf(stderr,"this return, c - classification, u - user data,\n");
fprintf(stderr,"p - point source ID, e - edge of flight line flag, and\n");
fprintf(stderr,"d - direction of scan flag.\n");
fprintf(stderr,"---------------------------------------------\n");
fprintf(stderr,"The '-sep space' flag specifies what separator to use. The\n");
fprintf(stderr,"default is a space but 'tab', 'komma', 'colon', 'hyphen',\n");
fprintf(stderr,"'dot', or 'semicolon' are other possibilities.\n");
fprintf(stderr,"---------------------------------------------\n");
fprintf(stderr,"The '-header pound' flag results in the header information\n");
fprintf(stderr,"being printed at the beginning of the ASCII file in form of\n");
fprintf(stderr,"a comment that starts with the special character '#'. Also\n");
fprintf(stderr,"possible are 'percent', 'dollar', 'semicolon', 'komma',\n");
fprintf(stderr,"'star', 'colon', or 'semicolon' as that special character.\n");
exit(1);
}
#ifdef _WIN32
extern "C" FILE* fopenGzipped(const char* filename, const char* mode);
#endif
static int lidardouble2string(char* string, double value)
{
int len;
len = sprintf(string, "%f", value) - 1;
while (string[len] == '0') len--;
if (string[len] != '.') len++;
string[len] = '\0';
return len;
}
static int lidardouble2string(char* string, double value0, double value1, double value2, bool eol)
{
int len;
len = sprintf(string, "%f", value0) - 1;
while (string[len] == '0') len--;
if (string[len] != '.') len++;
len += sprintf(&(string[len]), " %f", value1) - 1;
while (string[len] == '0') len--;
if (string[len] != '.') len++;
len += sprintf(&(string[len]), " %f", value2) - 1;
while (string[len] == '0') len--;
if (string[len] != '.') len++;
if (eol) string[len++] = '\012';
string[len] = '\0';
return len;
}
int main(int argc, char *argv[])
{
int i;
bool ilas = false;
bool otxt = false;
bool verbose = false;
char* file_name_in = 0;
char* file_name_out = 0;
char separator_sign = ' ';
char header_comment_sign = '\0';
char* parse_string = "xyz";
char printstring[256];
for (i = 1; i < argc; i++)
{
if (strcmp(argv[i],"-h") == 0)
{
usage();
}
else if (strcmp(argv[i],"-verbose") == 0)
{
verbose = true;
}
else if (strcmp(argv[i],"-parse") == 0)
{
i++;
parse_string = argv[i];
}
else if (strcmp(argv[i],"-sep") == 0)
{
i++;
if (strcmp(argv[i],"komma") == 0)
{
separator_sign = ',';
}
else if (strcmp(argv[i],"tab") == 0)
{
separator_sign = '\t';
}
else if (strcmp(argv[i],"dot") == 0 || strcmp(argv[i],"period") == 0)
{
separator_sign = '.';
}
else if (strcmp(argv[i],"colon") == 0)
{
separator_sign = ':';
}
else if (strcmp(argv[i],"scolon") == 0 || strcmp(argv[i],"semicolon") == 0)
{
separator_sign = ';';
}
else if (strcmp(argv[i],"hyphen") == 0 || strcmp(argv[i],"minus") == 0)
{
separator_sign = '-';
}
else if (strcmp(argv[i],"space") == 0)
{
separator_sign = ' ';
}
else
{
fprintf(stderr, "ERROR: unknown seperator '%s'\n",argv[i]);
usage();
}
}
else if ((strcmp(argv[i],"-header") == 0 || strcmp(argv[i],"-comment") == 0))
{
i++;
if (strcmp(argv[i],"komma") == 0)
{
header_comment_sign = ',';
}
else if (strcmp(argv[i],"colon") == 0)
{
header_comment_sign = ':';
}
else if (strcmp(argv[i],"scolon") == 0 || strcmp(argv[i],"semicolon") == 0)
{
header_comment_sign = ';';
}
else if (strcmp(argv[i],"pound") == 0 || strcmp(argv[i],"hash") == 0)
{
header_comment_sign = '#';
}
else if (strcmp(argv[i],"percent") == 0)
{
header_comment_sign = '%';
}
else if (strcmp(argv[i],"dollar") == 0)
{
header_comment_sign = '$';
}
else if (strcmp(argv[i],"star") == 0)
{
header_comment_sign = '*';
}
else
{
fprintf(stderr, "ERROR: unknown comment symbol '%s'\n",argv[i]);
usage();
}
}
else if (strcmp(argv[i],"-ilas") == 0)
{
ilas = true;
}
else if (strcmp(argv[i],"-otxt") == 0)
{
otxt = true;
}
else if (strcmp(argv[i],"-i") == 0)
{
i++;
file_name_in = argv[i];
}
else if (strcmp(argv[i],"-o") == 0)
{
i++;
file_name_out = argv[i];
}
else if (i == argc - 2 && file_name_in == 0 && file_name_out == 0)
{
file_name_in = argv[i];
}
else if (i == argc - 1 && file_name_in == 0 && file_name_out == 0)
{
file_name_in = argv[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -