File: bigtest.c

package info (click to toggle)
liblas 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,888 kB
  • ctags: 4,614
  • sloc: cpp: 31,630; xml: 4,195; python: 2,928; ansic: 2,439; cs: 2,411; sh: 143; makefile: 37
file content (58 lines) | stat: -rwxr-xr-x 2,185 bytes parent folder | download | duplicates (3)
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
#include <liblas.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void dumperror (const char * appmsg)
{
   printf("\n%s.\n\tMessage:  %s\n\tMethod: %s",appmsg, LASError_GetLastErrorMsg(), LASError_GetLastErrorMethod());
}
int main()
{

    LASHeaderH header = NULL;
    LASWriterH writer = NULL;
    LASReaderH reader = NULL;
    LASPointH pt = NULL;
    LASError err;
    // Limitation about seeking past 4GB output size.  At 20 bytes / record, we
    // can successfully write 204 million records, but not 205.
    const unsigned long nMillionPoints = 205;
    const unsigned long NPOINTS = 1024*1024*nMillionPoints ;
    const char * OutputName = "Issue147.las";
    unsigned long i = 0;
    unsigned long npoints = 0;

    // Write a LAS file and after the points are in, update the header.
    header = LASHeader_Create();
    writer = LASWriter_Create(OutputName, header, LAS_MODE_WRITE);
    
    for (i = 0; i < NPOINTS; i++)
    {
      if (i % 1000 == 0)
         printf("\b\b\b\b\b\b\b%6.2f%%", ((double)i)/NPOINTS * 100.0);
      
      pt = LASPoint_Create();
      err = LASPoint_SetX(pt, 0);
      if (err) printf ("For point %lu, failed to set point value X\n", i);
      err = LASPoint_SetY(pt, 0);
      if (err) printf ("For point %lu, failed to set point value Y\n", i);
      err = LASPoint_SetZ(pt, 0);
      if (err) printf ("For point %lu, failed to set point value Z\n", i);
      err = LASWriter_WritePoint(writer, pt);  
      if (err) printf ("For point %lu, failed to WritePoint\n", i);
      LASPoint_Destroy(pt);
    }
   err = LASHeader_SetPointRecordsCount(header, NPOINTS);
   if (err) dumperror ("Failed to LASHeader_SetPointRecordsCount\n");
   err = LASWriter_WriteHeader(writer, header);
   if (err) dumperror ("Failed to LASWriter_WriteHeader");
   LASWriter_Destroy(writer);
   LASHeader_Destroy(header);
   
   // Read the file we just wrote and check the header data.
    reader = LASReader_Create(OutputName);
    header = LASReader_GetHeader(reader);
    npoints = LASHeader_GetPointRecordsCount(header);
    printf ("\n\nWrote %lu, Read %lu (testing %lu Million (1024 x 1024) Points)\n", NPOINTS, npoints, nMillionPoints);
}