📄 lasinfo.cpp
字号:
/*
===============================================================================
FILE: lasinfo.cpp
CONTENTS:
This tool reads a LIDAR file in LAS or LAZ format and prints out the info
from the standard header. When the '-variable' flag is used then it also
prints out info from any variable length headers. When the '-check' flag
is used the real bounding box of the points is computed and compared with
the bounding box specified in the header.
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 July 2007 -- added the option to "repair" the header and change items
11 June 2007 -- fixed number of return counts after Vinton found another bug
6 June 2007 -- added lidardouble2string() after Vinton Valentine's bug report
25 March 2007 -- sitting at the Pacific Coffee after doing the escalators
===============================================================================
*/
#include "lasreader.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void usage()
{
fprintf(stderr,"usage:\n");
fprintf(stderr,"lasinfo lidar.las\n");
fprintf(stderr,"lasinfo -variable lidar.las\n");
fprintf(stderr,"lasinfo -variable -nocheck lidar.las\n");
fprintf(stderr,"lasinfo -i lidar.las -nocheck\n");
fprintf(stderr,"lasinfo -i lidar.las -repair\n");
fprintf(stderr,"lasinfo -i lidar.las -repair_bounding_box -file_creation 8 2007\n");
fprintf(stderr,"lasinfo -i lidar.las -system_identifier \"hello world!\" -generating_software \"this is a test (-:\"\n");
exit(1);
}
#ifdef _WIN32
extern "C" FILE* fopenGzipped(const char* filename, const char* mode);
#endif
static inline void VecUpdateMinMax3dv(double min[3], double max[3], const double v[3])
{
if (v[0]<min[0]) min[0]=v[0]; else if (v[0]>max[0]) max[0]=v[0];
if (v[1]<min[1]) min[1]=v[1]; else if (v[1]>max[1]) max[1]=v[1];
if (v[2]<min[2]) min[2]=v[2]; else if (v[2]>max[2]) max[2]=v[2];
}
static inline void VecCopy3dv(double v[3], const double a[3])
{
v[0] = a[0];
v[1] = a[1];
v[2] = a[2];
}
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 parse_variable_header = false;
bool check_points = true;
bool repair_header = false;
bool repair_bounding_box = false;
bool change_header = false;
char* system_identifier = 0;
char* generating_software = 0;
unsigned short file_creation_day = 0;
unsigned short file_creation_year = 0;
char* file_name = 0;
bool ilas = false;
for (i = 1; i < argc; i++)
{
if (strcmp(argv[i],"-h") == 0)
{
usage();
}
else if (strcmp(argv[i],"-i") == 0)
{
i++;
file_name = argv[i];
}
else if (strcmp(argv[i],"-ilas") == 0)
{
ilas = true;
}
else if (strcmp(argv[i],"-var") == 0 || strcmp(argv[i],"-variable") == 0)
{
parse_variable_header = true;
}
else if (strcmp(argv[i],"-points") == 0 || strcmp(argv[i],"-check") == 0 || strcmp(argv[i],"-check_points") == 0)
{
check_points = true;
}
else if (strcmp(argv[i],"-nocheck") == 0)
{
check_points = false;
}
else if (strcmp(argv[i],"-repair") == 0 || strcmp(argv[i],"-repair_header") == 0)
{
repair_header = true;
}
else if (strcmp(argv[i],"-repair_bb") == 0 || strcmp(argv[i],"-repair_boundingbox") == 0 || strcmp(argv[i],"-repair_bounding_box") == 0)
{
repair_bounding_box = true;
}
else if (strcmp(argv[i],"-system_identifier") == 0 || strcmp(argv[i],"-sys_id") == 0)
{
i++;
system_identifier = new char[32];
strncpy(system_identifier, argv[i], 31);
system_identifier[31] = '\0';
change_header = true;
}
else if (strcmp(argv[i],"-generating_software") == 0 || strcmp(argv[i],"-gen_soft") == 0)
{
i++;
generating_software = new char[32];
strncpy(generating_software, argv[i], 31);
generating_software[31] = '\0';
change_header = true;
}
else if (strcmp(argv[i],"-file_creation") == 0)
{
i++;
file_creation_day = (unsigned short)atoi(argv[i]);
i++;
file_creation_year = (unsigned short)atoi(argv[i]);
change_header = true;
}
else if (i == argc - 1 && file_name == 0)
{
file_name = argv[i];
}
else
{
usage();
}
}
FILE* file;
if (file_name)
{
if (strstr(file_name, ".gz"))
{
#ifdef _WIN32
file = fopenGzipped(file_name, "rb");
#else
fprintf(stderr, "ERROR: no support for gzipped input\n");
exit(1);
#endif
}
else
{
file = fopen(file_name, "rb");
}
if (file == 0)
{
fprintf (stderr, "ERROR: could not open file '%s'\n", file_name);
usage();
}
}
else if (ilas)
{
file = stdin;
}
else
{
fprintf (stderr, "ERROR: no input specified\n");
usage();
}
LASreader* lasreader = new LASreader();
if (lasreader->open(file,(parse_variable_header == false)) == false)
{
fprintf (stderr, "ERROR: lasreader open failed for '%s'\n", file_name);
}
LASheader* header = &(lasreader->header);
// print header info
char printstring[256];
fprintf(stderr, "reporting all LAS header entries:\n");
fprintf(stderr, " file signature: '%s'\n", header->file_signature);
fprintf(stderr, " file source ID: %d\n", header->file_source_id);
fprintf(stderr, " reserved: %d\n", header->reserved);
fprintf(stderr, " project ID GUID data 1-4: %d %d %d '%s'\n", header->project_ID_GUID_data_1, header->project_ID_GUID_data_2, header->project_ID_GUID_data_3, header->project_ID_GUID_data_4);
fprintf(stderr, " version major.minor: %d.%d\n", header->version_major, header->version_minor);
fprintf(stderr, " system_identifier: '%s'\n", header->system_identifier);
fprintf(stderr, " generating_software: '%s'\n", header->generating_software);
fprintf(stderr, " file creation day/year: %d/%d\n", header->file_creation_day, header->file_creation_year);
fprintf(stderr, " header size %d\n", header->header_size);
fprintf(stderr, " offset to point data %d\n", header->offset_to_point_data);
fprintf(stderr, " number var. length records %d\n", header->number_of_variable_length_records);
fprintf(stderr, " point data format %d\n", header->point_data_format);
fprintf(stderr, " point data record length %d\n", header->point_data_record_length);
fprintf(stderr, " number of point records %d\n", header->number_of_point_records);
fprintf(stderr, " number of points by return %d %d %d %d %d\n", header->number_of_points_by_return[0], header->number_of_points_by_return[1], header->number_of_points_by_return[2], header->number_of_points_by_return[3], header->number_of_points_by_return[4]);
fprintf(stderr, " scale factor x y z "); lidardouble2string(printstring, header->x_scale_factor, header->y_scale_factor, header->z_scale_factor, true); fprintf(stderr, printstring);
fprintf(stderr, " offset x y z "); lidardouble2string(printstring, header->x_offset, header->y_offset, header->z_offset, true); fprintf(stderr, printstring);
fprintf(stderr, " min x y z "); lidardouble2string(printstring, header->min_x, header->min_y, header->min_z, true); fprintf(stderr, printstring);
fprintf(stderr, " max x y z "); lidardouble2string(printstring, header->max_x, header->max_y, header->max_z, true); fprintf(stderr, printstring);
// maybe print variable header
if (parse_variable_header)
{
LASvariable_header variable_header;
unsigned int offset_to_point_data_counter = header->header_size;
for (int i = 0; i < (int)header->number_of_variable_length_records; i++)
{
if (fread(&variable_header, sizeof(LASvariable_header), 1, file) != 1)
{
fprintf(stderr,"ERROR: reading variable_header %d of %d\n",i,header->number_of_variable_length_records);
return 1;
}
fprintf(stderr, "variable length header record %d of %d:\n", i, (int)header->number_of_variable_length_records);
fprintf(stderr, " reserved %d\n", variable_header.reserved);
fprintf(stderr, " user ID '%s'\n", variable_header.user_id);
fprintf(stderr, " record ID %d\n", variable_header.record_id);
fprintf(stderr, " length after header %d\n", variable_header.record_length_after_header);
fprintf(stderr, " description '%s'\n", variable_header.description);
for (int j = 0; j < variable_header.record_length_after_header; j++)
{
fgetc(file);
}
offset_to_point_data_counter += (sizeof(LASvariable_header)+variable_header.record_length_after_header);
}
// move file pointer to where the points starts
for (; offset_to_point_data_counter < header->offset_to_point_data; offset_to_point_data_counter++)
{
fgetc(file);
}
}
// some additional histograms
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -