~ubuntu-branches/ubuntu/trusty/liblas/trusty-proposed

« back to all changes in this revision

Viewing changes to src/las_c_api.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2014-01-05 17:00:29 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140105170029-ddtp0j63x5jvck2u
Tags: 1.7.0+dfsg-2
Fixed missing linking of system boost component.
(closes: #733282)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************************
2
 
 * $Id$
3
 
 *
4
 
 * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
5
 
 * Purpose:  C API for libLAS
6
 
 * Author:   Howard Butler, hobu.inc@gmail.com, but I'm not proud of it.  
7
 
 *           I also swiped a lot of it from GDAL.
8
 
 *
9
 
 ******************************************************************************
10
 
 * Copyright (c) 2008, Mateusz Loskot
11
 
 * Copyright (c) 2008, Howard Butler
12
 
 *
13
 
 * All rights reserved.
14
 
 * 
15
 
 * Redistribution and use in source and binary forms, with or without 
16
 
 * modification, are permitted provided that the following 
17
 
 * conditions are met:
18
 
 * 
19
 
 *     * Redistributions of source code must retain the above copyright 
20
 
 *       notice, this list of conditions and the following disclaimer.
21
 
 *     * Redistributions in binary form must reproduce the above copyright 
22
 
 *       notice, this list of conditions and the following disclaimer in 
23
 
 *       the documentation and/or other materials provided 
24
 
 *       with the distribution.
25
 
 *     * Neither the name of the Martin Isenburg or Iowa Department 
26
 
 *       of Natural Resources nor the names of its contributors may be 
27
 
 *       used to endorse or promote products derived from this software 
28
 
 *       without specific prior written permission.
29
 
 * 
30
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
31
 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
32
 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
33
 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
34
 
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
35
 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
36
 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
37
 
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
38
 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
39
 
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
40
 
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
41
 
 * OF SUCH DAMAGE.
42
 
 ****************************************************************************/
43
 
 
44
 
#include <liblas/liblas.hpp>
45
 
#include <liblas/lasreader.hpp>
46
 
#include <liblas/laserror.hpp>
47
 
#include <liblas/laswriter.hpp>
48
 
#include <liblas/lasfile.hpp>
49
 
#include <liblas/exception.hpp>
50
 
#include <liblas/lasvariablerecord.hpp>
51
 
#include <liblas/guid.hpp>
52
 
#include <liblas/lasspatialreference.hpp>
53
 
#include <liblas/capi/las_config.h>
54
 
#include <liblas/capi/las_version.h>
55
 
 
56
 
typedef struct LASWriterHS *LASWriterH;
57
 
typedef struct LASReaderHS *LASReaderH;
58
 
typedef struct LASPointHS *LASPointH;
59
 
typedef struct LASHeaderHS *LASHeaderH;
60
 
typedef struct LASGuidHS *LASGuidH;
61
 
typedef struct LASVLRHS *LASVLRH;
62
 
typedef struct LASColorHS *LASColorH;
63
 
typedef struct LASSRSHS *LASSRSH;
64
 
 
65
 
 
66
 
#include <exception>
67
 
#include <fstream>
68
 
#include <iostream>
69
 
#include <map>
70
 
#include <sstream> // std::stringstream
71
 
#include <string>
72
 
#include <stack>
73
 
#include <typeinfo>
74
 
#include <vector>
75
 
#include <cstdio>
76
 
 
77
 
using namespace liblas;
78
 
 
79
 
LAS_C_START
80
 
 
81
 
#ifndef _WIN32
82
 
#include <stdint.h>
83
 
#endif
84
 
 
85
 
#ifdef _WIN32
86
 
#define compare_no_case(a,b,n)  _strnicmp( (a), (b), (n) )
87
 
#else
88
 
#define compare_no_case(a,b,n)  strncasecmp( (a), (b), (n) )
89
 
#endif
90
 
 
91
 
// Error stuff
92
 
 
93
 
 
94
 
typedef enum
95
 
{
96
 
    LE_None = 0,
97
 
    LE_Debug = 1,
98
 
    LE_Warning = 2,
99
 
    LE_Failure = 3,
100
 
    LE_Fatal = 4
101
 
} LASErrorEnum;
102
 
 
103
 
 
104
 
static std::stack<LASError > errors;
105
 
 
106
 
#ifdef _MSC_VER
107
 
# pragma warning(disable: 4127) // warning C4127: conditional expression is constant
108
 
#endif
109
 
 
110
 
#define VALIDATE_LAS_POINTER0(ptr, func) \
111
 
   do { if( NULL == ptr ) { \
112
 
        LASErrorEnum const ret = LE_Failure; \
113
 
        std::ostringstream msg; \
114
 
        msg << "Pointer \'" << #ptr << "\' is NULL in \'" << (func) <<"\'."; \
115
 
        std::string message(msg.str()); \
116
 
        LASError_PushError( ret, message.c_str(), (func)); \
117
 
        return; \
118
 
   }} while(0)
119
 
 
120
 
#define VALIDATE_LAS_POINTER1(ptr, func, rc) \
121
 
   do { if( NULL == ptr ) { \
122
 
        LASErrorEnum const ret = LE_Failure; \
123
 
        std::ostringstream msg; \
124
 
        msg << "Pointer \'" << #ptr << "\' is NULL in \'" << (func) <<"\'."; \
125
 
        std::string message(msg.str()); \
126
 
        LASError_PushError( ret, message.c_str(), (func)); \
127
 
        return (rc); \
128
 
   }} while(0)
129
 
 
130
 
LAS_DLL int LAS_IsGDALEnabled(void) {
131
 
    return IsGDALEnabled();
132
 
}
133
 
 
134
 
LAS_DLL int LAS_IsLibGeoTIFFEnabled(void) {
135
 
    return IsLibGeoTIFFEnabled();
136
 
}
137
 
 
138
 
LAS_DLL void LASError_Reset(void) {
139
 
    if (errors.empty()) return;
140
 
    for (std::size_t i=0;i<errors.size();i++) errors.pop();
141
 
}
142
 
 
143
 
LAS_DLL void LASError_Pop(void) {
144
 
    if (errors.empty()) return;
145
 
    errors.pop();
146
 
}
147
 
 
148
 
LAS_DLL int LASError_GetLastErrorNum(void){
149
 
    if (errors.empty())
150
 
        return 0;
151
 
    else {
152
 
        LASError err = errors.top();
153
 
        return err.GetCode();
154
 
    }
155
 
}
156
 
 
157
 
LAS_DLL char* LASError_GetLastErrorMsg(void){
158
 
    if (errors.empty()) 
159
 
        return NULL;
160
 
    else {
161
 
        LASError err = errors.top();
162
 
        return strdup(err.GetMessage().c_str());
163
 
    }
164
 
}
165
 
 
166
 
LAS_DLL char* LASError_GetLastErrorMethod(void){
167
 
    if (errors.empty()) 
168
 
        return NULL;
169
 
    else {
170
 
        LASError err = errors.top();
171
 
        return strdup(err.GetMethod().c_str());
172
 
    }
173
 
}
174
 
 
175
 
LAS_DLL void LASError_PushError(int code, const char *message, const char *method) {
176
 
    LASError err = LASError(code, std::string(message), std::string(method));
177
 
    errors.push(err);
178
 
}
179
 
 
180
 
LAS_DLL int LASError_GetErrorCount(void) {
181
 
    return static_cast<int>(errors.size());
182
 
}
183
 
 
184
 
LAS_DLL LASReaderH LASReader_Create(const char* filename) 
185
 
 
186
 
{
187
 
    VALIDATE_LAS_POINTER1(filename, "LASReader_Create", NULL);
188
 
 
189
 
    try {
190
 
        std::ios::openmode const mode = std::ios::in | std::ios::binary;
191
 
        std::istream* istrm;
192
 
        if (compare_no_case(filename,"STDIN",5) == 0)
193
 
        {
194
 
            istrm = &std::cin;
195
 
        }
196
 
        else 
197
 
        {
198
 
            istrm = new std::ifstream(filename, mode);
199
 
        }
200
 
        
201
 
        if (!istrm->good())
202
 
        {
203
 
            delete istrm;
204
 
            throw std::runtime_error("Reading stream was not able to be created");
205
 
        }
206
 
        return (LASReaderH) new LASReader(*istrm);
207
 
 
208
 
    
209
 
    } catch (std::exception const& e)
210
 
     {
211
 
         LASError_PushError(LE_Failure, e.what(), "LASReader_Create");
212
 
         return NULL;
213
 
     }
214
 
 
215
 
    
216
 
}
217
 
 
218
 
LAS_DLL void LASReader_Destroy(LASReaderH hReader)
219
 
{
220
 
    VALIDATE_LAS_POINTER0(hReader, "LASReader_Destroy");
221
 
 
222
 
    try { 
223
 
        LASReader* reader = (LASReader*)hReader;
224
 
        std::istream* istrm = &(reader->GetStream());
225
 
 
226
 
        delete reader;
227
 
        hReader = NULL;
228
 
    
229
 
        if (static_cast<std::ifstream&>(*istrm))
230
 
            static_cast<std::ifstream&>(*istrm).close();
231
 
        delete istrm;
232
 
        istrm = NULL;
233
 
  
234
 
        }  catch (std::runtime_error const& e/* e */) 
235
 
        {
236
 
            LASError_PushError(LE_Failure, e.what(), "LASReader_Destroy");
237
 
            return;
238
 
        }
239
 
 
240
 
 
241
 
    hReader = NULL;
242
 
}
243
 
 
244
 
 
245
 
 
246
 
LAS_DLL const LASPointH LASReader_GetNextPoint(const LASReaderH hReader)
247
 
{
248
 
    VALIDATE_LAS_POINTER1(hReader, "LASReader_GetNextPoint", NULL);
249
 
 
250
 
    try {
251
 
        LASReader *reader = ((LASReader*) hReader);
252
 
        if (reader->ReadNextPoint()) 
253
 
            // return (LASPointH) new LASPoint(reader->GetPoint());
254
 
            return (LASPointH) &(reader->GetPoint());
255
 
        else 
256
 
            return NULL;
257
 
    } catch (invalid_point_data const& e /*e */) {
258
 
        LASError_PushError(LE_Failure, e.what(), "LASReader_GetNextPoint Invalid Point");
259
 
    } catch (std::exception const& e)
260
 
    {
261
 
        LASError_PushError(LE_Failure, e.what(), "LASReader_GetNextPoint");
262
 
    }
263
 
 
264
 
    return NULL;
265
 
}
266
 
 
267
 
LAS_DLL const LASPointH LASReader_GetPointAt(const LASReaderH hReader, liblas::uint32_t position)
268
 
{
269
 
    VALIDATE_LAS_POINTER1(hReader, "LASReader_GetPointAt", NULL);
270
 
 
271
 
    try {
272
 
        LASReader *reader = ((LASReader*) hReader);
273
 
        if (reader->ReadPointAt((std::size_t) position)) 
274
 
            // return (LASPointH) new LASPoint(reader->GetPoint());
275
 
            return (LASPointH) &(reader->GetPoint());
276
 
        else 
277
 
            return NULL;
278
 
    } catch (invalid_point_data const& e /*e */) {
279
 
        LASError_PushError(LE_Failure, e.what(), "LASReader_GetPointAt Invalid Point");
280
 
    } catch (std::exception const& e)
281
 
    {
282
 
        LASError_PushError(LE_Failure, e.what(), "LASReader_GetPointAt");
283
 
    }
284
 
 
285
 
    return NULL;
286
 
 
287
 
}
288
 
LAS_DLL LASHeaderH LASReader_GetHeader(const LASReaderH hReader)
289
 
{
290
 
    VALIDATE_LAS_POINTER1(hReader, "LASReader_GetHeader", NULL);
291
 
 
292
 
    LASHeader header = ((LASReader*) hReader)->GetHeader();
293
 
    return (LASHeaderH) new LASHeader( header );
294
 
}
295
 
 
296
 
LAS_DLL LASErrorEnum LASReader_SetSRS(LASHeaderH hReader, const LASSRSH hSRS) {
297
 
    
298
 
    VALIDATE_LAS_POINTER1(hReader, "LASReader_SetSRS", LE_Failure);
299
 
    VALIDATE_LAS_POINTER1(hSRS, "LASReader_SetSRS", LE_Failure);
300
 
 
301
 
    try {
302
 
        ((LASReader*) hReader)->SetSRS(*((LASSpatialReference*)hSRS));
303
 
    }
304
 
    catch (std::exception const& e) {
305
 
        LASError_PushError(LE_Failure, e.what(), "LASReader_SetSRS");
306
 
        return LE_Failure;
307
 
    }
308
 
 
309
 
    return LE_None;
310
 
}
311
 
 
312
 
LAS_DLL LASHeaderH LASHeader_Create(void) {
313
 
        return (LASHeaderH) new LASHeader();
314
 
}
315
 
 
316
 
LAS_DLL LASPointH LASPoint_Create(void) {
317
 
        return (LASPointH) new LASPoint();
318
 
}
319
 
 
320
 
LAS_DLL LASPointH LASPoint_Copy(const LASPointH hPoint) {
321
 
        return (LASPointH) new LASPoint(*((LASPoint*) hPoint));
322
 
}
323
 
 
324
 
LAS_DLL void LASPoint_Destroy(LASPointH hPoint) {
325
 
    VALIDATE_LAS_POINTER0(hPoint, "LASPoint_Destroy");
326
 
    delete (LASPoint*) hPoint;
327
 
    hPoint = NULL;
328
 
}
329
 
 
330
 
LAS_DLL double LASPoint_GetX(const LASPointH hPoint) {
331
 
 
332
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetX", 0.0);
333
 
    
334
 
    double value = ((LASPoint*) hPoint)->GetX();
335
 
    return value;
336
 
}
337
 
 
338
 
LAS_DLL LASErrorEnum LASPoint_SetX(LASPointH hPoint, double value) {
339
 
 
340
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetX", LE_Failure);
341
 
 
342
 
    try {
343
 
            ((LASPoint*) hPoint)->SetX(value);
344
 
    } catch (std::exception const& e)
345
 
    {
346
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetX");
347
 
        return LE_Failure;
348
 
    }
349
 
 
350
 
    return LE_None;
351
 
 
352
 
}
353
 
 
354
 
LAS_DLL double LASPoint_GetY(const LASPointH hPoint) {
355
 
    
356
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetY", 0.0);
357
 
    
358
 
    double value = ((LASPoint*) hPoint)->GetY();
359
 
    return value;
360
 
}
361
 
 
362
 
LAS_DLL LASErrorEnum LASPoint_SetY(LASPointH hPoint, double value) {
363
 
 
364
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetY", LE_Failure);
365
 
 
366
 
    try {
367
 
            ((LASPoint*) hPoint)->SetY(value);
368
 
    } catch (std::exception const& e)
369
 
    {
370
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetY");
371
 
        return LE_Failure;
372
 
    }
373
 
 
374
 
    return LE_None;
375
 
 
376
 
}
377
 
 
378
 
LAS_DLL double LASPoint_GetZ(const LASPointH hPoint) {
379
 
    
380
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetZ", 0.0);
381
 
    
382
 
    double value = ((LASPoint*) hPoint)->GetZ();
383
 
    return value;
384
 
}
385
 
 
386
 
LAS_DLL LASErrorEnum LASPoint_SetZ(LASPointH hPoint, double value) {
387
 
 
388
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetZ", LE_Failure);
389
 
 
390
 
    try {
391
 
            ((LASPoint*) hPoint)->SetZ(value);
392
 
    } catch (std::exception const& e)
393
 
    {
394
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetZ");
395
 
        return LE_Failure;
396
 
    }
397
 
 
398
 
    return LE_None;
399
 
 
400
 
}
401
 
 
402
 
LAS_DLL liblas::uint16_t LASPoint_GetIntensity(const LASPointH hPoint) {
403
 
    
404
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetIntensity", 0);
405
 
    
406
 
    liblas::uint16_t value = ((LASPoint*) hPoint)->GetIntensity();
407
 
    return value;
408
 
}
409
 
 
410
 
LAS_DLL LASErrorEnum LASPoint_SetIntensity(LASPointH hPoint, liblas::uint16_t value) {
411
 
 
412
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetIntensity", LE_Failure);
413
 
 
414
 
    try {
415
 
            ((LASPoint*) hPoint)->SetIntensity(value);
416
 
    } catch (std::exception const& e)
417
 
    {
418
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetIntensity");
419
 
        return LE_Failure;
420
 
    }
421
 
 
422
 
    return LE_None;
423
 
 
424
 
}
425
 
 
426
 
LAS_DLL liblas::uint16_t LASPoint_GetReturnNumber(const LASPointH hPoint) {
427
 
    
428
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetReturnNumber", 0);
429
 
    
430
 
    liblas::uint16_t value = ((LASPoint*) hPoint)->GetReturnNumber();
431
 
    return value;
432
 
}
433
 
 
434
 
LAS_DLL LASErrorEnum LASPoint_SetReturnNumber(LASPointH hPoint, liblas::uint16_t value) {
435
 
 
436
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetReturnNumber", LE_Failure);
437
 
 
438
 
    try {
439
 
            ((LASPoint*) hPoint)->SetReturnNumber(value);
440
 
    } catch (std::exception const& e)
441
 
    {
442
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetReturnNumber");
443
 
        return LE_Failure;
444
 
    }
445
 
 
446
 
    return LE_None;
447
 
 
448
 
}
449
 
 
450
 
LAS_DLL liblas::uint16_t LASPoint_GetNumberOfReturns(const LASPointH hPoint) {
451
 
    
452
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetNumberOfReturns", 0);
453
 
    
454
 
    liblas::uint16_t value = ((LASPoint*) hPoint)->GetNumberOfReturns();
455
 
    return value;
456
 
}
457
 
 
458
 
LAS_DLL LASErrorEnum LASPoint_SetNumberOfReturns(LASPointH hPoint, liblas::uint16_t value) {
459
 
 
460
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetNumberOfReturns", LE_Failure);
461
 
 
462
 
    try {
463
 
            ((LASPoint*) hPoint)->SetNumberOfReturns(value);
464
 
    } catch (std::exception const& e)
465
 
    {
466
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetNumberOfReturns");
467
 
        return LE_Failure;
468
 
    }
469
 
 
470
 
    return LE_None;
471
 
 
472
 
}
473
 
 
474
 
LAS_DLL liblas::uint16_t LASPoint_GetScanDirection(const LASPointH hPoint) {
475
 
    
476
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetScanDirection", 0);
477
 
    
478
 
    liblas::uint16_t value = ((LASPoint*) hPoint)->GetScanDirection();
479
 
    return value;
480
 
}
481
 
 
482
 
LAS_DLL LASErrorEnum LASPoint_SetScanDirection(LASPointH hPoint, liblas::uint16_t value) {
483
 
 
484
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetScanDirection", LE_Failure);
485
 
 
486
 
    try {
487
 
            ((LASPoint*) hPoint)->SetScanDirection(value);
488
 
    } catch (std::exception const& e)
489
 
    {
490
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetScanDirection");
491
 
        return LE_Failure;
492
 
    }
493
 
 
494
 
    return LE_None;
495
 
 
496
 
}
497
 
 
498
 
LAS_DLL liblas::uint16_t LASPoint_GetFlightLineEdge(const LASPointH hPoint) {
499
 
    
500
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetFlightLineEdge", 0);
501
 
    
502
 
    liblas::uint16_t value = ((LASPoint*) hPoint)->GetFlightLineEdge();
503
 
    return value;
504
 
}
505
 
 
506
 
LAS_DLL LASErrorEnum LASPoint_SetFlightLineEdge(LASPointH hPoint, liblas::uint16_t value) {
507
 
 
508
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetFlightLineEdge", LE_Failure);
509
 
 
510
 
    try {
511
 
            ((LASPoint*) hPoint)->SetFlightLineEdge(value);
512
 
    } catch (std::exception const& e)
513
 
    {
514
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetFlightLineEdge");
515
 
        return LE_Failure;
516
 
    }
517
 
 
518
 
    return LE_None;
519
 
 
520
 
}
521
 
 
522
 
LAS_DLL liblas::uint8_t LASPoint_GetScanFlags(const LASPointH hPoint) {
523
 
    
524
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetScanFlags", 0);
525
 
    
526
 
    liblas::uint8_t value = ((LASPoint*) hPoint)->GetScanFlags();
527
 
    return value;
528
 
}
529
 
 
530
 
LAS_DLL LASErrorEnum LASPoint_SetScanFlags(LASPointH hPoint, liblas::uint8_t value) {
531
 
 
532
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetScanFlags", LE_Failure);
533
 
 
534
 
    try {
535
 
            ((LASPoint*) hPoint)->SetScanFlags(value);
536
 
    } catch (std::exception const& e)
537
 
    {
538
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetScanFlags");
539
 
        return LE_Failure;
540
 
    }
541
 
 
542
 
    return LE_None;
543
 
 
544
 
}
545
 
 
546
 
LAS_DLL liblas::uint8_t LASPoint_GetClassification(const LASPointH hPoint) {
547
 
    
548
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetClassification", 0);
549
 
    
550
 
    liblas::uint8_t value = ((LASPoint*) hPoint)->GetClassification();
551
 
    return value;
552
 
}
553
 
 
554
 
LAS_DLL LASErrorEnum LASPoint_SetClassification(LASPointH hPoint, liblas::uint8_t value) {
555
 
 
556
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetClassification", LE_Failure);
557
 
 
558
 
    try {
559
 
            ((LASPoint*) hPoint)->SetClassification(value);
560
 
    } catch (std::exception const& e)
561
 
    {
562
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetClassification");
563
 
        return LE_Failure;
564
 
    }
565
 
 
566
 
    return LE_None;
567
 
 
568
 
}
569
 
 
570
 
LAS_DLL LASErrorEnum LASPoint_SetTime(LASPointH hPoint, double value) {
571
 
 
572
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetTime", LE_Failure);
573
 
 
574
 
    try {
575
 
            ((LASPoint*) hPoint)->SetTime(value);
576
 
    } catch (std::exception const& e)
577
 
    {
578
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetTime");
579
 
        return LE_Failure;
580
 
    }
581
 
 
582
 
    return LE_None;
583
 
 
584
 
}
585
 
 
586
 
LAS_DLL double LASPoint_GetTime(const LASPointH hPoint) {
587
 
    
588
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetTime", 0.0);
589
 
    
590
 
    double value = ((LASPoint*) hPoint)->GetTime();
591
 
    return value;
592
 
}
593
 
 
594
 
LAS_DLL liblas::int8_t LASPoint_GetScanAngleRank(const LASPointH hPoint) {
595
 
    
596
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetScanAngleRank", 0);
597
 
    
598
 
    liblas::int8_t value = ((LASPoint*) hPoint)->GetScanAngleRank();
599
 
    return value;
600
 
}
601
 
 
602
 
LAS_DLL LASErrorEnum LASPoint_SetScanAngleRank(LASPointH hPoint, liblas::int8_t value) {
603
 
 
604
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetScanAngleRank", LE_Failure);
605
 
 
606
 
    try {
607
 
            ((LASPoint*) hPoint)->SetScanAngleRank(value);
608
 
    } catch (std::exception const& e)
609
 
    {
610
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetScanAngleRank");
611
 
        return LE_Failure;
612
 
    }
613
 
 
614
 
    return LE_None;
615
 
 
616
 
}
617
 
 
618
 
LAS_DLL liblas::uint16_t LASPoint_GetPointSourceId(const LASPointH hPoint) {
619
 
    
620
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetPointSourceId", 0);
621
 
    
622
 
    liblas::uint16_t value = ((LASPoint*) hPoint)->GetPointSourceID();
623
 
    return value;
624
 
}
625
 
 
626
 
LAS_DLL LASErrorEnum LASPoint_SetPointSourceId(LASPointH hPoint, liblas::uint16_t value) {
627
 
 
628
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetPointSourceId", LE_Failure);
629
 
 
630
 
    try {
631
 
            ((LASPoint*) hPoint)->SetPointSourceID(value);
632
 
    } catch (std::exception const& e)
633
 
    {
634
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetPointSourceId");
635
 
        return LE_Failure;
636
 
    }
637
 
 
638
 
    return LE_None;
639
 
 
640
 
}
641
 
 
642
 
 
643
 
LAS_DLL liblas::uint8_t LASPoint_GetUserData(const LASPointH hPoint) {
644
 
    
645
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetUserData", 0);
646
 
    
647
 
    liblas::uint8_t value = ((LASPoint*) hPoint)->GetUserData();
648
 
    return value;
649
 
}
650
 
 
651
 
LAS_DLL LASErrorEnum LASPoint_SetUserData(LASPointH hPoint, liblas::uint8_t value) {
652
 
 
653
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetUserData", LE_Failure);
654
 
 
655
 
    try {
656
 
            ((LASPoint*) hPoint)->SetUserData(value);
657
 
    } catch (std::exception const& e)
658
 
    {
659
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetUserData");
660
 
        return LE_Failure;
661
 
    }
662
 
 
663
 
    return LE_None;
664
 
 
665
 
}
666
 
 
667
 
LAS_DLL int LASPoint_Equal(const LASPointH hPoint1, const LASPointH hPoint2) {
668
 
    VALIDATE_LAS_POINTER1(hPoint1, "LASPoint_Equal", 0);
669
 
    VALIDATE_LAS_POINTER1(hPoint2, "LASPoint_Equal", 0);
670
 
 
671
 
    LASPoint* point1 = ((LASPoint*) hPoint1);
672
 
    LASPoint* point2 = ((LASPoint*) hPoint2);
673
 
 
674
 
    return (point1 == point2);
675
 
 
676
 
}
677
 
 
678
 
LAS_DLL int LASPoint_Validate(LASPointH hPoint) {
679
 
 
680
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_Validate", LE_Failure);
681
 
 
682
 
    try {
683
 
            ((LASPoint*) hPoint)->Validate();
684
 
    } catch (invalid_point_data const& e /*e */) {
685
 
        return e.who();
686
 
    } catch (std::exception const& e)
687
 
    {
688
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_Validate");
689
 
        return LE_Failure;
690
 
    }
691
 
 
692
 
    return LE_None;
693
 
}
694
 
 
695
 
LAS_DLL int LASPoint_IsValid(LASPointH hPoint) {
696
 
 
697
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_IsValid", LE_Failure);
698
 
    return ((LASPoint*) hPoint)->IsValid();
699
 
}
700
 
 
701
 
LAS_DLL char* LASHeader_GetFileSignature(const LASHeaderH hHeader) {
702
 
    // caller owns it
703
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetFileSignature", NULL);
704
 
    
705
 
    std::string signature = ((LASHeader*) hHeader)->GetFileSignature();
706
 
    return strdup(signature.c_str());
707
 
}
708
 
 
709
 
LAS_DLL liblas::uint16_t LASHeader_GetFileSourceId(const LASHeaderH hHeader) {
710
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetFileSourceId", 0);
711
 
 
712
 
    unsigned short value = ((LASHeader*) hHeader)->GetFileSourceId();
713
 
    return value;
714
 
}
715
 
 
716
 
LAS_DLL LASErrorEnum LASHeader_SetFileSourceId(LASHeaderH hHeader, liblas::uint16_t value) {
717
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetFileSourceId", LE_Failure);
718
 
    ((LASHeader*) hHeader)->SetFileSourceId(value);    
719
 
    return LE_None;
720
 
}
721
 
 
722
 
 
723
 
LAS_DLL liblas::uint16_t LASHeader_GetReserved(const LASHeaderH hHeader) {
724
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetReserved", 0);
725
 
 
726
 
    unsigned short value = ((LASHeader*) hHeader)->GetReserved();
727
 
    return value;
728
 
}
729
 
 
730
 
LAS_DLL LASErrorEnum LASHeader_SetReserved(LASHeaderH hHeader, liblas::uint16_t value) {
731
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetReserved", LE_Failure);
732
 
    ((LASHeader*) hHeader)->SetReserved(value);    
733
 
    return LE_None;
734
 
}
735
 
 
736
 
LAS_DLL char* LASHeader_GetProjectId(const LASHeaderH hHeader) {
737
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetProjectId", 0);
738
 
    
739
 
    liblas::guid id = ((LASHeader*) hHeader)->GetProjectId();
740
 
    return strdup(id.to_string().c_str());
741
 
}
742
 
 
743
 
LAS_DLL LASErrorEnum LASHeader_SetProjectId(LASHeaderH hHeader, const char* value) {
744
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetProjectId", LE_Failure);
745
 
 
746
 
    try {
747
 
        liblas::guid id;
748
 
        id = liblas::guid::guid(value);
749
 
        ((LASHeader*) hHeader)->SetProjectId(id);    
750
 
    } catch (std::exception const& e)
751
 
    {
752
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetGUID");
753
 
        return LE_Failure;
754
 
    }
755
 
 
756
 
    return LE_None;
757
 
}
758
 
 
759
 
LAS_DLL liblas::uint8_t LASHeader_GetVersionMajor(const LASHeaderH hHeader) {
760
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetVersionMajor", 0);
761
 
 
762
 
    long value = ((LASHeader*) hHeader)->GetVersionMajor();
763
 
    return liblas::uint8_t(value);
764
 
}
765
 
 
766
 
LAS_DLL LASErrorEnum LASHeader_SetVersionMajor(LASHeaderH hHeader, liblas::uint8_t value) {
767
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetVersionMajor", LE_Failure);
768
 
 
769
 
    try {
770
 
        ((LASHeader*) hHeader)->SetVersionMajor(value);    
771
 
    } catch (std::exception const& e)
772
 
    {
773
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetVersionMajor");
774
 
        return LE_Failure;
775
 
    }
776
 
 
777
 
    return LE_None;
778
 
}
779
 
 
780
 
LAS_DLL liblas::uint8_t LASHeader_GetVersionMinor(const LASHeaderH hHeader) {
781
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetVersionMinor", 0);
782
 
 
783
 
    long value = ((LASHeader*) hHeader)->GetVersionMinor();
784
 
    return liblas::uint8_t(value);
785
 
}
786
 
 
787
 
LAS_DLL LASErrorEnum LASHeader_SetVersionMinor(LASHeaderH hHeader, liblas::uint8_t value) {
788
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetVersionMinor", LE_Failure);
789
 
 
790
 
    // TODO: Maybe this should be a fatal error -- hobu
791
 
    try {
792
 
        ((LASHeader*) hHeader)->SetVersionMinor(value);    
793
 
    } catch (std::exception const& e)
794
 
    {
795
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetVersionMinor");
796
 
        return LE_Failure;
797
 
    }
798
 
 
799
 
    return LE_None;
800
 
}
801
 
 
802
 
LAS_DLL char* LASHeader_GetSystemId(const LASHeaderH hHeader) {
803
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetSystemId", NULL);
804
 
 
805
 
    // caller owns it
806
 
    std::string sysid = ((LASHeader*) hHeader)->GetSystemId();
807
 
    return strdup(sysid.c_str());
808
 
}
809
 
 
810
 
LAS_DLL LASErrorEnum LASHeader_SetSystemId(LASHeaderH hHeader, const char* value) {
811
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetSystemId", LE_Failure); 
812
 
 
813
 
    try {
814
 
            ((LASHeader*) hHeader)->SetSystemId(value);
815
 
    } catch (std::exception const& e)
816
 
    {
817
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetSystemId");
818
 
        return LE_Failure;
819
 
    }
820
 
 
821
 
    return LE_None;
822
 
}
823
 
 
824
 
LAS_DLL char* LASHeader_GetSoftwareId(const LASHeaderH hHeader) {
825
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetSoftwareId", NULL);
826
 
 
827
 
    // caller owns it
828
 
    std::string softid = ((LASHeader*) hHeader)->GetSoftwareId();
829
 
    return strdup(softid.c_str());
830
 
}
831
 
 
832
 
LAS_DLL LASErrorEnum LASHeader_SetSoftwareId(LASHeaderH hHeader, const char* value) {
833
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetSoftwareId", LE_Failure); 
834
 
 
835
 
    try {
836
 
            ((LASHeader*) hHeader)->SetSoftwareId(value);
837
 
    } catch (std::exception const& e)
838
 
    {
839
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetSoftwareId");
840
 
        return LE_Failure;
841
 
    }
842
 
 
843
 
    return LE_None;
844
 
}
845
 
 
846
 
LAS_DLL liblas::uint16_t LASHeader_GetCreationDOY(const LASHeaderH hHeader) {
847
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetCreationDOY", 0);
848
 
 
849
 
    unsigned short value = ((LASHeader*) hHeader)->GetCreationDOY();
850
 
    return value;
851
 
}
852
 
 
853
 
LAS_DLL LASErrorEnum LASHeader_SetCreationDOY(LASHeaderH hHeader, liblas::uint16_t value) {
854
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetCreationDOY", LE_Failure);
855
 
    ((LASHeader*) hHeader)->SetCreationDOY(value);    
856
 
    return LE_None;
857
 
}
858
 
 
859
 
LAS_DLL liblas::uint16_t LASHeader_GetCreationYear(const LASHeaderH hHeader) {
860
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetCreationYear", 0);
861
 
 
862
 
    unsigned short value = ((LASHeader*) hHeader)->GetCreationYear();
863
 
    return value;
864
 
}
865
 
 
866
 
LAS_DLL LASErrorEnum LASHeader_SetCreationYear(LASHeaderH hHeader, liblas::uint16_t value) {
867
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetCreationYear", LE_Failure);
868
 
    ((LASHeader*) hHeader)->SetCreationYear(value);    
869
 
    return LE_None;
870
 
}
871
 
 
872
 
LAS_DLL liblas::uint16_t LASHeader_GetHeaderSize(const LASHeaderH hHeader) {
873
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetHeaderSize", 0);
874
 
 
875
 
    unsigned short value = ((LASHeader*) hHeader)->GetHeaderSize();
876
 
    return value;
877
 
}
878
 
 
879
 
LAS_DLL liblas::uint32_t LASHeader_GetDataOffset(const LASHeaderH hHeader) {
880
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetDataOffset", 0);
881
 
 
882
 
    unsigned long value = ((LASHeader*) hHeader)->GetDataOffset();
883
 
    return value;
884
 
}
885
 
 
886
 
LAS_DLL LASErrorEnum LASHeader_SetDataOffset(const LASHeaderH hHeader, liblas::uint32_t value) {
887
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetDataOffset", LE_Failure);
888
 
 
889
 
    try {
890
 
        ((LASHeader*) hHeader)->SetDataOffset(value);    
891
 
    } catch (std::exception const& e)
892
 
    {
893
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetDataOffset");
894
 
        return LE_Failure;
895
 
    }
896
 
 
897
 
    return LE_None;    
898
 
}
899
 
 
900
 
 
901
 
LAS_DLL liblas::uint32_t LASHeader_GetRecordsCount(const LASHeaderH hHeader) {
902
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetRecordsCount", 0);
903
 
 
904
 
    unsigned long value = ((LASHeader*) hHeader)->GetRecordsCount();
905
 
    return value;
906
 
}
907
 
 
908
 
LAS_DLL liblas::uint8_t LASHeader_GetDataFormatId(const LASHeaderH hHeader) {
909
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetDataFormatId", 0);
910
 
    
911
 
    LASHeader::PointFormat id = ((LASHeader*) hHeader)->GetDataFormatId();
912
 
    return static_cast<liblas::uint8_t>(id);
913
 
}
914
 
 
915
 
LAS_DLL LASErrorEnum LASHeader_SetDataFormatId(LASHeaderH hHeader, liblas::uint8_t value) {
916
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetDataFormatId", LE_Failure); 
917
 
    
918
 
    try {
919
 
            ((LASHeader*) hHeader)->SetDataFormatId((liblas::LASHeader::PointFormat)value);
920
 
    } catch (std::exception const& e)
921
 
    {
922
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetDataFormatId");
923
 
        return LE_Failure;
924
 
    }
925
 
 
926
 
    return LE_None;
927
 
}
928
 
 
929
 
LAS_DLL liblas::uint16_t LASHeader_GetDataRecordLength(const LASHeaderH hHeader) {
930
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetDataRecordLength", 0);
931
 
 
932
 
    unsigned short value = ((LASHeader*) hHeader)->GetDataRecordLength();
933
 
    return value;
934
 
}
935
 
 
936
 
 
937
 
LAS_DLL liblas::uint32_t LASHeader_GetPointRecordsByReturnCount(const LASHeaderH hHeader, int index) {
938
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetPointRecordsByReturnCount", 0);
939
 
 
940
 
    std::vector<liblas::uint32_t> counts  = ((LASHeader*) hHeader)->GetPointRecordsByReturnCount();
941
 
    if ( (index < 5) && (index >= 0)) {
942
 
        return counts[index];
943
 
    } 
944
 
 
945
 
    return 0;
946
 
    
947
 
}
948
 
 
949
 
LAS_DLL LASErrorEnum LASHeader_SetPointRecordsByReturnCount(const LASHeaderH hHeader, int index, liblas::uint32_t value) {
950
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetPointRecordsByReturnCount", LE_Failure);
951
 
 
952
 
    try {
953
 
        ((LASHeader*) hHeader)->SetPointRecordsByReturnCount(index, value);    
954
 
    } catch (std::exception const& e)
955
 
    {
956
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetPointRecordsByReturnCount");
957
 
        return LE_Failure;
958
 
    }
959
 
 
960
 
    return LE_None;    
961
 
}
962
 
 
963
 
 
964
 
LAS_DLL liblas::uint32_t LASHeader_GetPointRecordsCount(const LASHeaderH hHeader) {
965
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetPointRecordsCount", 0);
966
 
 
967
 
    unsigned long value = ((LASHeader*) hHeader)->GetPointRecordsCount();
968
 
    return value;
969
 
}
970
 
 
971
 
LAS_DLL LASErrorEnum LASHeader_SetPointRecordsCount(const LASHeaderH hHeader, liblas::uint32_t value) {
972
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetPointRecordsCount", LE_Failure);
973
 
 
974
 
    try {
975
 
        ((LASHeader*) hHeader)->SetPointRecordsCount(value);    
976
 
    } catch (std::exception const& e)
977
 
    {
978
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetPointRecordsCount");
979
 
        return LE_Failure;
980
 
    }
981
 
 
982
 
    return LE_None;    
983
 
}
984
 
 
985
 
LAS_DLL double LASHeader_GetScaleX(const LASHeaderH hHeader) {
986
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetScaleX", 0.0);
987
 
 
988
 
    double value = ((LASHeader*) hHeader)->GetScaleX();
989
 
    return value;
990
 
}
991
 
 
992
 
LAS_DLL double LASHeader_GetScaleY(const LASHeaderH hHeader) {
993
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetScaleY", 0.0);
994
 
 
995
 
    double value = ((LASHeader*) hHeader)->GetScaleY();
996
 
    return value;
997
 
}
998
 
 
999
 
LAS_DLL double LASHeader_GetScaleZ(const LASHeaderH hHeader) {
1000
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetScaleZ", 0.0);
1001
 
 
1002
 
    double value = ((LASHeader*) hHeader)->GetScaleZ();
1003
 
    return value;
1004
 
}
1005
 
 
1006
 
LAS_DLL LASErrorEnum LASHeader_SetScale(LASHeaderH hHeader, double x, double y, double z) {
1007
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetScale", LE_Failure); 
1008
 
    
1009
 
    try {
1010
 
            ((LASHeader*) hHeader)->SetScale(x,y,z);
1011
 
    } catch (std::exception const& e)
1012
 
    {
1013
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetScale");
1014
 
        return LE_Failure;
1015
 
    }
1016
 
 
1017
 
    return LE_None;
1018
 
}
1019
 
 
1020
 
LAS_DLL double LASHeader_GetOffsetX(const LASHeaderH hHeader) {
1021
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetOffsetX", 0.0);
1022
 
 
1023
 
    double value = ((LASHeader*) hHeader)->GetOffsetX();
1024
 
    return value;
1025
 
}
1026
 
 
1027
 
LAS_DLL double LASHeader_GetOffsetY(const LASHeaderH hHeader) {
1028
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetOffsetY", 0.0);
1029
 
 
1030
 
    double value = ((LASHeader*) hHeader)->GetOffsetY();
1031
 
    return value;
1032
 
}
1033
 
 
1034
 
LAS_DLL double LASHeader_GetOffsetZ(const LASHeaderH hHeader) {
1035
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetOffsetZ", 0.0);
1036
 
 
1037
 
    double value = ((LASHeader*) hHeader)->GetOffsetZ();
1038
 
    return value;
1039
 
}
1040
 
 
1041
 
LAS_DLL LASErrorEnum LASHeader_SetOffset(LASHeaderH hHeader, double x, double y, double z) {
1042
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetOffset", LE_Failure); 
1043
 
    
1044
 
    try {
1045
 
            ((LASHeader*) hHeader)->SetOffset(x,y,z);
1046
 
    } catch (std::exception const& e)
1047
 
    {
1048
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetOffset");
1049
 
        return LE_Failure;
1050
 
    }
1051
 
 
1052
 
    return LE_None;
1053
 
}
1054
 
 
1055
 
LAS_DLL double LASHeader_GetMinX(const LASHeaderH hHeader) {
1056
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetMinX", 0.0);
1057
 
 
1058
 
    double value = ((LASHeader*) hHeader)->GetMinX();
1059
 
    return value;
1060
 
}
1061
 
 
1062
 
LAS_DLL double LASHeader_GetMinY(const LASHeaderH hHeader) {
1063
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetMinY", 0.0);
1064
 
 
1065
 
    double value = ((LASHeader*) hHeader)->GetMinY();
1066
 
    return value;
1067
 
}
1068
 
 
1069
 
LAS_DLL double LASHeader_GetMinZ(const LASHeaderH hHeader) {
1070
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetMinZ", 0.0);
1071
 
 
1072
 
    double value = ((LASHeader*) hHeader)->GetMinZ();
1073
 
    return value;
1074
 
}
1075
 
 
1076
 
LAS_DLL LASErrorEnum LASHeader_SetMin(LASHeaderH hHeader, double x, double y, double z) {
1077
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetMin", LE_Failure); 
1078
 
    
1079
 
    try {
1080
 
            ((LASHeader*) hHeader)->SetMin(x,y,z);
1081
 
    } catch (std::exception const& e)
1082
 
    {
1083
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetMin");
1084
 
        return LE_Failure;
1085
 
    }
1086
 
 
1087
 
    return LE_None;
1088
 
}
1089
 
 
1090
 
LAS_DLL double LASHeader_GetMaxX(const LASHeaderH hHeader) {
1091
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetMaxX", 0.0);
1092
 
 
1093
 
    double value = ((LASHeader*) hHeader)->GetMaxX();
1094
 
    return value;
1095
 
}
1096
 
 
1097
 
LAS_DLL double LASHeader_GetMaxY(const LASHeaderH hHeader) {
1098
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetMaxY", 0.0);
1099
 
 
1100
 
    double value = ((LASHeader*) hHeader)->GetMaxY();
1101
 
    return value;
1102
 
}
1103
 
 
1104
 
LAS_DLL double LASHeader_GetMaxZ(const LASHeaderH hHeader) {
1105
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetMaxZ", 0.0);
1106
 
 
1107
 
    double value = ((LASHeader*) hHeader)->GetMaxZ();
1108
 
    return value;
1109
 
}
1110
 
 
1111
 
LAS_DLL LASErrorEnum LASHeader_SetMax(LASHeaderH hHeader, double x, double y, double z) {
1112
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetMax", LE_Failure); 
1113
 
    
1114
 
    try {
1115
 
            ((LASHeader*) hHeader)->SetMax(x,y,z);
1116
 
    } catch (std::exception const& e)
1117
 
    {
1118
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetMax");
1119
 
        return LE_Failure;
1120
 
    }
1121
 
 
1122
 
    return LE_None;
1123
 
}
1124
 
 
1125
 
LAS_DLL void LASHeader_Destroy(LASHeaderH hHeader)
1126
 
{
1127
 
    VALIDATE_LAS_POINTER0(hHeader, "LASHeader_Destroy");
1128
 
    delete ((LASHeader*) hHeader);
1129
 
    hHeader=NULL;
1130
 
}
1131
 
 
1132
 
LAS_DLL LASHeaderH LASHeader_Copy(const LASHeaderH hHeader) {
1133
 
        return (LASHeaderH) new LASHeader(*((LASHeader*) hHeader));
1134
 
}
1135
 
 
1136
 
LAS_DLL int LASHeader_Equal(const LASHeaderH hHeader1, const LASHeaderH hHeader2) {
1137
 
    VALIDATE_LAS_POINTER1(hHeader1, "LASHeader_Equal", 0);
1138
 
    VALIDATE_LAS_POINTER1(hHeader2, "LASHeader_Equal", 0);
1139
 
 
1140
 
    LASHeader* header1 = ((LASHeader*) hHeader1);
1141
 
    LASHeader* header2 = ((LASHeader*) hHeader2);
1142
 
 
1143
 
    return (header1 == header2);
1144
 
}
1145
 
 
1146
 
LAS_DLL LASGuidH LASHeader_GetGUID(const LASHeaderH hHeader) {
1147
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetGUID", 0);
1148
 
    
1149
 
    liblas::guid id = ((LASHeader*) hHeader)->GetProjectId();
1150
 
    return (LASGuidH) new liblas::guid(id);
1151
 
}
1152
 
 
1153
 
 
1154
 
LAS_DLL LASErrorEnum LASHeader_SetGUID(LASHeaderH hHeader, LASGuidH hId) {
1155
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetGUID", LE_Failure);
1156
 
 
1157
 
    try {
1158
 
        liblas::guid* id = (liblas::guid*) hId;
1159
 
        
1160
 
        ((LASHeader*) hHeader)->SetProjectId(*id);    
1161
 
    } catch (std::exception const& e)
1162
 
    {
1163
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetGUID");
1164
 
        return LE_Failure;
1165
 
    }
1166
 
 
1167
 
    return LE_None;
1168
 
}
1169
 
 
1170
 
LAS_DLL LASVLRH LASHeader_GetVLR(const LASHeaderH hHeader, liblas::uint32_t i) {
1171
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetVLR", 0);
1172
 
    
1173
 
    LASVariableRecord vlr = ((LASHeader*) hHeader)->GetVLR(i);
1174
 
    return (LASVLRH) new LASVariableRecord(vlr);
1175
 
}
1176
 
 
1177
 
LAS_DLL LASErrorEnum LASHeader_DeleteVLR(LASHeaderH hHeader, liblas::uint32_t index) {
1178
 
    
1179
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_DeleteVLR", LE_Failure);
1180
 
 
1181
 
    try {
1182
 
        ((LASHeader*) hHeader)->DeleteVLR(index);
1183
 
    }
1184
 
    catch (std::exception const& e) {
1185
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_DeleteVLR");
1186
 
        return LE_Failure;
1187
 
    }
1188
 
 
1189
 
 
1190
 
    return LE_None;
1191
 
}
1192
 
 
1193
 
LAS_DLL LASErrorEnum LASHeader_AddVLR(LASHeaderH hHeader, const LASVLRH hVLR) {
1194
 
    
1195
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_AddVLR", LE_Failure);
1196
 
    VALIDATE_LAS_POINTER1(hVLR, "LASHeader_AddVLR", LE_Failure);
1197
 
 
1198
 
    try {
1199
 
        ((LASHeader*) hHeader)->AddVLR(*((LASVariableRecord*)hVLR));
1200
 
    }
1201
 
    catch (std::exception const& e) {
1202
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_AddVLR");
1203
 
        return LE_Failure;
1204
 
    }
1205
 
 
1206
 
 
1207
 
    return LE_None;
1208
 
}
1209
 
 
1210
 
 
1211
 
 
1212
 
 
1213
 
LAS_DLL LASWriterH LASWriter_Create(const char* filename, const LASHeaderH hHeader, int mode) {
1214
 
    VALIDATE_LAS_POINTER1(hHeader, "LASWriter_Create", NULL); 
1215
 
    
1216
 
    if (filename == NULL) {
1217
 
        LASError_PushError(LE_Failure, "Input filename was null", "LASWriter_Create");
1218
 
        return NULL;
1219
 
    }
1220
 
    try {
1221
 
        std::ios::openmode m;
1222
 
        if ( (mode > 2) || (mode < 1)) {
1223
 
            throw std::runtime_error("File mode must be eWrite or eAppend");
1224
 
        }
1225
 
        
1226
 
        std::ostream* ostrm;
1227
 
 
1228
 
        // append mode 
1229
 
        if (mode == 2) {
1230
 
            m = std::ios::out | std::ios::in | std::ios::binary | std::ios::ate;
1231
 
        }
1232
 
        // write mode
1233
 
        else {
1234
 
            m = std::ios::out | std::ios::binary | std::ios::ate;
1235
 
        }
1236
 
                
1237
 
        if (compare_no_case(filename,"STOUT",5) == 0)
1238
 
        {
1239
 
            ostrm = &std::cout;
1240
 
        }
1241
 
        else 
1242
 
        {
1243
 
            ostrm = new std::ofstream(filename, m);
1244
 
        }
1245
 
 
1246
 
        
1247
 
        if (!ostrm->good())
1248
 
        {
1249
 
            delete ostrm;
1250
 
            throw std::runtime_error("Writing stream was not able to be created");
1251
 
        }
1252
 
        
1253
 
        LASHeader* header = ((LASHeader*) hHeader);
1254
 
        LASWriter* writer = new LASWriter(*ostrm, *header);
1255
 
        return (LASWriterH) writer;
1256
 
 
1257
 
    } catch (std::exception const& e)
1258
 
     {
1259
 
         LASError_PushError(LE_Failure, e.what(), "LASWriter_Create");
1260
 
         return NULL;
1261
 
     }
1262
 
    
1263
 
}
1264
 
 
1265
 
LAS_DLL LASErrorEnum LASWriter_WritePoint(const LASWriterH hWriter, const LASPointH hPoint) {
1266
 
 
1267
 
    VALIDATE_LAS_POINTER1(hPoint, "LASWriter_WritePoint", LE_Failure);
1268
 
    int ret;
1269
 
 
1270
 
    try {
1271
 
            ret = ((LASWriter*) hWriter)->WritePoint(*((LASPoint*) hPoint));
1272
 
            if (!ret) {
1273
 
                LASError_PushError( LE_Warning, 
1274
 
                                    "Failed to write point because it was invalid", 
1275
 
                                    "LASWriter_WritePoint");
1276
 
                return LE_Warning;                
1277
 
            }
1278
 
    } catch (std::exception const& e)
1279
 
    {
1280
 
        LASError_PushError(LE_Failure, e.what(), "LASWriter_WritePoint");
1281
 
        return LE_Failure;
1282
 
    }
1283
 
 
1284
 
    return LE_None;    
1285
 
}
1286
 
 
1287
 
LAS_DLL LASErrorEnum LASWriter_WriteHeader(const LASWriterH hWriter, const LASHeaderH hHeader) {
1288
 
 
1289
 
    VALIDATE_LAS_POINTER1(hHeader, "LASWriter_WriteHeader", LE_Failure);
1290
 
    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_WriteHeader", LE_Failure);
1291
 
    
1292
 
    try {
1293
 
            ((LASWriter*) hWriter)->WriteHeader(*((LASHeader*) hHeader));
1294
 
    } catch (std::exception const& e)
1295
 
    {
1296
 
        LASError_PushError(LE_Failure, e.what(), "LASWriter_WriteHeader");
1297
 
        return LE_Failure;
1298
 
    }
1299
 
 
1300
 
    return LE_None;    
1301
 
}
1302
 
 
1303
 
LAS_DLL void LASWriter_Destroy(LASWriterH hWriter)
1304
 
{
1305
 
    VALIDATE_LAS_POINTER0(hWriter, "LASWriter_Destroy");
1306
 
 
1307
 
 
1308
 
    
1309
 
 
1310
 
  
1311
 
    
1312
 
    try { 
1313
 
        LASWriter* writer = (LASWriter*)hWriter;
1314
 
        std::ostream* ostrm = &(writer->GetStream());
1315
 
 
1316
 
        delete writer;
1317
 
        hWriter = NULL;
1318
 
    
1319
 
        if (static_cast<std::ofstream&>(*ostrm))
1320
 
            static_cast<std::ofstream&>(*ostrm).close();
1321
 
        delete ostrm;
1322
 
        ostrm = NULL;
1323
 
  
1324
 
        }  catch (std::runtime_error const& e/* e */) 
1325
 
        {
1326
 
            LASError_PushError(LE_Failure, e.what(), "LASWriter_Destroy");
1327
 
            return;
1328
 
        }
1329
 
 
1330
 
}
1331
 
 
1332
 
LAS_DLL LASErrorEnum LASWriter_SetSRS(LASWriterH hWriter, const LASSRSH hSRS) {
1333
 
    
1334
 
    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_SetSRS", LE_Failure);
1335
 
    VALIDATE_LAS_POINTER1(hSRS, "LASWriter_SetSRS", LE_Failure);
1336
 
 
1337
 
    try {
1338
 
        ((LASWriter*) hWriter)->SetSRS(*((LASSpatialReference*)hSRS));
1339
 
    }
1340
 
    catch (std::exception const& e) {
1341
 
        LASError_PushError(LE_Failure, e.what(), "LASWriter_SetSRS");
1342
 
        return LE_Failure;
1343
 
    }
1344
 
 
1345
 
    return LE_None;
1346
 
}
1347
 
 
1348
 
LAS_DLL void LASError_Print(const char* message) {
1349
 
 
1350
 
    char* errmsg= NULL;
1351
 
    char* errmethod = NULL;
1352
 
    errmsg = LASError_GetLastErrorMsg();
1353
 
    errmethod = LASError_GetLastErrorMethod();
1354
 
    if (LASError_GetErrorCount()) {
1355
 
        fprintf(stderr, 
1356
 
            "%s: %s (%d) from method %s\n",
1357
 
            message,
1358
 
            errmsg,
1359
 
            LASError_GetLastErrorNum(),
1360
 
            errmethod
1361
 
        ); 
1362
 
        if (errmsg) free(errmsg);
1363
 
        if (errmethod) free(errmethod);
1364
 
    } else {
1365
 
        fprintf(stderr, 
1366
 
            "You have encountered an error. '%s'\n",
1367
 
            message
1368
 
        );         
1369
 
    }
1370
 
 
1371
 
}
1372
 
 
1373
 
LAS_DLL char * LAS_GetVersion() {
1374
 
 
1375
 
    /* XXX - mloskot: I'd suggest to define PACKAGE_VERSION as static object
1376
 
       and return safe const pointer, instead of newly allocated string. */
1377
 
 
1378
 
    /* FIXME - mloskot: Termporarily, I defined PACKAGE_VERSION
1379
 
       in las_config.h to solve Visual C++ compilation  (Ticket #23) */
1380
 
 
1381
 
    std::ostringstream output;
1382
 
        
1383
 
//    output << LIBLAS_VERSION_MAJOR;
1384
 
//    output << "." << LIBLAS_VERSION_MINOR;
1385
 
//    output << "." << LIBLAS_VERSION_REV;
1386
 
//    output << "." << LIBLAS_VERSION_BUILD;
1387
 
    output << LIBLAS_RELEASE_NAME;
1388
 
    std::string out(output.str());
1389
 
    return strdup(out.c_str());
1390
 
}
1391
 
 
1392
 
 
1393
 
 
1394
 
LAS_DLL LASVLRH LASVLR_Create(void) {
1395
 
    return (LASVLRH) new LASVariableRecord();
1396
 
}
1397
 
 
1398
 
LAS_DLL void LASVLR_Destroy(LASVLRH hVLR){
1399
 
    VALIDATE_LAS_POINTER0(hVLR, "LASVLR_Destroy");
1400
 
    delete (LASVariableRecord*)hVLR;
1401
 
    hVLR = NULL;
1402
 
    
1403
 
}
1404
 
 
1405
 
LAS_DLL char* LASVLR_GetUserId(const LASVLRH hVLR) {
1406
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetUserId", 0);
1407
 
    LASVariableRecord* vlr = (LASVariableRecord*)hVLR;
1408
 
    return strdup(vlr->GetUserId(true).c_str());
1409
 
}
1410
 
 
1411
 
LAS_DLL LASErrorEnum LASVLR_SetUserId(LASVLRH hVLR, const char* value) {
1412
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetUserId", LE_Failure); 
1413
 
 
1414
 
    try {
1415
 
            ((LASVariableRecord*) hVLR)->SetUserId(value);
1416
 
    } catch (std::exception const& e)
1417
 
    {
1418
 
        LASError_PushError(LE_Failure, e.what(), "LASVLR_SetUserId");
1419
 
        return LE_Failure;
1420
 
    }
1421
 
 
1422
 
    return LE_None;
1423
 
}
1424
 
 
1425
 
LAS_DLL char* LASVLR_GetDescription(const LASVLRH hVLR) {
1426
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetDescription", 0);
1427
 
    LASVariableRecord* vlr = (LASVariableRecord*)hVLR;
1428
 
    return strdup(vlr->GetDescription(true).c_str());
1429
 
}
1430
 
 
1431
 
LAS_DLL LASErrorEnum LASVLR_SetDescription(LASVLRH hVLR, const char* value) {
1432
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetDescription", LE_Failure); 
1433
 
 
1434
 
    try {
1435
 
            ((LASVariableRecord*) hVLR)->SetDescription(value);
1436
 
    } catch (std::exception const& e)
1437
 
    {
1438
 
        LASError_PushError(LE_Failure, e.what(), "LASVLR_SetDescription");
1439
 
        return LE_Failure;
1440
 
    }
1441
 
 
1442
 
    return LE_None;
1443
 
}
1444
 
 
1445
 
LAS_DLL liblas::uint16_t LASVLR_GetRecordLength(const LASVLRH hVLR) {
1446
 
    
1447
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetRecordLength", 0);
1448
 
    
1449
 
    liblas::uint16_t value = ((LASVariableRecord*) hVLR)->GetRecordLength();
1450
 
    return value;
1451
 
}
1452
 
LAS_DLL LASErrorEnum LASVLR_SetRecordLength(LASVLRH hVLR, liblas::uint16_t value) {
1453
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetRecordLength", LE_Failure);
1454
 
    ((LASVariableRecord*) hVLR)->SetRecordLength(value);    
1455
 
    return LE_None;
1456
 
}
1457
 
 
1458
 
LAS_DLL liblas::uint16_t LASVLR_GetRecordId(const LASVLRH hVLR) {
1459
 
    
1460
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetRecordId", 0);
1461
 
    
1462
 
    liblas::uint16_t value = ((LASVariableRecord*) hVLR)->GetRecordId();
1463
 
    return value;
1464
 
}
1465
 
LAS_DLL LASErrorEnum LASVLR_SetRecordId(LASVLRH hVLR, liblas::uint16_t value) {
1466
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetRecordId", LE_Failure);
1467
 
    ((LASVariableRecord*) hVLR)->SetRecordId(value);    
1468
 
    return LE_None;
1469
 
}
1470
 
 
1471
 
 
1472
 
LAS_DLL LASErrorEnum LASVLR_SetReserved(LASVLRH hVLR, liblas::uint16_t value) {
1473
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetReserved", LE_Failure);
1474
 
    ((LASVariableRecord*) hVLR)->SetReserved(value);    
1475
 
    return LE_None;
1476
 
}
1477
 
 
1478
 
LAS_DLL liblas::uint16_t LASVLR_GetReserved(const LASVLRH hVLR) {
1479
 
    
1480
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetReserved", 0);
1481
 
    
1482
 
    liblas::uint16_t value = ((LASVariableRecord*) hVLR)->GetReserved();
1483
 
    return value;
1484
 
}
1485
 
 
1486
 
LAS_DLL LASErrorEnum LASVLR_GetData(const LASVLRH hVLR, liblas::uint8_t* data) {
1487
 
    
1488
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetData", LE_Failure);
1489
 
 
1490
 
    try {
1491
 
        LASVariableRecord* vlr = ((LASVariableRecord*) hVLR);
1492
 
        std::vector<liblas::uint8_t> d = vlr->GetData();
1493
 
        liblas::uint16_t length = vlr->GetRecordLength();
1494
 
        for (liblas::uint16_t i=0; i < length; i++) {
1495
 
            data[i] = d[i];
1496
 
        }
1497
 
    }
1498
 
    catch (std::exception const& e) {
1499
 
        LASError_PushError(LE_Failure, e.what(), "LASVLR_GetData");
1500
 
        return LE_Failure;
1501
 
    }
1502
 
 
1503
 
 
1504
 
    return LE_None;
1505
 
}
1506
 
 
1507
 
LAS_DLL LASErrorEnum LASVLR_SetData(const LASVLRH hVLR, liblas::uint8_t* data, liblas::uint16_t length) {
1508
 
    
1509
 
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetData", LE_Failure);
1510
 
 
1511
 
    try {
1512
 
        LASVariableRecord* vlr = ((LASVariableRecord*) hVLR);
1513
 
        std::vector<liblas::uint8_t> d;
1514
 
        d.resize(length);
1515
 
        for (liblas::uint16_t i=0; i < length; i++) {
1516
 
            d[i] = data[i];
1517
 
        }
1518
 
        vlr->SetData(d);
1519
 
    }
1520
 
    catch (std::exception const& e) {
1521
 
        LASError_PushError(LE_Failure, e.what(), "LASVLR_GetData");
1522
 
        return LE_Failure;
1523
 
    }
1524
 
 
1525
 
 
1526
 
    return LE_None;
1527
 
}
1528
 
 
1529
 
LAS_DLL LASGuidH LASGuid_Create() {
1530
 
    liblas::guid random;
1531
 
    try {
1532
 
        random = liblas::guid::create();
1533
 
        return (LASGuidH) new liblas::guid(random);
1534
 
    }
1535
 
    catch (std::exception const& e) {
1536
 
        LASError_PushError(LE_Failure, e.what(), "LASGuid_Create");
1537
 
        return NULL;
1538
 
    }
1539
 
}
1540
 
 
1541
 
LAS_DLL LASGuidH LASGuid_CreateFromString(const char* string) {
1542
 
    VALIDATE_LAS_POINTER1(string, "LASGuid_CreateFromString", NULL);    
1543
 
    liblas::guid id;
1544
 
    try {
1545
 
        id = liblas::guid::guid(string);
1546
 
        return (LASGuidH) new liblas::guid(id);
1547
 
    }
1548
 
    catch (std::exception const& e) {
1549
 
        LASError_PushError(LE_Failure, e.what(), "LASGuid_CreateFromString");
1550
 
        return NULL;
1551
 
    }
1552
 
}
1553
 
 
1554
 
LAS_DLL void LASGuid_Destroy(LASGuidH hId) {
1555
 
    VALIDATE_LAS_POINTER0(hId, "LASGuid_Destroy");
1556
 
    delete (liblas::guid*) hId;
1557
 
    hId = NULL;
1558
 
}
1559
 
 
1560
 
LAS_DLL int LASGuid_Equals(LASGuidH hId1, LASGuidH hId2) {
1561
 
    VALIDATE_LAS_POINTER1(hId1, "LASGuid_Equals", LE_Failure);
1562
 
    VALIDATE_LAS_POINTER1(hId2, "LASGuid_Equals", LE_Failure);
1563
 
 
1564
 
    liblas::guid* id1 = (liblas::guid*)hId1;
1565
 
    liblas::guid* id2 = (liblas::guid*)hId2;
1566
 
    try {
1567
 
 
1568
 
        return( *id1 == *id2);
1569
 
    }
1570
 
    catch (std::exception const& e) {
1571
 
        LASError_PushError(LE_Failure, e.what(), "LASGuid_Equals");
1572
 
        return LE_Failure;
1573
 
    }
1574
 
}
1575
 
 
1576
 
LAS_DLL char* LASGuid_AsString(LASGuidH hId) {
1577
 
    VALIDATE_LAS_POINTER1(hId, "LASGuid_AsString", 0);
1578
 
    liblas::guid* id= (liblas::guid*)hId;
1579
 
    return strdup(id->to_string().c_str());
1580
 
}
1581
 
 
1582
 
 
1583
 
 
1584
 
LAS_DLL LASColorH LASColor_Create(void) {
1585
 
    return (LASColorH) new LASColor();
1586
 
}
1587
 
 
1588
 
LAS_DLL void LASColor_Destroy(LASColorH hColor){
1589
 
    VALIDATE_LAS_POINTER0(hColor, "LASColor_Destroy");
1590
 
    delete (LASColor*)hColor;
1591
 
    hColor = NULL;
1592
 
}
1593
 
 
1594
 
LAS_DLL LASErrorEnum LASColor_SetRed(LASColorH hColor, liblas::uint16_t value) {
1595
 
    
1596
 
    VALIDATE_LAS_POINTER1(hColor, "LASColor_SetRed", LE_Failure);
1597
 
 
1598
 
    try {
1599
 
        LASColor* color = ((LASColor*) hColor);
1600
 
        color->SetRed(value);
1601
 
    }
1602
 
    catch (std::exception const& e) {
1603
 
        LASError_PushError(LE_Failure, e.what(), "LASColor_SetRed");
1604
 
        return LE_Failure;
1605
 
    }
1606
 
 
1607
 
    return LE_None;
1608
 
}
1609
 
 
1610
 
LAS_DLL liblas::uint16_t LASColor_GetRed(LASColorH hColor) {
1611
 
    
1612
 
    VALIDATE_LAS_POINTER1(hColor, "LASColor_GetRed", 0);
1613
 
    
1614
 
    liblas::uint16_t value = ((LASColor*) hColor)->GetRed();
1615
 
    return value;
1616
 
}
1617
 
 
1618
 
LAS_DLL LASErrorEnum LASColor_SetBlue(LASColorH hColor, liblas::uint16_t value) {
1619
 
    
1620
 
    VALIDATE_LAS_POINTER1(hColor, "LASColor_SetBlue", LE_Failure);
1621
 
 
1622
 
    try {
1623
 
        LASColor* color = ((LASColor*) hColor);
1624
 
        color->SetBlue(value);
1625
 
    }
1626
 
    catch (std::exception const& e) {
1627
 
        LASError_PushError(LE_Failure, e.what(), "LASColor_SetBlue");
1628
 
        return LE_Failure;
1629
 
    }
1630
 
 
1631
 
    return LE_None;
1632
 
}
1633
 
 
1634
 
LAS_DLL liblas::uint16_t LASColor_GetBlue(LASColorH hColor) {
1635
 
    
1636
 
    VALIDATE_LAS_POINTER1(hColor, "LASColor_GetBlue", 0);
1637
 
    
1638
 
    liblas::uint16_t value = ((LASColor*) hColor)->GetBlue();
1639
 
    return value;
1640
 
}
1641
 
 
1642
 
LAS_DLL LASErrorEnum LASColor_SetGreen(LASColorH hColor, liblas::uint16_t value) {
1643
 
    
1644
 
    VALIDATE_LAS_POINTER1(hColor, "LASColor_SetGreen", LE_Failure);
1645
 
 
1646
 
    try {
1647
 
        LASColor* color = ((LASColor*) hColor);
1648
 
        color->SetGreen(value);
1649
 
    }
1650
 
    catch (std::exception const& e) {
1651
 
        LASError_PushError(LE_Failure, e.what(), "LASColor_SetGreen");
1652
 
        return LE_Failure;
1653
 
    }
1654
 
 
1655
 
    return LE_None;
1656
 
}
1657
 
 
1658
 
LAS_DLL liblas::uint16_t LASColor_GetGreen(LASColorH hColor) {
1659
 
    
1660
 
    VALIDATE_LAS_POINTER1(hColor, "LASColor_GetGreen", 0);
1661
 
    
1662
 
    liblas::uint16_t value = ((LASColor*) hColor)->GetGreen();
1663
 
    return value;
1664
 
}
1665
 
 
1666
 
LAS_DLL LASColorH LASPoint_GetColor(const LASPointH hPoint) {
1667
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetColor", 0);
1668
 
    
1669
 
    LASColor color = ((LASPoint*) hPoint)->GetColor();
1670
 
    return (LASColorH) new LASColor(color);
1671
 
}
1672
 
 
1673
 
LAS_DLL LASErrorEnum LASPoint_SetColor(LASPointH hPoint, const LASColorH hColor) {
1674
 
    
1675
 
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetColor", LE_Failure);
1676
 
    VALIDATE_LAS_POINTER1(hColor, "LASPoint_SetColor", LE_Failure);
1677
 
 
1678
 
    try {
1679
 
        ((LASPoint*) hPoint)->SetColor(*((LASColor*)hColor));
1680
 
    }
1681
 
    catch (std::exception const& e) {
1682
 
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetColor");
1683
 
        return LE_Failure;
1684
 
    }
1685
 
 
1686
 
    return LE_None;
1687
 
}
1688
 
 
1689
 
LAS_DLL LASSRSH LASSRS_Create(void) {
1690
 
    return (LASSRSH) new LASSpatialReference();
1691
 
}
1692
 
 
1693
 
LAS_DLL void LASSRS_Destroy(LASSRSH hSRS){
1694
 
    VALIDATE_LAS_POINTER0(hSRS, "LASSRS_Destroy");
1695
 
    delete (LASSpatialReference*)hSRS;
1696
 
    hSRS = NULL;
1697
 
}
1698
 
 
1699
 
LAS_DLL const GTIF* LASSRS_GetGTIF(LASSRSH hSRS) {
1700
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetGTIF", 0);
1701
 
    
1702
 
    try {
1703
 
        return ((LASSpatialReference*) hSRS)->GetGTIF();
1704
 
    }
1705
 
    catch (std::exception const& e) {
1706
 
        LASError_PushError(LE_Failure, e.what(), "LASSRS_GetGTIF");
1707
 
        return 0;
1708
 
    }
1709
 
}
1710
 
 
1711
 
LAS_DLL LASErrorEnum LASSRS_SetGTIF(LASSRSH hSRS, const GTIF* gtiff, const ST_TIFF* tiff)
1712
 
{
1713
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_SetGTIF", LE_Failure);
1714
 
    VALIDATE_LAS_POINTER1(gtiff, "LASSRS_SetGTIF", LE_Failure);
1715
 
    VALIDATE_LAS_POINTER1(tiff, "LASSRS_SetGTIF", LE_Failure);
1716
 
    try {
1717
 
        ((LASSpatialReference*) hSRS)->SetGTIF(gtiff, tiff);
1718
 
    }
1719
 
    catch (std::exception const& e) {
1720
 
        LASError_PushError(LE_Failure, e.what(), "LASSRS_SetGTIF");
1721
 
        return LE_Failure;
1722
 
    }
1723
 
 
1724
 
    return LE_None;    
1725
 
}
1726
 
LAS_DLL char* LASSRS_GetProj4(LASSRSH hSRS) 
1727
 
{
1728
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetProj4", NULL);
1729
 
    LASSpatialReference* srs = (LASSpatialReference*)hSRS;
1730
 
 
1731
 
    return strdup((srs)->GetProj4().c_str());
1732
 
    
1733
 
}
1734
 
 
1735
 
LAS_DLL LASErrorEnum LASSRS_SetProj4(LASSRSH hSRS, const char* value)
1736
 
{
1737
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_SetProj4", LE_Failure);
1738
 
    VALIDATE_LAS_POINTER1(value, "LASSRS_SetProj4", LE_Failure);
1739
 
 
1740
 
    try {
1741
 
         ((LASSpatialReference*) hSRS)->SetProj4(value);
1742
 
    }
1743
 
    catch (std::exception const& e) {
1744
 
        LASError_PushError(LE_Failure, e.what(), "LASSRS_SetProj4");
1745
 
        return LE_Failure;
1746
 
    }
1747
 
 
1748
 
    return LE_None;
1749
 
}
1750
 
 
1751
 
LAS_DLL char* LASSRS_GetWKT(LASSRSH hSRS) 
1752
 
{
1753
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetWKT", NULL);
1754
 
    LASSpatialReference* srs = (LASSpatialReference*)hSRS;
1755
 
 
1756
 
    return strdup((srs)->GetWKT().c_str());
1757
 
    
1758
 
}
1759
 
 
1760
 
LAS_DLL LASErrorEnum LASSRS_SetWKT(LASSRSH hSRS, const char* value)
1761
 
{
1762
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_SetWKT", LE_Failure);
1763
 
    VALIDATE_LAS_POINTER1(value, "LASSRS_SetWKT", LE_Failure);
1764
 
 
1765
 
    try {
1766
 
         ((LASSpatialReference*) hSRS)->SetWKT(value);
1767
 
    }
1768
 
    catch (std::exception const& e) {
1769
 
        LASError_PushError(LE_Failure, e.what(), "LASSRS_SetWKT");
1770
 
        return LE_Failure;
1771
 
    }
1772
 
 
1773
 
    return LE_None;
1774
 
}
1775
 
 
1776
 
LAS_DLL LASErrorEnum LASSRS_AddVLR(LASSRSH hSRS, const LASVLRH hVLR) {
1777
 
    
1778
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_AddVLR", LE_Failure);
1779
 
    VALIDATE_LAS_POINTER1(hVLR, "LASSRS_AddVLR", LE_Failure);
1780
 
 
1781
 
    try {
1782
 
        ((LASSpatialReference*) hSRS)->AddVLR(*((LASVariableRecord*)hVLR));
1783
 
    }
1784
 
    catch (std::exception const& e) {
1785
 
        LASError_PushError(LE_Failure, e.what(), "LASSRS_AddVLR");
1786
 
        return LE_Failure;
1787
 
    }
1788
 
 
1789
 
 
1790
 
    return LE_None;
1791
 
}
1792
 
 
1793
 
LAS_DLL LASVLRH LASSRS_GetVLR(const LASSRSH hSRS, liblas::uint32_t i) {
1794
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetVLR", 0);
1795
 
    
1796
 
    LASVariableRecord vlr = ((LASSpatialReference*) hSRS)->GetVLRs()[i];
1797
 
    return (LASVLRH) new LASVariableRecord(vlr);
1798
 
}
1799
 
 
1800
 
LAS_DLL liblas::uint32_t LASSRS_GetVLRCount(const LASSRSH hSRS) {
1801
 
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetVLR", 0);
1802
 
    
1803
 
    liblas::uint32_t size = ((LASSpatialReference*) hSRS)->GetVLRs().size();
1804
 
    return size;
1805
 
}
1806
 
 
1807
 
LAS_DLL LASErrorEnum LASHeader_SetSRS(LASHeaderH hHeader, const LASSRSH hSRS) {
1808
 
    
1809
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetSRS", LE_Failure);
1810
 
    VALIDATE_LAS_POINTER1(hSRS, "LASHeader_SetSRS", LE_Failure);
1811
 
 
1812
 
    try {
1813
 
        ((LASHeader*) hHeader)->SetSRS(*((LASSpatialReference*)hSRS));
1814
 
    }
1815
 
    catch (std::exception const& e) {
1816
 
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetSRS");
1817
 
        return LE_Failure;
1818
 
    }
1819
 
 
1820
 
 
1821
 
    return LE_None;
1822
 
}
1823
 
 
1824
 
LAS_DLL LASSRSH LASHeader_GetSRS(const LASHeaderH hHeader) {
1825
 
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetSRS", 0);
1826
 
    
1827
 
    LASSpatialReference srs = ((LASHeader*) hHeader)->GetSRS();
1828
 
    return (LASSRSH) new LASSpatialReference(srs);
1829
 
}
1830
 
 
1831
 
 
1832
 
LAS_DLL void LASString_Free(char* string) {
1833
 
    if (string)
1834
 
        free(string);
1835
 
}
1836
 
 
1837
 
LAS_C_END
1838
 
 
1839
 
#ifdef _MSC_VER
1840
 
# pragma warning(default: 4127) // enable warning C4127: conditional expression is constant
1841
 
#endif