forked from LAStools/LAStools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtxt2las.cpp
More file actions
721 lines (648 loc) · 23.6 KB
/
Copy pathtxt2las.cpp
File metadata and controls
721 lines (648 loc) · 23.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
/*
===============================================================================
FILE: txt2las.cpp
CONTENTS:
This tool parses LIDAR data as it is typically stored in standard ASCII
formats and converts it into the more efficient binary LAS format. If
the LAS/LAZ output goes into a file the tool operates in one pass and
updtes the header in the end. If the LAS/LAZ output is piped the tool
operates in two passes because it has to precompute the information that
is stored in the LAS header. The first pass counts the points, measures
their bounding box, and - if applicable - creates the histogram for the
number of returns. The second pass writes the points.
PROGRAMMERS:
martin.isenburg@rapidlasso.com - http://rapidlasso.com
COPYRIGHT:
(c) 2007-2016, martin isenburg, rapidlasso - fast tools to catch reality
This is free software; you can redistribute and/or modify it under the
terms of the GNU Lesser General Licence as published by the Free Software
Foundation. See the LICENSE.txt file for more information.
This software is distributed WITHOUT ANY WARRANTY and without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
CHANGE HISTORY:
17 January 2016 -- pre-scaling and pre-offsetting of "extra bytes" attributes
1 January 2016 -- option '-set_ogc_wkt' to store CRS as OGC WKT string
4 December 2011 -- added option to set classification with '-set_class 2'
22 April 2011 -- added command-line flags to specify the projection VLRs
20 March 2011 -- added capability to read *.zip, *.rar, and *.7z directly
22 February 2011 -- added option to scale the intensity and scan_angle
19 Juni 2009 -- added option to skip a number of lines in the text file
12 March 2009 -- updated to ask for input if started without arguments
17 September 2008 -- updated to deal with LAS format version 1.2
13 July 2007 -- single pass if output is to file by using fopen("rb+" ...)
25 June 2007 -- added warning in case that quantization causes a sign flip
13 June 2007 -- added 'e' and 'd' for the parse string
26 February 2007 -- created sitting in the SFO lounge waiting for LH 455
===============================================================================
*/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#endif
#include "lasreader.hpp"
#include "laswriter.hpp"
#include "geoprojectionconverter.hpp"
void usage(bool error=false, bool wait=false)
{
fprintf(stderr,"Supported ASCII Inputs:\n");
fprintf(stderr," -i lidar.txt\n");
fprintf(stderr," -i lidar.txt.gz\n");
fprintf(stderr," -i lidar.zip\n");
fprintf(stderr," -i lidar.rar\n");
fprintf(stderr," -i lidar.7z\n");
fprintf(stderr," -stdin (pipe from stdin)\n");
fprintf(stderr,"usage:\n");
fprintf(stderr,"txt2las -parse tsxyz -i lidar.txt.gz\n");
fprintf(stderr,"txt2las -parse xyzairn -i lidar.zip -utm 17T -vertical_navd88 -olaz -set_class 2 -quiet\n");
fprintf(stderr,"unzip -p lidar.zip | txt2las -parse xyz -stdin -o lidar.las -longlat -elevation_survey_feet\n");
fprintf(stderr,"txt2las -i lidar.zip -parse txyzar -scale_scan_angle 57.3 -o lidar.laz\n");
fprintf(stderr,"txt2las -skip 5 -parse xyz -i lidar.rar -set_file_creation 28 2011 -o lidar.las\n");
fprintf(stderr,"txt2las -parse xyzsst -verbose -set_scale 0.001 0.001 0.001 -i lidar.txt\n");
fprintf(stderr,"txt2las -parse xsysz -set_scale 0.1 0.1 0.01 -i lidar.txt.gz -sp83 OH_N -feet\n");
fprintf(stderr,"las2las -parse tsxyzRGB -i lidar.txt -set_version 1.2 -scale_intensity 65535 -o lidar.las\n");
fprintf(stderr,"txt2las -h\n");
fprintf(stderr,"---------------------------------------------\n");
fprintf(stderr,"The '-parse tsxyz' flag specifies how to interpret\n");
fprintf(stderr,"each line of the ASCII file. For example, 'tsxyzssa'\n");
fprintf(stderr,"means that the first number is the gpstime, the next\n");
fprintf(stderr,"number should be skipped, the next three numbers are\n");
fprintf(stderr,"the x, y, and z coordinate, the next two should be\n");
fprintf(stderr,"skipped, and the next number is the scan angle.\n");
fprintf(stderr,"The other supported entries are i - intensity,\n");
fprintf(stderr,"n - number of returns of given pulse, r - number\n");
fprintf(stderr,"of return, c - classification, u - user data, and\n");
fprintf(stderr,"p - point source ID, e - edge of flight line flag, and\n");
fprintf(stderr,"d - direction of scan flag, R - red channel of RGB\n");
fprintf(stderr,"color, G - green channel, B - blue channel\n");
fprintf(stderr,"---------------------------------------------\n");
fprintf(stderr,"Other parameters are\n");
fprintf(stderr,"'-set_scale 0.05 0.05 0.001'\n");
fprintf(stderr,"'-set_offset 500000 2000000 0'\n");
fprintf(stderr,"'-set_file_creation 67 2011'\n");
fprintf(stderr,"'-set_system_identifier \"Riegl 500,000 Hz\"'\n");
fprintf(stderr,"'-set_generating_software \"LAStools\"'\n");
fprintf(stderr,"'-utm 14T'\n");
fprintf(stderr,"'-sp83 CA_I -feet -elevation_survey_feet'\n");
fprintf(stderr,"'-longlat -elevation_feet'\n");
if (wait)
{
fprintf(stderr,"<press ENTER>\n");
getc(stdin);
}
exit(error);
}
static void byebye(bool error=false, bool wait=false)
{
if (wait)
{
fprintf(stderr,"<press ENTER>\n");
getc(stdin);
}
exit(error);
}
static double taketime()
{
return (double)(clock())/CLOCKS_PER_SEC;
}
extern "C" FILE* fopen_compressed(const char* filename, const char* mode, bool* piped=0);
#ifdef COMPILE_WITH_GUI
extern int txt2las_gui(int argc, char *argv[], LASreadOpener* lasreadopener);
#endif
#ifdef COMPILE_WITH_MULTI_CORE
extern int txt2las_multi_core(int argc, char *argv[], GeoProjectionConverter* geoprojectionconverter, LASreadOpener* lasreadopener, LASwriteOpener* laswriteopener, I32 cores);
#endif
int main(int argc, char *argv[])
{
int i;
#ifdef COMPILE_WITH_GUI
bool gui = false;
#endif
#ifdef COMPILE_WITH_MULTI_CORE
I32 cores = 1;
#endif
bool verbose = false;
bool projection_was_set = false;
bool quiet = false;
int file_creation_day = -1;
int file_creation_year = -1;
int set_version_major = -1;
int set_version_minor = -1;
int set_classification = -1;
char* set_system_identifier = 0;
char* set_generating_software = 0;
bool set_ogc_wkt = false;
double start_time = 0.0;
LASreadOpener lasreadopener;
GeoProjectionConverter geoprojectionconverter;
LASwriteOpener laswriteopener;
if (argc == 1)
{
#ifdef COMPILE_WITH_GUI
return txt2las_gui(argc, argv, 0);
#else
char file_name[256];
fprintf(stderr,"%s is better run in the command line\n", argv[0]);
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);
#endif
}
else
{
// need to get those before lastransform->parse() routine gets them
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '–') argv[i][0] = '-';
if (strcmp(argv[i],"-scale_intensity") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: factor\n", argv[i]);
usage(true);
}
lasreadopener.set_scale_intensity((F32)atof(argv[i+1]));
*argv[i]='\0'; *argv[i+1]='\0'; i+=1;
}
else if (strcmp(argv[i],"-translate_intensity") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: offset\n", argv[i]);
usage(true);
}
lasreadopener.set_translate_intensity((F32)atof(argv[i+1]));
*argv[i]='\0'; *argv[i+1]='\0'; i+=1;
}
else if (strcmp(argv[i],"-translate_then_scale_intensity") == 0)
{
if ((i+2) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 2 arguments: offset factor\n", argv[i]);
usage(true);
}
lasreadopener.set_translate_intensity((F32)atof(argv[i+1]));
lasreadopener.set_scale_intensity((F32)atof(argv[i+2]));
*argv[i]='\0'; *argv[i+1]='\0'; *argv[i+2]='\0'; i+=2;
}
else if (strcmp(argv[i],"-scale_scan_angle") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: factor\n", argv[i]);
usage(true);
}
lasreadopener.set_scale_scan_angle((F32)atof(argv[i+1]));
*argv[i]='\0'; *argv[i+1]='\0'; i+=1;
}
}
if (!lasreadopener.parse(argc, argv)) byebye(true);
if (!geoprojectionconverter.parse(argc, argv)) byebye(true);
if (!laswriteopener.parse(argc, argv)) byebye(true);
}
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '\0')
{
continue;
}
else if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"-help") == 0)
{
fprintf(stderr, "LAStools (by martin@rapidlasso.com) version %d\n", LAS_TOOLS_VERSION);
usage();
}
else if (strcmp(argv[i],"-v") == 0 || strcmp(argv[i],"-verbose") == 0)
{
verbose = true;
}
else if (strcmp(argv[i],"-version") == 0)
{
fprintf(stderr, "LAStools (by martin@rapidlasso.com) version %d\n", LAS_TOOLS_VERSION);
byebye();
}
else if (strcmp(argv[i],"-gui") == 0)
{
#ifdef COMPILE_WITH_GUI
gui = true;
#else
fprintf(stderr, "WARNING: not compiled with GUI support. ignoring '-gui' ...\n");
#endif
}
else if (strcmp(argv[i],"-cores") == 0)
{
#ifdef COMPILE_WITH_MULTI_CORE
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: number\n", argv[i]);
usage(true);
}
argv[i][0] = '\0';
i++;
cores = atoi(argv[i]);
argv[i][0] = '\0';
#else
fprintf(stderr, "WARNING: not compiled with multi-core batching. ignoring '-cores' ...\n");
i++;
#endif
}
else if (strcmp(argv[i],"-quiet") == 0)
{
quiet = true;
}
else if (strcmp(argv[i],"-parse") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: parse_string\n", argv[i]);
usage(true);
}
i++;
lasreadopener.set_parse_string(argv[i]);
}
else if (strcmp(argv[i],"-skip") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: number_of_lines\n", argv[i]);
usage(true);
}
i++;
lasreadopener.set_skip_lines(atoi(argv[i]));
}
else if (strcmp(argv[i],"-set_scale") == 0)
{
if ((i+3) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 3 arguments: x y z\n", argv[i]);
usage(true);
}
F64 scale_factor[3];
i++;
sscanf(argv[i], "%lf", &(scale_factor[0]));
i++;
sscanf(argv[i], "%lf", &(scale_factor[1]));
i++;
sscanf(argv[i], "%lf", &(scale_factor[2]));
lasreadopener.set_scale_factor(scale_factor);
}
else if (strcmp(argv[i],"-set_offset") == 0)
{
if ((i+3) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 3 arguments: x y z\n", argv[i]);
usage(true);
}
F64 offset[3];
i++;
sscanf(argv[i], "%lf", &(offset[0]));
i++;
sscanf(argv[i], "%lf", &(offset[1]));
i++;
sscanf(argv[i], "%lf", &(offset[2]));
lasreadopener.set_offset(offset);
}
else if (strcmp(argv[i],"-add_extra") == 0 || strcmp(argv[i],"-add_attribute") == 0)
{
if ((i+3) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs at least 3 arguments: data_type name description\n", argv[i]);
usage(true);
}
if (((i+4) < argc) && (atof(argv[i+4]) != 0.0))
{
if (((i+5) < argc) && ((atof(argv[i+5]) != 0.0) || (strcmp(argv[i+5], "0") == 0) || (strcmp(argv[i+5], "0.0") == 0)))
{
if (((i+6) < argc) && (atof(argv[i+6]) != 0.0))
{
if (((i+7) < argc) && ((atof(argv[i+7]) != 0.0) || (strcmp(argv[i+7], "0") == 0) || (strcmp(argv[i+7], "0.0") == 0)))
{
lasreadopener.add_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3], atof(argv[i+4]), atof(argv[i+5]), atof(argv[i+6]), atof(argv[i+7]));
i+=7;
}
else
{
lasreadopener.add_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3], atof(argv[i+4]), atof(argv[i+5]), atof(argv[i+6]));
i+=6;
}
}
else
{
lasreadopener.add_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3], atof(argv[i+4]), atof(argv[i+5]));
i+=5;
}
}
else
{
lasreadopener.add_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3], atof(argv[i+4]));
i+=4;
}
}
else
{
lasreadopener.add_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3]);
i+=3;
}
}
else if (strcmp(argv[i],"-set_creation_date") == 0 || strcmp(argv[i],"-set_file_creation") == 0)
{
if ((i+2) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 2 arguments: day year\n", argv[i]);
usage(true);
}
i++;
sscanf(argv[i], "%d", &file_creation_day);
i++;
sscanf(argv[i], "%d", &file_creation_year);
}
else if (strcmp(argv[i],"-set_class") == 0 || strcmp(argv[i],"-set_classification") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: value\n", argv[i]);
usage(true);
}
i++;
set_classification = atoi(argv[i]);
}
else if (strcmp(argv[i],"-set_system_identifier") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: name\n", argv[i]);
usage(true);
}
i++;
set_system_identifier = argv[i];
}
else if (strcmp(argv[i],"-set_generating_software") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: name\n", argv[i]);
usage(true);
}
i++;
set_generating_software = argv[i];
}
else if (strcmp(argv[i],"-set_ogc_wkt") == 0)
{
set_ogc_wkt = true;
}
else if (strcmp(argv[i],"-set_version") == 0)
{
if ((i+1) >= argc)
{
fprintf(stderr,"ERROR: '%s' needs 1 argument: major.minor\n", argv[i]);
usage(true);
}
i++;
if (sscanf(argv[i],"%d.%d",&set_version_major,&set_version_minor) != 2)
{
fprintf(stderr, "ERROR: cannot understand argument '%s' of '%s'\n", argv[i], argv[i-1]);
usage(true);
}
}
else if ((argv[i][0] != '-') && (lasreadopener.get_file_name_number() == 0))
{
lasreadopener.add_file_name(argv[i]);
argv[i][0] = '\0';
}
else
{
fprintf(stderr, "ERROR: cannot understand argument '%s'\n", argv[i]);
usage(true);
}
}
#ifdef COMPILE_WITH_GUI
if (gui)
{
return txt2las_gui(argc, argv, &lasreadopener);
}
#endif
#ifdef COMPILE_WITH_MULTI_CORE
if (cores > 1)
{
if (lasreadopener.get_file_name_number() < 2)
{
fprintf(stderr,"WARNING: only %u input files. ignoring '-cores %d' ...\n", lasreadopener.get_file_name_number(), cores);
}
else if (lasreadopener.is_merged())
{
fprintf(stderr,"WARNING: input files merged on-the-fly. ignoring '-cores %d' ...\n", cores);
}
else
{
return txt2las_multi_core(argc, argv, &geoprojectionconverter, &lasreadopener, &laswriteopener, cores);
}
}
#endif
// make sure we have input
if (!lasreadopener.active())
{
fprintf(stderr, "ERROR: no input specified\n");
byebye(true, argc==1);
}
// make sure that input and output are not *both* piped
if (lasreadopener.is_piped() && laswriteopener.is_piped())
{
fprintf(stderr, "ERROR: input and output cannot both be piped\n");
byebye(true, argc==1);
}
// check if projection info was set in the command line
int number_of_keys;
GeoProjectionGeoKeys* geo_keys = 0;
int num_geo_double_params;
double* geo_double_params = 0;
if (geoprojectionconverter.has_projection())
{
projection_was_set = geoprojectionconverter.get_geo_keys_from_projection(number_of_keys, &geo_keys, num_geo_double_params, &geo_double_params);
}
// loop over multiple input files
while (lasreadopener.active())
{
if (verbose) start_time = taketime();
// open lasreader
LASreader* lasreader = lasreadopener.open();
if (lasreader == 0)
{
fprintf(stderr, "ERROR: could not open lasreader\n");
byebye(true, argc==1);
}
// check output
if (!laswriteopener.active())
{
// create name from input name
laswriteopener.make_file_name(lasreadopener.get_file_name(), -2);
}
// if the output was piped we need to precompute the bounding box, etc ...
if (laswriteopener.is_piped())
{
// because the output goes to a pipe we have to precompute the header
// information with an additional pass.
if (verbose) { fprintf(stderr, "piped output. extra read pass over file '%s' ...\n", lasreadopener.get_file_name()); }
while (lasreader->read_point());
lasreader->close();
// output some stats
if (verbose)
{
#ifdef _WIN32
fprintf(stderr, "npoints %I64d min %g %g %g max %g %g %g\n", lasreader->npoints, lasreader->header.min_x, lasreader->header.min_y, lasreader->header.min_z, lasreader->header.max_x, lasreader->header.max_y, lasreader->header.max_z);
#else
fprintf(stderr, "npoints %lld min %g %g %g max %g %g %g\n", lasreader->npoints, lasreader->header.min_x, lasreader->header.min_y, lasreader->header.min_z, lasreader->header.max_x, lasreader->header.max_y, lasreader->header.max_z);
#endif
fprintf(stderr, "return histogram %d %d %d %d %d\n", lasreader->header.number_of_points_by_return[0], lasreader->header.number_of_points_by_return[1], lasreader->header.number_of_points_by_return[2], lasreader->header.number_of_points_by_return[3], lasreader->header.number_of_points_by_return[4]);
fprintf(stderr,"took %g sec.\n", taketime()-start_time); start_time = taketime();
}
// reopen lasreader for the second pass
if (!lasreadopener.reopen(lasreader))
{
fprintf(stderr, "ERROR: could not reopen '%s' for main pass\n", lasreadopener.get_file_name());
byebye(true, argc==1);
}
}
// populate header
for (i = 0; i < 32; i++)
{
lasreader->header.system_identifier[i] = '\0';
lasreader->header.generating_software[i] = '\0';
}
if (set_system_identifier)
{
strncpy(lasreader->header.system_identifier, set_system_identifier, 32);
lasreader->header.system_identifier[31] = '\0';
}
else
{
strncpy(lasreader->header.system_identifier, "LAStools (c) by rapidlasso GmbH", 32);
lasreader->header.system_identifier[31] = '\0';
}
if (set_generating_software)
{
strncpy(lasreader->header.generating_software, set_generating_software, 32);
lasreader->header.generating_software[31] = '\0';
}
else
{
char temp[64];
sprintf(temp, "txt2las (version %d)", LAS_TOOLS_VERSION);
strncpy(lasreader->header.generating_software, temp, 32);
lasreader->header.generating_software[31] = '\0';
}
// maybe set creation date
#ifdef _WIN32
if (lasreadopener.get_file_name() && file_creation_day == -1 && file_creation_year == -1)
{
WIN32_FILE_ATTRIBUTE_DATA attr;
SYSTEMTIME creation;
GetFileAttributesEx(lasreadopener.get_file_name(), GetFileExInfoStandard, &attr);
FileTimeToSystemTime(&attr.ftCreationTime, &creation);
int startday[13] = {-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
file_creation_day = startday[creation.wMonth] + creation.wDay;
file_creation_year = creation.wYear;
// leap year handling
if ((((creation.wYear)%4) == 0) && (creation.wMonth > 2)) file_creation_day++;
}
#endif
if (file_creation_day == -1 && file_creation_year == -1)
{
lasreader->header.file_creation_day = (U16)333;
lasreader->header.file_creation_year = (U16)2011;
}
else
{
lasreader->header.file_creation_day = (U16)file_creation_day;
lasreader->header.file_creation_year = (U16)file_creation_year;
}
// maybe set version
if (set_version_major != -1) lasreader->header.version_major = (U8)set_version_major;
if (set_version_minor != -1) lasreader->header.version_minor = (U8)set_version_minor;
if (set_version_minor == 3)
{
lasreader->header.header_size = 235;
lasreader->header.offset_to_point_data = 235;
}
else if (set_version_minor == 4)
{
lasreader->header.header_size = 375;
lasreader->header.offset_to_point_data = 375;
}
// maybe set projection
if (projection_was_set)
{
lasreader->header.set_geo_keys(number_of_keys, (LASvlr_key_entry*)geo_keys);
if (geo_double_params)
{
lasreader->header.set_geo_double_params(num_geo_double_params, geo_double_params);
}
else
{
lasreader->header.del_geo_double_params();
}
lasreader->header.del_geo_ascii_params();
if (set_ogc_wkt) // maybe also set the OCG WKT
{
I32 len = 0;
CHAR* ogc_wkt = 0;
if (geoprojectionconverter.get_ogc_wkt_from_projection(len, &ogc_wkt, !geoprojectionconverter.has_projection(false)))
{
lasreader->header.set_geo_wkt_ogc_cs(len, ogc_wkt);
free(ogc_wkt);
if ((lasreader->header.version_minor >= 4) && (lasreader->header.point_data_format >= 6))
{
lasreader->header.set_global_encoding_bit(LAS_TOOLS_GLOBAL_ENCODING_BIT_OGC_WKT_CRS);
}
}
else
{
fprintf(stderr, "WARNING: cannot produce OCG WKT. ignoring '-set_ogc_wkt' for '%s'\n", lasreadopener.get_file_name());
}
}
}
// open the output
LASwriter* laswriter = laswriteopener.open(&lasreader->header);
if (laswriter == 0)
{
fprintf(stderr, "ERROR: could not open laswriter\n");
byebye(true, argc==1);
}
if (verbose) fprintf(stderr, "reading file '%s' and writing to '%s'\n", lasreadopener.get_file_name(), laswriteopener.get_file_name());
// loop over points
while (lasreader->read_point())
{
// maybe set classification
if (set_classification != -1)
{
lasreader->point.set_classification(set_classification);
}
// write the point
laswriter->write_point(&lasreader->point);
}
lasreader->close();
if (!laswriteopener.is_piped())
{
laswriter->update_header(&lasreader->header, FALSE, TRUE);
if (verbose)
{
#ifdef _WIN32
fprintf(stderr, "npoints %I64d min %g %g %g max %g %g %g\n", lasreader->npoints, lasreader->header.min_x, lasreader->header.min_y, lasreader->header.min_z, lasreader->header.max_x, lasreader->header.max_y, lasreader->header.max_z);
#else
fprintf(stderr, "npoints %lld min %g %g %g max %g %g %g\n", lasreader->npoints, lasreader->header.min_x, lasreader->header.min_y, lasreader->header.min_z, lasreader->header.max_x, lasreader->header.max_y, lasreader->header.max_z);
#endif
fprintf(stderr, "return histogram %d %d %d %d %d\n", lasreader->header.number_of_points_by_return[0], lasreader->header.number_of_points_by_return[1], lasreader->header.number_of_points_by_return[2], lasreader->header.number_of_points_by_return[3], lasreader->header.number_of_points_by_return[4]);
}
}
laswriter->close();
delete laswriter;
delete lasreader;
laswriteopener.set_file_name(0);
if (verbose) fprintf(stderr,"took %g sec.\n", taketime()-start_time);
}
byebye(false, argc==1);
return 0;
}