info.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * lidar-related printing and scanning functions
  3. *
  4. * Authors:
  5. * Markus Metz (r.in.lidar)
  6. * Vaclav Petras (refactoring and various additions)
  7. *
  8. * Copyright 2011-2016 by Markus Metz, and The GRASS Development Team
  9. *
  10. * This program is free software licensed under the GPL (>=v2).
  11. * Read the COPYING file that comes with GRASS for details.
  12. *
  13. */
  14. #include <string.h>
  15. #include <grass/glocale.h>
  16. #include <liblas/capi/liblas.h>
  17. #include "info.h"
  18. void print_lasinfo(LASHeaderH LAS_header, LASSRSH LAS_srs)
  19. {
  20. char *las_srs_proj4 = LASSRS_GetProj4(LAS_srs);
  21. int las_point_format = LASHeader_GetDataFormatId(LAS_header);
  22. fprintf(stdout, "\nUsing LAS Library Version '%s'\n\n",
  23. LAS_GetFullVersion());
  24. fprintf(stdout, "LAS File Version: %d.%d\n",
  25. LASHeader_GetVersionMajor(LAS_header),
  26. LASHeader_GetVersionMinor(LAS_header));
  27. fprintf(stdout, "System ID: '%s'\n",
  28. LASHeader_GetSystemId(LAS_header));
  29. fprintf(stdout, "Generating Software: '%s'\n",
  30. LASHeader_GetSoftwareId(LAS_header));
  31. fprintf(stdout, "File Creation Day/Year: %d/%d\n",
  32. LASHeader_GetCreationDOY(LAS_header),
  33. LASHeader_GetCreationYear(LAS_header));
  34. fprintf(stdout, "Point Data Format: %d\n",
  35. las_point_format);
  36. fprintf(stdout, "Number of Point Records: %d\n",
  37. LASHeader_GetPointRecordsCount(LAS_header));
  38. fprintf(stdout, "Number of Points by Return: %d %d %d %d %d\n",
  39. LASHeader_GetPointRecordsByReturnCount(LAS_header, 0),
  40. LASHeader_GetPointRecordsByReturnCount(LAS_header, 1),
  41. LASHeader_GetPointRecordsByReturnCount(LAS_header, 2),
  42. LASHeader_GetPointRecordsByReturnCount(LAS_header, 3),
  43. LASHeader_GetPointRecordsByReturnCount(LAS_header, 4));
  44. fprintf(stdout, "Scale Factor X Y Z: %g %g %g\n",
  45. LASHeader_GetScaleX(LAS_header),
  46. LASHeader_GetScaleY(LAS_header), LASHeader_GetScaleZ(LAS_header));
  47. fprintf(stdout, "Offset X Y Z: %g %g %g\n",
  48. LASHeader_GetOffsetX(LAS_header),
  49. LASHeader_GetOffsetY(LAS_header),
  50. LASHeader_GetOffsetZ(LAS_header));
  51. fprintf(stdout, "Min X Y Z: %g %g %g\n",
  52. LASHeader_GetMinX(LAS_header),
  53. LASHeader_GetMinY(LAS_header), LASHeader_GetMinZ(LAS_header));
  54. fprintf(stdout, "Max X Y Z: %g %g %g\n",
  55. LASHeader_GetMaxX(LAS_header),
  56. LASHeader_GetMaxY(LAS_header), LASHeader_GetMaxZ(LAS_header));
  57. if (las_srs_proj4 && strlen(las_srs_proj4) > 0) {
  58. fprintf(stdout, "Spatial Reference:\n");
  59. fprintf(stdout, "%s\n", las_srs_proj4);
  60. }
  61. else {
  62. fprintf(stdout, "Spatial Reference: None\n");
  63. }
  64. fprintf(stdout, "\nData Fields:\n");
  65. fprintf(stdout,
  66. " 'X'\n 'Y'\n 'Z'\n 'Intensity'\n 'Return Number'\n");
  67. fprintf(stdout, " 'Number of Returns'\n 'Scan Direction'\n");
  68. fprintf(stdout,
  69. " 'Flighline Edge'\n 'Classification'\n 'Scan Angle Rank'\n");
  70. fprintf(stdout, " 'User Data'\n 'Point Source ID'\n");
  71. if (las_point_format == 1 || las_point_format == 3 ||
  72. las_point_format == 4 || las_point_format == 5) {
  73. fprintf(stdout, " 'GPS Time'\n");
  74. }
  75. if (las_point_format == 2 || las_point_format == 3 ||
  76. las_point_format == 5) {
  77. fprintf(stdout, " 'Red'\n 'Green'\n 'Blue'\n");
  78. }
  79. fprintf(stdout, "\n");
  80. fflush(stdout);
  81. return;
  82. }
  83. int scan_bounds(LASReaderH LAS_reader, int shell_style, int extents, int update,
  84. double zscale, struct Cell_head *region)
  85. {
  86. unsigned long line;
  87. int first;
  88. double min_x, max_x, min_y, max_y, min_z, max_z;
  89. double x, y, z;
  90. LASPointH LAS_point;
  91. line = 0;
  92. first = TRUE;
  93. /* init to nan in case no points are found */
  94. min_x = max_x = min_y = max_y = min_z = max_z = 0.0 / 0.0;
  95. G_verbose_message(_("Scanning data ..."));
  96. LASReader_Seek(LAS_reader, 0);
  97. while ((LAS_point = LASReader_GetNextPoint(LAS_reader)) != NULL) {
  98. line++;
  99. /* we don't do any filtering here */
  100. x = LASPoint_GetX(LAS_point);
  101. y = LASPoint_GetY(LAS_point);
  102. z = LASPoint_GetZ(LAS_point);
  103. if (first) {
  104. min_x = x;
  105. max_x = x;
  106. min_y = y;
  107. max_y = y;
  108. min_z = z;
  109. max_z = z;
  110. first = FALSE;
  111. }
  112. else {
  113. if (x < min_x)
  114. min_x = x;
  115. if (x > max_x)
  116. max_x = x;
  117. if (y < min_y)
  118. min_y = y;
  119. if (y > max_y)
  120. max_y = y;
  121. if (z < min_z)
  122. min_z = z;
  123. if (z > max_z)
  124. max_z = z;
  125. }
  126. }
  127. if (!extents) {
  128. if (!shell_style) {
  129. fprintf(stderr, _("Range: min max\n"));
  130. fprintf(stdout, "x: %11f %11f\n", min_x, max_x);
  131. fprintf(stdout, "y: %11f %11f\n", min_y, max_y);
  132. fprintf(stdout, "z: %11f %11f\n", min_z * zscale, max_z * zscale);
  133. }
  134. else
  135. fprintf(stdout, "n=%f s=%f e=%f w=%f b=%f t=%f\n",
  136. max_y, min_y, max_x, min_x, min_z * zscale,
  137. max_z * zscale);
  138. }
  139. else if (update) {
  140. if (min_x < region->west)
  141. region->west = min_x;
  142. if (max_x > region->east)
  143. region->east = max_x;
  144. if (min_y < region->south)
  145. region->south = min_y;
  146. if (max_y > region->north)
  147. region->north = max_y;
  148. }
  149. else {
  150. region->east = max_x;
  151. region->west = min_x;
  152. region->north = max_y;
  153. region->south = min_y;
  154. }
  155. G_debug(1, "Processed %lu points.", line);
  156. G_debug(1, "region template: g.region n=%f s=%f e=%f w=%f",
  157. max_y, min_y, max_x, min_x);
  158. return 0;
  159. }