info.c 6.0 KB

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