forked from LAStools/LAStools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlasreader_dtm.cpp
1590 lines (1460 loc) · 49 KB
/
lasreader_dtm.cpp
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
===============================================================================
FILE: lasreader_dtm.cpp
CONTENTS:
see corresponding header file
PROGRAMMERS:
[email protected] - http://rapidlasso.com
COPYRIGHT:
(c) 2007-2013, 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:
see corresponding header file
===============================================================================
*/
#include "lasreader_dtm.hpp"
// used to map GeoTIFF codes to GCTP codes
static const unsigned short PCS_NAD83_Alabama_East = 26929;
static const unsigned short PCS_NAD83_Alabama_West = 26930;
static const unsigned short PCS_NAD83_Alaska_zone_1 = 26931; /* Hotine Oblique Mercator Projection not supported*/
static const unsigned short PCS_NAD83_Alaska_zone_2 = 26932;
static const unsigned short PCS_NAD83_Alaska_zone_3 = 26933;
static const unsigned short PCS_NAD83_Alaska_zone_4 = 26934;
static const unsigned short PCS_NAD83_Alaska_zone_5 = 26935;
static const unsigned short PCS_NAD83_Alaska_zone_6 = 26936;
static const unsigned short PCS_NAD83_Alaska_zone_7 = 26937;
static const unsigned short PCS_NAD83_Alaska_zone_8 = 26938;
static const unsigned short PCS_NAD83_Alaska_zone_9 = 26939;
static const unsigned short PCS_NAD83_Alaska_zone_10 = 26940;
static const unsigned short PCS_NAD83_California_1 = 26941;
static const unsigned short PCS_NAD83_California_2 = 26942;
static const unsigned short PCS_NAD83_California_3 = 26943;
static const unsigned short PCS_NAD83_California_4 = 26944;
static const unsigned short PCS_NAD83_California_5 = 26945;
static const unsigned short PCS_NAD83_California_6 = 26946;
static const unsigned short PCS_NAD83_Arizona_East = 26948;
static const unsigned short PCS_NAD83_Arizona_Central = 26949;
static const unsigned short PCS_NAD83_Arizona_West = 26950;
static const unsigned short PCS_NAD83_Arkansas_North = 26951;
static const unsigned short PCS_NAD83_Arkansas_South = 26952;
static const unsigned short PCS_NAD83_Colorado_North = 26953;
static const unsigned short PCS_NAD83_Colorado_Central = 26954;
static const unsigned short PCS_NAD83_Colorado_South = 26955;
static const unsigned short PCS_NAD83_Connecticut = 26956;
static const unsigned short PCS_NAD83_Delaware = 26957;
static const unsigned short PCS_NAD83_Florida_East = 26958;
static const unsigned short PCS_NAD83_Florida_West = 26959;
static const unsigned short PCS_NAD83_Florida_North = 26960;
static const unsigned short PCS_NAD83_Hawaii_zone_1 = 26961;
static const unsigned short PCS_NAD83_Hawaii_zone_2 = 26962;
static const unsigned short PCS_NAD83_Hawaii_zone_3 = 26963;
static const unsigned short PCS_NAD83_Hawaii_zone_4 = 26964;
static const unsigned short PCS_NAD83_Hawaii_zone_5 = 26965;
static const unsigned short PCS_NAD83_Georgia_East = 26966;
static const unsigned short PCS_NAD83_Georgia_West = 26967;
static const unsigned short PCS_NAD83_Idaho_East = 26968;
static const unsigned short PCS_NAD83_Idaho_Central = 26969;
static const unsigned short PCS_NAD83_Idaho_West = 26970;
static const unsigned short PCS_NAD83_Illinois_East = 26971;
static const unsigned short PCS_NAD83_Illinois_West = 26972;
static const unsigned short PCS_NAD83_Indiana_East = 26973;
static const unsigned short PCS_NAD83_Indiana_West = 26974;
static const unsigned short PCS_NAD83_Iowa_North = 26975;
static const unsigned short PCS_NAD83_Iowa_South = 26976;
static const unsigned short PCS_NAD83_Kansas_North = 26977;
static const unsigned short PCS_NAD83_Kansas_South = 26978;
static const unsigned short PCS_NAD83_Kentucky_North = 2205;
static const unsigned short PCS_NAD83_Kentucky_South = 26980;
static const unsigned short PCS_NAD83_Louisiana_North = 26981;
static const unsigned short PCS_NAD83_Louisiana_South = 26982;
static const unsigned short PCS_NAD83_Maine_East = 26983;
static const unsigned short PCS_NAD83_Maine_West = 26984;
static const unsigned short PCS_NAD83_Maryland = 26985;
static const unsigned short PCS_NAD83_Massachusetts = 26986;
static const unsigned short PCS_NAD83_Massachusetts_Is = 26987;
static const unsigned short PCS_NAD83_Michigan_North = 26988;
static const unsigned short PCS_NAD83_Michigan_Central = 26989;
static const unsigned short PCS_NAD83_Michigan_South = 26990;
static const unsigned short PCS_NAD83_Minnesota_North = 26991;
static const unsigned short PCS_NAD83_Minnesota_Central = 26992;
static const unsigned short PCS_NAD83_Minnesota_South = 26993;
static const unsigned short PCS_NAD83_Mississippi_East = 26994;
static const unsigned short PCS_NAD83_Mississippi_West = 26995;
static const unsigned short PCS_NAD83_Missouri_East = 26996;
static const unsigned short PCS_NAD83_Missouri_Central = 26997;
static const unsigned short PCS_NAD83_Missouri_West = 26998;
static const unsigned short PCS_NAD83_Montana = 32100;
static const unsigned short PCS_NAD83_Nebraska = 32104;
static const unsigned short PCS_NAD83_Nevada_East = 32107;
static const unsigned short PCS_NAD83_Nevada_Central = 32108;
static const unsigned short PCS_NAD83_Nevada_West = 32109;
static const unsigned short PCS_NAD83_New_Hampshire = 32110;
static const unsigned short PCS_NAD83_New_Jersey = 32111;
static const unsigned short PCS_NAD83_New_Mexico_East = 32112;
static const unsigned short PCS_NAD83_New_Mexico_Central = 32113;
static const unsigned short PCS_NAD83_New_Mexico_West = 32114;
static const unsigned short PCS_NAD83_New_York_East = 32115;
static const unsigned short PCS_NAD83_New_York_Central = 32116;
static const unsigned short PCS_NAD83_New_York_West = 32117;
static const unsigned short PCS_NAD83_New_York_Long_Is = 32118;
static const unsigned short PCS_NAD83_North_Carolina = 32119;
static const unsigned short PCS_NAD83_North_Dakota_N = 32120;
static const unsigned short PCS_NAD83_North_Dakota_S = 32121;
static const unsigned short PCS_NAD83_Ohio_North = 32122;
static const unsigned short PCS_NAD83_Ohio_South = 32123;
static const unsigned short PCS_NAD83_Oklahoma_North = 32124;
static const unsigned short PCS_NAD83_Oklahoma_South = 32125;
static const unsigned short PCS_NAD83_Oregon_North = 32126;
static const unsigned short PCS_NAD83_Oregon_South = 32127;
static const unsigned short PCS_NAD83_Pennsylvania_N = 32128;
static const unsigned short PCS_NAD83_Pennsylvania_S = 32129;
static const unsigned short PCS_NAD83_Rhode_Island = 32130;
static const unsigned short PCS_NAD83_South_Carolina = 32133;
static const unsigned short PCS_NAD83_South_Dakota_N = 32134;
static const unsigned short PCS_NAD83_South_Dakota_S = 32135;
static const unsigned short PCS_NAD83_Tennessee = 32136;
static const unsigned short PCS_NAD83_Texas_North = 32137;
static const unsigned short PCS_NAD83_Texas_North_Central = 32138;
static const unsigned short PCS_NAD83_Texas_Central = 32139;
static const unsigned short PCS_NAD83_Texas_South_Central = 32140;
static const unsigned short PCS_NAD83_Texas_South = 32141;
static const unsigned short PCS_NAD83_Utah_North = 32142;
static const unsigned short PCS_NAD83_Utah_Central = 32143;
static const unsigned short PCS_NAD83_Utah_South = 32144;
static const unsigned short PCS_NAD83_Vermont = 32145;
static const unsigned short PCS_NAD83_Virginia_North = 32146;
static const unsigned short PCS_NAD83_Virginia_South = 32147;
static const unsigned short PCS_NAD83_Washington_North = 32148;
static const unsigned short PCS_NAD83_Washington_South = 32149;
static const unsigned short PCS_NAD83_West_Virginia_N = 32150;
static const unsigned short PCS_NAD83_West_Virginia_S = 32151;
static const unsigned short PCS_NAD83_Wisconsin_North = 32152;
static const unsigned short PCS_NAD83_Wisconsin_Central = 32153;
static const unsigned short PCS_NAD83_Wisconsin_South = 32154;
static const unsigned short PCS_NAD83_Wyoming_East = 32155;
static const unsigned short PCS_NAD83_Wyoming_East_Central = 32156;
static const unsigned short PCS_NAD83_Wyoming_West_Central = 32157;
static const unsigned short PCS_NAD83_Wyoming_West = 32158;
static const unsigned short PCS_NAD83_Puerto_Rico = 32161;
static const unsigned short GCTP_NAD83_Alabama_East = 101;
static const unsigned short GCTP_NAD83_Alabama_West = 102;
static const unsigned short GCTP_NAD83_Alaska_zone_1 = 5001; /* Hotine Oblique Mercator Projection not supported*/
static const unsigned short GCTP_NAD83_Alaska_zone_2 = 5002;
static const unsigned short GCTP_NAD83_Alaska_zone_3 = 5003;
static const unsigned short GCTP_NAD83_Alaska_zone_4 = 5004;
static const unsigned short GCTP_NAD83_Alaska_zone_5 = 5005;
static const unsigned short GCTP_NAD83_Alaska_zone_6 = 5006;
static const unsigned short GCTP_NAD83_Alaska_zone_7 = 5007;
static const unsigned short GCTP_NAD83_Alaska_zone_8 = 5008;
static const unsigned short GCTP_NAD83_Alaska_zone_9 = 5009;
static const unsigned short GCTP_NAD83_Alaska_zone_10 = 5010;
static const unsigned short GCTP_NAD83_California_1 = 401;
static const unsigned short GCTP_NAD83_California_2 = 402;
static const unsigned short GCTP_NAD83_California_3 = 403;
static const unsigned short GCTP_NAD83_California_4 = 404;
static const unsigned short GCTP_NAD83_California_5 = 405;
static const unsigned short GCTP_NAD83_California_6 = 406;
static const unsigned short GCTP_NAD83_Arizona_East = 201;
static const unsigned short GCTP_NAD83_Arizona_Central = 202;
static const unsigned short GCTP_NAD83_Arizona_West = 203;
static const unsigned short GCTP_NAD83_Arkansas_North = 301;
static const unsigned short GCTP_NAD83_Arkansas_South = 302;
static const unsigned short GCTP_NAD83_Colorado_North = 501;
static const unsigned short GCTP_NAD83_Colorado_Central = 502;
static const unsigned short GCTP_NAD83_Colorado_South = 503;
static const unsigned short GCTP_NAD83_Connecticut = 600;
static const unsigned short GCTP_NAD83_Delaware = 700;
static const unsigned short GCTP_NAD83_Florida_East = 901;
static const unsigned short GCTP_NAD83_Florida_West = 902;
static const unsigned short GCTP_NAD83_Florida_North = 903;
static const unsigned short GCTP_NAD83_Hawaii_zone_1 = 5101;
static const unsigned short GCTP_NAD83_Hawaii_zone_2 = 5102;
static const unsigned short GCTP_NAD83_Hawaii_zone_3 = 5103;
static const unsigned short GCTP_NAD83_Hawaii_zone_4 = 5104;
static const unsigned short GCTP_NAD83_Hawaii_zone_5 = 5105;
static const unsigned short GCTP_NAD83_Georgia_East = 1001;
static const unsigned short GCTP_NAD83_Georgia_West = 1002;
static const unsigned short GCTP_NAD83_Idaho_East = 1101;
static const unsigned short GCTP_NAD83_Idaho_Central = 1102;
static const unsigned short GCTP_NAD83_Idaho_West = 1103;
static const unsigned short GCTP_NAD83_Illinois_East = 1201;
static const unsigned short GCTP_NAD83_Illinois_West = 1202;
static const unsigned short GCTP_NAD83_Indiana_East = 1301;
static const unsigned short GCTP_NAD83_Indiana_West = 1302;
static const unsigned short GCTP_NAD83_Iowa_North = 1401;
static const unsigned short GCTP_NAD83_Iowa_South = 1402;
static const unsigned short GCTP_NAD83_Kansas_North = 1501;
static const unsigned short GCTP_NAD83_Kansas_South = 1502;
static const unsigned short GCTP_NAD83_Kentucky_North = 1601;
static const unsigned short GCTP_NAD83_Kentucky_South = 1602;
static const unsigned short GCTP_NAD83_Louisiana_North = 1701;
static const unsigned short GCTP_NAD83_Louisiana_South = 1702;
static const unsigned short GCTP_NAD83_Maine_East = 1801;
static const unsigned short GCTP_NAD83_Maine_West = 1802;
static const unsigned short GCTP_NAD83_Maryland = 1900;
static const unsigned short GCTP_NAD83_Massachusetts = 2001;
static const unsigned short GCTP_NAD83_Massachusetts_Is = 2002;
static const unsigned short GCTP_NAD83_Michigan_North = 2111;
static const unsigned short GCTP_NAD83_Michigan_Central = 2112;
static const unsigned short GCTP_NAD83_Michigan_South = 2113;
static const unsigned short GCTP_NAD83_Minnesota_North = 2201;
static const unsigned short GCTP_NAD83_Minnesota_Central = 2202;
static const unsigned short GCTP_NAD83_Minnesota_South = 2203;
static const unsigned short GCTP_NAD83_Mississippi_East = 2301;
static const unsigned short GCTP_NAD83_Mississippi_West = 2302;
static const unsigned short GCTP_NAD83_Missouri_East = 2401;
static const unsigned short GCTP_NAD83_Missouri_Central = 2402;
static const unsigned short GCTP_NAD83_Missouri_West = 2403;
static const unsigned short GCTP_NAD83_Montana = 2500;
static const unsigned short GCTP_NAD83_Nebraska = 2600;
static const unsigned short GCTP_NAD83_Nevada_East = 2701;
static const unsigned short GCTP_NAD83_Nevada_Central = 2702;
static const unsigned short GCTP_NAD83_Nevada_West = 2703;
static const unsigned short GCTP_NAD83_New_Hampshire = 2800;
static const unsigned short GCTP_NAD83_New_Jersey = 2900;
static const unsigned short GCTP_NAD83_New_Mexico_East = 3001;
static const unsigned short GCTP_NAD83_New_Mexico_Central = 3002;
static const unsigned short GCTP_NAD83_New_Mexico_West = 3003;
static const unsigned short GCTP_NAD83_New_York_East = 3101;
static const unsigned short GCTP_NAD83_New_York_Central = 3102;
static const unsigned short GCTP_NAD83_New_York_West = 3103;
static const unsigned short GCTP_NAD83_New_York_Long_Is = 3104;
static const unsigned short GCTP_NAD83_North_Carolina = 3200;
static const unsigned short GCTP_NAD83_North_Dakota_N = 3301;
static const unsigned short GCTP_NAD83_North_Dakota_S = 3302;
static const unsigned short GCTP_NAD83_Ohio_North = 3401;
static const unsigned short GCTP_NAD83_Ohio_South = 3402;
static const unsigned short GCTP_NAD83_Oklahoma_North = 3501;
static const unsigned short GCTP_NAD83_Oklahoma_South = 3502;
static const unsigned short GCTP_NAD83_Oregon_North = 3601;
static const unsigned short GCTP_NAD83_Oregon_South = 3602;
static const unsigned short GCTP_NAD83_Pennsylvania_N = 3701;
static const unsigned short GCTP_NAD83_Pennsylvania_S = 3702;
static const unsigned short GCTP_NAD83_Rhode_Island = 3800;
static const unsigned short GCTP_NAD83_South_Carolina = 3900;
static const unsigned short GCTP_NAD83_South_Dakota_N = 4001;
static const unsigned short GCTP_NAD83_South_Dakota_S = 4002;
static const unsigned short GCTP_NAD83_Tennessee = 4100;
static const unsigned short GCTP_NAD83_Texas_North = 4201;
static const unsigned short GCTP_NAD83_Texas_North_Central = 4202;
static const unsigned short GCTP_NAD83_Texas_Central = 4203;
static const unsigned short GCTP_NAD83_Texas_South_Central = 4204;
static const unsigned short GCTP_NAD83_Texas_South = 4205;
static const unsigned short GCTP_NAD83_Utah_North = 4301;
static const unsigned short GCTP_NAD83_Utah_Central = 4302;
static const unsigned short GCTP_NAD83_Utah_South = 4303;
static const unsigned short GCTP_NAD83_Vermont = 4400;
static const unsigned short GCTP_NAD83_Virginia_North = 4501;
static const unsigned short GCTP_NAD83_Virginia_South = 4502;
static const unsigned short GCTP_NAD83_Washington_North = 4601;
static const unsigned short GCTP_NAD83_Washington_South = 4602;
static const unsigned short GCTP_NAD83_West_Virginia_N = 4701;
static const unsigned short GCTP_NAD83_West_Virginia_S = 4702;
static const unsigned short GCTP_NAD83_Wisconsin_North = 4801;
static const unsigned short GCTP_NAD83_Wisconsin_Central = 4802;
static const unsigned short GCTP_NAD83_Wisconsin_South = 4803;
static const unsigned short GCTP_NAD83_Wyoming_East = 4901;
static const unsigned short GCTP_NAD83_Wyoming_East_Central = 4902;
static const unsigned short GCTP_NAD83_Wyoming_West_Central = 4903;
static const unsigned short GCTP_NAD83_Wyoming_West = 4904;
static const unsigned short GCTP_NAD83_Puerto_Rico = 5200;
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#endif
BOOL LASreaderDTM::open(const CHAR* file_name)
{
if (file_name == 0)
{
fprintf(stderr,"ERROR: fine name pointer is zero\n");
return FALSE;
}
// clean header
clean();
// open the DTM file
file = fopen(file_name, "rb");
if (file == 0)
{
fprintf(stderr, "ERROR: cannot open file '%s'\n", file_name);
return FALSE;
}
// read the 200 byte header
CHAR signature[21];
if (fread(signature, 1, 21, file) != 21)
{
fprintf(stderr, "ERROR: reading 21 byte signature for '%s'\n", file_name);
return FALSE;
}
// do the first 21 bytes contain the right signature
if (strncmp(signature, "PLANS-PC BINARY .DTM", 21) != 0)
{
fprintf(stderr, "ERROR: cannot open DTM file '%s', wrong signature '%21s'\n", file_name, signature);
return FALSE;
}
// read the next 61 bytes containing the description
CHAR description[61];
if (fread(description, 1, 61, file) != 61)
{
fprintf(stderr, "ERROR: reading 61 byte description for '%s'\n", file_name);
return FALSE;
}
// read version
F32 version;
if (fread(&version, 4, 1, file) != 1)
{
fprintf(stderr, "ERROR: reading 4 byte version for '%s'\n", file_name);
return FALSE;
}
// check the version
if (version != 3.1f)
{
fprintf(stderr, "WARNING: expected 3.1 but version is %1.1f\n", version);
}
// read lower left x
if (fread(&ll_x, 8, 1, file) != 1)
{
}
// read lower left y
if (fread(&ll_y, 8, 1, file) != 1)
{
}
// read min_z
F64 min_z;
if (fread(&min_z, 8, 1, file) != 1)
{
}
// read max_z
F64 max_z;
if (fread(&max_z, 8, 1, file) != 1)
{
}
// read rotation
F64 rotation;
if (fread(&rotation, 8, 1, file) != 1)
{
}
// check rotation
if (rotation != 0.0)
{
fprintf(stderr, "WARNING: expected 0.0 but rotation is %g\n", rotation);
}
F64 column_spacing;
if (fread(&column_spacing, 8, 1, file) != 1)
{
}
xdim = (F32)column_spacing;
F64 row_spacing;
if (fread(&row_spacing, 8, 1, file) != 1)
{
}
ydim = (F32)row_spacing;
if (fread(&ncols, 4, 1, file) != 1)
{
}
if (fread(&nrows, 4, 1, file) != 1)
{
}
ll_x += 0.5*xdim;
ll_y += 0.5*ydim;
I16 horizontal_units = 0;
I16 vertical_units = 0;
data_type = -1;
I16 coordinate_system = 0;
I16 coordinate_zone = 0;
I16 horizontal_datum = 0;
I16 vertical_datum = 0;
if (fread(&horizontal_units, 2, 1, file) != 1)
{
fprintf(stderr, "ERROR: reading 2 byte horizontal_units for '%s'\n", file_name);
return FALSE;
}
if (fread(&vertical_units, 2, 1, file) != 1)
{
fprintf(stderr, "ERROR: reading 2 byte vertical_units for '%s'\n", file_name);
return FALSE;
}
if (fread(&data_type, 2, 1, file) != 1)
{
fprintf(stderr, "ERROR: reading 2 byte data_type for '%s'\n", file_name);
return FALSE;
}
if (fread(&coordinate_system, 2, 1, file) != 1)
{
fprintf(stderr, "ERROR: reading 2 byte horizontal_units for '%s'\n", file_name);
return FALSE;
}
if (fread(&coordinate_zone, 2, 1, file) != 1)
{
fprintf(stderr, "ERROR: reading 2 byte coordinate_zone for '%s'\n", file_name);
return FALSE;
}
if (fread(&horizontal_datum, 2, 1, file) != 1)
{
fprintf(stderr, "ERROR: reading 2 byte horizontal_datum for '%s'\n", file_name);
return FALSE;
}
if (fread(&vertical_datum, 2, 1, file) != 1)
{
fprintf(stderr, "ERROR: reading 2 byte vertical_datum for '%s'\n", file_name);
return FALSE;
}
int num_geo_keys = 0;
LASvlr_key_entry geo_keys[6];
if ((coordinate_system == 2) && (coordinate_zone >= 1) && (coordinate_zone <= 160)) // UTM
{
unsigned short geokey = 0;
if (horizontal_datum == 1) // GEO_ELLIPSOID_NAD27
{
if ((3 <= coordinate_zone) && (coordinate_zone <= 22))
{
geokey = coordinate_zone + 26700;
}
else
{
fprintf(stderr, "UTM zone %d for NAD27 out-of-range\n", (int)coordinate_zone);
}
}
else if (horizontal_datum == 2) // GEO_ELLIPSOID_NAD83
{
if ((3 <= coordinate_zone) && (coordinate_zone <= 22))
{
geokey = coordinate_zone + 26900;
}
else if ((28 <= coordinate_zone) && (coordinate_zone <= 38))
{
geokey = coordinate_zone + 25800;
}
else
{
fprintf(stderr, "UTM zone %d for NAD83 out-of-range\n", (int)coordinate_zone);
}
}
else if (horizontal_datum == 3) // GEO_ELLIPSOID_WGS84
{
if (coordinate_zone < 100)
{
geokey = coordinate_zone + 32600; // northern_hemisphere
}
else
{
geokey = coordinate_zone - 100 + 32700; // southern_hemisphere
}
}
if (geokey)
{
num_geo_keys = 2;
// projected coordinates
geo_keys[0].key_id = 1024; // GTModelTypeGeoKey
geo_keys[0].tiff_tag_location = 0;
geo_keys[0].count = 1;
geo_keys[0].value_offset = 1; // ModelTypeProjected
// projection
geo_keys[1].key_id = 3072; // ProjectedCSTypeGeoKey
geo_keys[1].tiff_tag_location = 0;
geo_keys[1].count = 1;
geo_keys[1].value_offset = geokey;
}
}
else if (coordinate_system == 3) // state plane
{
unsigned short geokey = 0;
if (horizontal_datum == 2) // GEO_ELLIPSOID_NAD83
{
switch(coordinate_zone)
{
case GCTP_NAD83_Alabama_East:
geokey = PCS_NAD83_Alabama_East;
break;
case GCTP_NAD83_Alabama_West:
geokey = PCS_NAD83_Alabama_West;
break;
case GCTP_NAD83_Alaska_zone_1:
geokey = PCS_NAD83_Alaska_zone_1;
break;
case GCTP_NAD83_Alaska_zone_2:
geokey = PCS_NAD83_Alaska_zone_2;
break;
case GCTP_NAD83_Alaska_zone_3:
geokey = PCS_NAD83_Alaska_zone_3;
break;
case GCTP_NAD83_Alaska_zone_4:
geokey = PCS_NAD83_Alaska_zone_4;
break;
case GCTP_NAD83_Alaska_zone_5:
geokey = PCS_NAD83_Alaska_zone_5;
break;
case GCTP_NAD83_Alaska_zone_6:
geokey = PCS_NAD83_Alaska_zone_6;
break;
case GCTP_NAD83_Alaska_zone_7:
geokey = PCS_NAD83_Alaska_zone_7;
break;
case GCTP_NAD83_Alaska_zone_8:
geokey = PCS_NAD83_Alaska_zone_8;
break;
case GCTP_NAD83_Alaska_zone_9:
geokey = PCS_NAD83_Alaska_zone_9;
break;
case GCTP_NAD83_Alaska_zone_10:
geokey = PCS_NAD83_Alaska_zone_10;
break;
case GCTP_NAD83_California_1:
geokey = PCS_NAD83_California_1;
break;
case GCTP_NAD83_California_2:
geokey = PCS_NAD83_California_2;
break;
case GCTP_NAD83_California_3:
geokey = PCS_NAD83_California_3;
break;
case GCTP_NAD83_California_4:
geokey = PCS_NAD83_California_4;
break;
case GCTP_NAD83_California_5:
geokey = PCS_NAD83_California_5;
break;
case GCTP_NAD83_California_6:
geokey = PCS_NAD83_California_6;
break;
case GCTP_NAD83_Arizona_East:
geokey = PCS_NAD83_Arizona_East;
break;
case GCTP_NAD83_Arizona_Central:
geokey = PCS_NAD83_Arizona_Central;
break;
case GCTP_NAD83_Arizona_West:
geokey = PCS_NAD83_Arizona_West;
break;
case GCTP_NAD83_Arkansas_North:
geokey = PCS_NAD83_Arkansas_North;
break;
case GCTP_NAD83_Arkansas_South:
geokey = PCS_NAD83_Arkansas_South;
break;
case GCTP_NAD83_Colorado_North:
geokey = PCS_NAD83_Colorado_North;
break;
case GCTP_NAD83_Colorado_Central:
geokey = PCS_NAD83_Colorado_Central;
break;
case GCTP_NAD83_Colorado_South:
geokey = PCS_NAD83_Colorado_South;
break;
case GCTP_NAD83_Connecticut:
geokey = PCS_NAD83_Connecticut;
break;
case GCTP_NAD83_Delaware:
geokey = PCS_NAD83_Delaware;
break;
case GCTP_NAD83_Florida_East:
geokey = PCS_NAD83_Florida_East;
break;
case GCTP_NAD83_Florida_West:
geokey = PCS_NAD83_Florida_West;
break;
case GCTP_NAD83_Florida_North:
geokey = PCS_NAD83_Florida_North;
break;
case GCTP_NAD83_Hawaii_zone_1:
geokey = PCS_NAD83_Hawaii_zone_1;
break;
case GCTP_NAD83_Hawaii_zone_2:
geokey = PCS_NAD83_Hawaii_zone_2;
break;
case GCTP_NAD83_Hawaii_zone_3:
geokey = PCS_NAD83_Hawaii_zone_3;
break;
case GCTP_NAD83_Hawaii_zone_4:
geokey = PCS_NAD83_Hawaii_zone_4;
break;
case GCTP_NAD83_Hawaii_zone_5:
geokey = PCS_NAD83_Hawaii_zone_5;
break;
case GCTP_NAD83_Georgia_East:
geokey = PCS_NAD83_Georgia_East;
break;
case GCTP_NAD83_Georgia_West:
geokey = PCS_NAD83_Georgia_West;
break;
case GCTP_NAD83_Idaho_East:
geokey = PCS_NAD83_Idaho_East;
break;
case GCTP_NAD83_Idaho_Central:
geokey = PCS_NAD83_Idaho_Central;
break;
case GCTP_NAD83_Idaho_West:
geokey = PCS_NAD83_Idaho_West;
break;
case GCTP_NAD83_Illinois_East:
geokey = PCS_NAD83_Illinois_East;
break;
case GCTP_NAD83_Illinois_West:
geokey = PCS_NAD83_Illinois_West;
break;
case GCTP_NAD83_Indiana_East:
geokey = PCS_NAD83_Indiana_East;
break;
case GCTP_NAD83_Indiana_West:
geokey = PCS_NAD83_Indiana_West;
break;
case GCTP_NAD83_Iowa_North:
geokey = PCS_NAD83_Iowa_North;
break;
case GCTP_NAD83_Iowa_South:
geokey = PCS_NAD83_Iowa_South;
break;
case GCTP_NAD83_Kansas_North:
geokey = PCS_NAD83_Kansas_North;
break;
case GCTP_NAD83_Kansas_South:
geokey = PCS_NAD83_Kansas_South;
break;
case GCTP_NAD83_Kentucky_North:
geokey = PCS_NAD83_Kentucky_North;
break;
case GCTP_NAD83_Kentucky_South:
geokey = PCS_NAD83_Kentucky_North;
break;
case GCTP_NAD83_Louisiana_North:
geokey = PCS_NAD83_Louisiana_North;
break;
case GCTP_NAD83_Louisiana_South:
geokey = PCS_NAD83_Louisiana_South;
break;
case GCTP_NAD83_Maine_East:
geokey = PCS_NAD83_Maine_East;
break;
case GCTP_NAD83_Maine_West:
geokey = PCS_NAD83_Maine_West;
break;
case GCTP_NAD83_Maryland:
geokey = PCS_NAD83_Maryland;
break;
case GCTP_NAD83_Massachusetts:
geokey = PCS_NAD83_Massachusetts;
break;
case GCTP_NAD83_Massachusetts_Is:
geokey = PCS_NAD83_Massachusetts_Is;
break;
case GCTP_NAD83_Michigan_North:
geokey = PCS_NAD83_Michigan_North;
break;
case GCTP_NAD83_Michigan_Central:
geokey = PCS_NAD83_Michigan_Central;
break;
case GCTP_NAD83_Michigan_South:
geokey = PCS_NAD83_Michigan_South;
break;
case GCTP_NAD83_Minnesota_North:
geokey = PCS_NAD83_Minnesota_North;
break;
case GCTP_NAD83_Minnesota_Central:
geokey = PCS_NAD83_Minnesota_Central;
break;
case GCTP_NAD83_Minnesota_South:
geokey = PCS_NAD83_Minnesota_South;
break;
case GCTP_NAD83_Mississippi_East:
geokey = PCS_NAD83_Mississippi_East;
break;
case GCTP_NAD83_Mississippi_West:
geokey = PCS_NAD83_Mississippi_West;
break;
case GCTP_NAD83_Missouri_East:
geokey = PCS_NAD83_Missouri_East;
break;
case GCTP_NAD83_Missouri_Central:
geokey = PCS_NAD83_Missouri_Central;
break;
case GCTP_NAD83_Missouri_West:
geokey = PCS_NAD83_Missouri_West;
break;
case GCTP_NAD83_Montana:
geokey = PCS_NAD83_Montana;
break;
case GCTP_NAD83_Nebraska:
geokey = PCS_NAD83_Nebraska;
break;
case GCTP_NAD83_Nevada_East:
geokey = PCS_NAD83_Nevada_East;
break;
case GCTP_NAD83_Nevada_Central:
geokey = PCS_NAD83_Nevada_Central;
break;
case GCTP_NAD83_Nevada_West:
geokey = PCS_NAD83_Nevada_West;
break;
case GCTP_NAD83_New_Hampshire:
geokey = PCS_NAD83_New_Hampshire;
break;
case GCTP_NAD83_New_Jersey:
geokey = PCS_NAD83_New_Jersey;
break;
case GCTP_NAD83_New_Mexico_East:
geokey = PCS_NAD83_New_Mexico_East;
break;
case GCTP_NAD83_New_Mexico_Central:
geokey = PCS_NAD83_New_Mexico_Central;
break;
case GCTP_NAD83_New_Mexico_West:
geokey = PCS_NAD83_New_Mexico_West;
break;
case GCTP_NAD83_New_York_East:
geokey = PCS_NAD83_New_York_East;
break;
case GCTP_NAD83_New_York_Central:
geokey = PCS_NAD83_New_York_Central;
break;
case GCTP_NAD83_New_York_West:
geokey = PCS_NAD83_New_York_West;
break;
case GCTP_NAD83_New_York_Long_Is:
geokey = PCS_NAD83_New_York_Long_Is;
break;
case GCTP_NAD83_North_Carolina:
geokey = PCS_NAD83_North_Carolina;
break;
case GCTP_NAD83_North_Dakota_N:
geokey = PCS_NAD83_North_Dakota_N;
break;
case GCTP_NAD83_North_Dakota_S:
geokey = PCS_NAD83_North_Dakota_S;
break;
case GCTP_NAD83_Ohio_North:
geokey = PCS_NAD83_Ohio_North;
break;
case GCTP_NAD83_Ohio_South:
geokey = PCS_NAD83_Ohio_South;
break;
case GCTP_NAD83_Oklahoma_North:
geokey = PCS_NAD83_Oklahoma_North;
break;
case GCTP_NAD83_Oklahoma_South:
geokey = PCS_NAD83_Oklahoma_South;
break;
case GCTP_NAD83_Oregon_North:
geokey = PCS_NAD83_Oregon_North;
break;
case GCTP_NAD83_Oregon_South:
geokey = PCS_NAD83_Oregon_South;
break;
case GCTP_NAD83_Pennsylvania_N:
geokey = PCS_NAD83_Pennsylvania_N;
break;
case GCTP_NAD83_Pennsylvania_S:
geokey = PCS_NAD83_Pennsylvania_S;
break;
case GCTP_NAD83_Rhode_Island:
geokey = PCS_NAD83_Rhode_Island;
break;
case GCTP_NAD83_South_Carolina:
geokey = PCS_NAD83_South_Carolina;
break;
case GCTP_NAD83_South_Dakota_N:
geokey = PCS_NAD83_South_Dakota_N;
break;
case GCTP_NAD83_South_Dakota_S:
geokey = PCS_NAD83_South_Dakota_S;
break;
case GCTP_NAD83_Tennessee:
geokey = PCS_NAD83_Tennessee;
break;
case GCTP_NAD83_Texas_North:
geokey = PCS_NAD83_Texas_North;
break;
case GCTP_NAD83_Texas_North_Central:
geokey = PCS_NAD83_Texas_North_Central;
break;
case GCTP_NAD83_Texas_Central:
geokey = PCS_NAD83_Texas_Central;
break;
case GCTP_NAD83_Texas_South_Central:
geokey = PCS_NAD83_Texas_South_Central;
break;
case GCTP_NAD83_Texas_South:
geokey = PCS_NAD83_Texas_South;
break;
case GCTP_NAD83_Utah_North:
geokey = PCS_NAD83_Utah_North;
break;
case GCTP_NAD83_Utah_Central:
geokey = PCS_NAD83_Utah_Central;
break;
case GCTP_NAD83_Utah_South:
geokey = PCS_NAD83_Utah_South;
break;
case GCTP_NAD83_Vermont:
geokey = PCS_NAD83_Vermont;
break;
case GCTP_NAD83_Virginia_North:
geokey = PCS_NAD83_Virginia_North;
break;
case GCTP_NAD83_Virginia_South:
geokey = PCS_NAD83_Virginia_South;
break;
case GCTP_NAD83_Washington_North:
geokey = PCS_NAD83_Washington_North;
break;
case GCTP_NAD83_Washington_South:
geokey = PCS_NAD83_Washington_South;
break;
case GCTP_NAD83_West_Virginia_N:
geokey = PCS_NAD83_West_Virginia_N;
break;
case GCTP_NAD83_West_Virginia_S:
geokey = PCS_NAD83_West_Virginia_S;
break;
case GCTP_NAD83_Wisconsin_North:
geokey = PCS_NAD83_Wisconsin_North;
break;
case GCTP_NAD83_Wisconsin_Central:
geokey = PCS_NAD83_Wisconsin_Central;
break;
case GCTP_NAD83_Wisconsin_South:
geokey = PCS_NAD83_Wisconsin_South;
break;
case GCTP_NAD83_Wyoming_East:
geokey = PCS_NAD83_Wyoming_East;
break;
case GCTP_NAD83_Wyoming_East_Central:
geokey = PCS_NAD83_Wyoming_East_Central;
break;
case GCTP_NAD83_Wyoming_West_Central:
geokey = PCS_NAD83_Wyoming_West_Central;
break;
case GCTP_NAD83_Wyoming_West:
geokey = PCS_NAD83_Wyoming_West;
break;
case GCTP_NAD83_Puerto_Rico:
geokey = PCS_NAD83_Puerto_Rico;
break;
default:
fprintf(stderr, "state plane NAD83 zone %d not implemented\n", (int)coordinate_zone);
}
}
if (geokey)
{
num_geo_keys = 2;
// projected coordinates
geo_keys[0].key_id = 1024; // GTModelTypeGeoKey
geo_keys[0].tiff_tag_location = 0;
geo_keys[0].count = 1;
geo_keys[0].value_offset = 1; // ModelTypeProjected
// projection
geo_keys[1].key_id = 3072; // ProjectedCSTypeGeoKey
geo_keys[1].tiff_tag_location = 0;
geo_keys[1].count = 1;
geo_keys[1].value_offset = geokey;
}
}
if (horizontal_units < 2)
{
// horizontal units
geo_keys[num_geo_keys].key_id = 3076; // ProjLinearUnitsGeoKey
geo_keys[num_geo_keys].tiff_tag_location = 0;
geo_keys[num_geo_keys].count = 1;
geo_keys[num_geo_keys].value_offset = (horizontal_units == 1 ? 9001 : 9002);
num_geo_keys++;
}
if (vertical_units < 2)
{
// vertical units
geo_keys[num_geo_keys].key_id = 4099; // VerticalUnitsGeoKey
geo_keys[num_geo_keys].tiff_tag_location = 0;
geo_keys[num_geo_keys].count = 1;
geo_keys[num_geo_keys].value_offset = (vertical_units == 1 ? 9001 : 9002);
num_geo_keys++;
}
if (vertical_datum)
{
// vertical datum
geo_keys[num_geo_keys].key_id = 4096; // VerticalCSTypeGeoKey
geo_keys[num_geo_keys].tiff_tag_location = 0;
geo_keys[num_geo_keys].count = 1;
if (vertical_datum == 2)
{
geo_keys[num_geo_keys].value_offset = 5103;// GEO_VERTICAL_NAVD88;
}
else if (vertical_datum == 3)
{
geo_keys[num_geo_keys].value_offset = 5030; // GEO_VERTICAL_WGS84;
}
else if (vertical_datum == 1)
{
geo_keys[num_geo_keys].value_offset = 5102; // GEO_VERTICAL_NAVD29;
}
num_geo_keys++;
}
if (num_geo_keys)
{
header.set_geo_keys(num_geo_keys, geo_keys);
}
// get remaining zero bytes of header
I32 i;
for (i = 164; i < 200; i++)
{
fgetc(file);
}
// check that we have all the needed info
if (xdim <= 0)
{
fprintf(stderr,"WARNING: xdim was %g. setting to 1.0\n", xdim);
xdim = 1;
}
if (ydim <= 0)
{
ydim = 1;
fprintf(stderr,"WARNING: ydim was %g. setting to 1.0\n", ydim);
}
// populate the header as much as it makes sense
sprintf(header.system_identifier, "LAStools (c) by rapidlasso GmbH");
sprintf(header.generating_software, "via LASreaderDTM (%d)", LAS_TOOLS_VERSION);
// maybe set creation date
#ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA attr;
SYSTEMTIME creation;
GetFileAttributesEx(file_name, GetFileExInfoStandard, &attr);