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

« back to all changes in this revision

Viewing changes to src/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
#ifdef HAVE_LIBGEOTIFF
 
45
// Supress inclusion of cpl_serv.h per #194, perhaps remove one day
 
46
// when libgeotiff 1.4.0+ is widely used
 
47
#define CPL_SERV_H_INCLUDED
 
48
 
 
49
#include <geotiff.h>
 
50
#include <geo_simpletags.h>
 
51
#include <geo_normalize.h>
 
52
#endif
 
53
 
 
54
#include <liblas/liblas.hpp>
 
55
#include <liblas/detail/reader/reader.hpp>
 
56
#include <liblas/detail/reader/zipreader.hpp>
 
57
#include <liblas/detail/reader/cachedreader.hpp>
 
58
#include <liblas/external/property_tree/xml_parser.hpp>
 
59
 
 
60
typedef struct LASWriterHS *LASWriterH;
 
61
typedef struct LASReaderHS *LASReaderH;
 
62
typedef struct LASPointHS *LASPointH;
 
63
typedef liblas::HeaderPtr* LASHeaderH;
 
64
typedef struct LASGuidHS *LASGuidH;
 
65
typedef struct LASVLRHS *LASVLRH;
 
66
typedef struct LASColorHS *LASColorH;
 
67
typedef struct LASSRSHS *LASSRSH;
 
68
typedef struct LASSchemaHS *LASSchemaH;
 
69
typedef struct LASFilterHS *LASFilterH;
 
70
 
 
71
// boost
 
72
#include <boost/cstdint.hpp>
 
73
// std
 
74
#include <cstdio>
 
75
#include <bitset>
 
76
#include <exception>
 
77
#include <fstream>
 
78
#include <iostream>
 
79
#include <map>
 
80
#include <sstream> // std::stringstream
 
81
#include <string>
 
82
#include <stack>
 
83
#include <typeinfo>
 
84
#include <vector>
 
85
 
 
86
using namespace liblas;
 
87
 
 
88
#ifdef _WIN32
 
89
#define compare_no_case(a,b,n)  _strnicmp( (a), (b), (n) )
 
90
#else
 
91
#define compare_no_case(a,b,n)  strncasecmp( (a), (b), (n) )
 
92
#endif
 
93
 
 
94
#include <boost/lambda/lambda.hpp>
 
95
 
 
96
bool IsReprojectionTransform(liblas::TransformPtr const& p)
 
97
{
 
98
    if (dynamic_cast<liblas::ReprojectionTransform*>(p.get()))
 
99
        return true;
 
100
    return false;
 
101
}
 
102
 
 
103
LAS_C_START
 
104
 
 
105
#ifndef _WIN32
 
106
#include <stdint.h>
 
107
#endif
 
108
 
 
109
 
 
110
// Error stuff
 
111
typedef enum
 
112
{
 
113
    LE_None = 0,
 
114
    LE_Debug = 1,
 
115
    LE_Warning = 2,
 
116
    LE_Failure = 3,
 
117
    LE_Fatal = 4
 
118
} LASErrorEnum;
 
119
 
 
120
typedef enum
 
121
{
 
122
    LE_Filter_Bounds = 0,
 
123
    LE_Filter_Classification = 1,
 
124
    LE_Filter_Thin = 2,
 
125
    LE_Filter_Return = 3,
 
126
    LE_Filter_Color = 4,
 
127
    LE_Filter_Intensity = 5,
 
128
    LE_Filter_ScanAngleRank = 6,
 
129
    LE_Filter_Time = 7
 
130
} LASFilterEnum;
 
131
 
 
132
typedef enum
 
133
{
 
134
    LE_Transform_Reprojection = 0
 
135
} LASTransformEnum;
 
136
 
 
137
static std::stack<liblas::Error > errors;
 
138
static std::vector<liblas::TransformPtr> transforms;
 
139
static std::vector<liblas::FilterPtr> filters;
 
140
 
 
141
 
 
142
static std::map<liblas::Reader*, std::istream*> readers;
 
143
static std::map<liblas::Writer*, std::ostream*> writers;
 
144
 
 
145
#ifdef _MSC_VER
 
146
# pragma warning(disable: 4127) // warning C4127: conditional expression is constant
 
147
# pragma warning(disable: 4702)  // unreachable code
 
148
#endif
 
149
 
 
150
#define VALIDATE_LAS_POINTER0(ptr, func) \
 
151
   do { if( NULL == ptr ) { \
 
152
        LASErrorEnum const ret = LE_Failure; \
 
153
        std::ostringstream msg; \
 
154
        msg << "Pointer \'" << #ptr << "\' is NULL in \'" << (func) <<"\'."; \
 
155
        std::string message(msg.str()); \
 
156
        LASError_PushError( ret, message.c_str(), (func)); \
 
157
        return; \
 
158
   }} while(0)
 
159
 
 
160
#define VALIDATE_LAS_POINTER1(ptr, func, rc) \
 
161
   do { if( NULL == ptr ) { \
 
162
        LASErrorEnum const ret = LE_Failure; \
 
163
        std::ostringstream msg; \
 
164
        msg << "Pointer \'" << #ptr << "\' is NULL in \'" << (func) <<"\'."; \
 
165
        std::string message(msg.str()); \
 
166
        LASError_PushError( ret, message.c_str(), (func)); \
 
167
        return (rc); \
 
168
   }} while(0)
 
169
 
 
170
LAS_DLL int LAS_IsGDALEnabled(void) {
 
171
    return IsGDALEnabled();
 
172
}
 
173
 
 
174
LAS_DLL int LAS_IsLibGeoTIFFEnabled(void) {
 
175
    return IsLibGeoTIFFEnabled();
 
176
}
 
177
 
 
178
LAS_DLL void LASError_Reset(void) {
 
179
    if (errors.empty()) return;
 
180
    for (std::stack<liblas::Error >::size_type i=0;i<errors.size();i++) errors.pop();
 
181
}
 
182
 
 
183
LAS_DLL void LASError_Pop(void) {
 
184
    if (errors.empty()) return;
 
185
    errors.pop();
 
186
}
 
187
 
 
188
LAS_DLL int LASError_GetLastErrorNum(void){
 
189
    if (errors.empty())
 
190
        return 0;
 
191
    else {
 
192
        liblas::Error err = errors.top();
 
193
        return err.GetCode();
 
194
    }
 
195
}
 
196
 
 
197
LAS_DLL char* LASError_GetLastErrorMsg(void){
 
198
    if (errors.empty()) 
 
199
        return NULL;
 
200
    else {
 
201
        liblas::Error err = errors.top();
 
202
        return LASCopyString(err.GetMessage().c_str());
 
203
    }
 
204
}
 
205
 
 
206
LAS_DLL char* LASError_GetLastErrorMethod(void){
 
207
    if (errors.empty()) 
 
208
        return NULL;
 
209
    else {
 
210
        liblas::Error err = errors.top();
 
211
        return LASCopyString(err.GetMethod().c_str());
 
212
    }
 
213
}
 
214
 
 
215
LAS_DLL void LASError_PushError(int code, const char *message, const char *method) {
 
216
    liblas::Error err = liblas::Error(code, std::string(message), std::string(method));
 
217
    errors.push(err);
 
218
}
 
219
 
 
220
LAS_DLL int LASError_GetErrorCount(void) {
 
221
    return static_cast<int>(errors.size());
 
222
}
 
223
 
 
224
 
 
225
 
 
226
LAS_DLL LASReaderH LASReader_Create(const char* filename) 
 
227
 
 
228
{
 
229
    VALIDATE_LAS_POINTER1(filename, "LASReader_Create", NULL);
 
230
    
 
231
    std::istream* istrm = NULL;
 
232
    try {
 
233
        istrm = liblas::Open(filename, std::ios::in | std::ios::binary);
 
234
    } catch (std::exception const& e)
 
235
    {
 
236
        if (istrm)
 
237
            delete istrm;
 
238
        LASError_PushError(LE_Failure, e.what(), "LASReader_Create");
 
239
        return NULL;
 
240
    }
 
241
 
 
242
    try {
 
243
        liblas::ReaderFactory f;
 
244
        liblas::Reader* reader = new liblas::Reader(f.CreateWithStream(*istrm));
 
245
        readers.insert(std::pair<liblas::Reader*, std::istream*>(reader, istrm));
 
246
        return (LASReaderH) reader;
 
247
    } catch (std::exception const& e)
 
248
    {
 
249
        LASError_PushError(LE_Failure, e.what(), "LASReader_Create");
 
250
        return NULL;
 
251
    }
 
252
 
 
253
 
 
254
 
 
255
}
 
256
 
 
257
LAS_DLL LASReaderH LASReader_CreateWithHeader(  const char* filename,
 
258
                                                LASHeaderH hHeader) 
 
259
 
 
260
{
 
261
    VALIDATE_LAS_POINTER1(filename, "LASReader_CreateWithHeader", NULL);
 
262
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASReader_CreateWithHeader", NULL);
 
263
    
 
264
    std::istream* istrm = NULL;
 
265
    liblas::ReaderFactory f;
 
266
    try {
 
267
        istrm = liblas::Open(filename, std::ios::in | std::ios::binary);
 
268
    } catch (std::exception const& e)
 
269
    {
 
270
        if (istrm) delete istrm;
 
271
        LASError_PushError(LE_Failure, e.what(), "LASReader_Create");
 
272
        return NULL;
 
273
    }
 
274
 
 
275
    try {
 
276
 
 
277
        liblas::Reader* reader = new liblas::Reader(f.CreateWithStream(*istrm));
 
278
        
 
279
        liblas::Header const& current_header = reader->GetHeader();
 
280
        
 
281
        // If the original data were compressed, we need to override whatever value
 
282
        // our incoming header has for that value
 
283
        liblas::HeaderPtr* header = ((liblas::HeaderPtr*) hHeader);
 
284
        if (current_header.Compressed())
 
285
        {
 
286
            header->get()->SetCompressed(true);
 
287
        }
 
288
        reader->SetHeader(*header->get());
 
289
        readers.insert(std::pair<liblas::Reader*, std::istream*>(reader, istrm));
 
290
        return (LASReaderH) reader;
 
291
 
 
292
    
 
293
    } catch (std::exception const& e)
 
294
    {
 
295
        LASError_PushError(LE_Failure, e.what(), "LASReader_Create");
 
296
        return NULL;
 
297
    }
 
298
 
 
299
 
 
300
}
 
301
 
 
302
LAS_DLL void LASReader_SetHeader(  LASReaderH hReader, const LASHeaderH hHeader) 
 
303
 
 
304
{
 
305
    VALIDATE_LAS_POINTER0(hReader, "LASReader_SetHeader");
 
306
    VALIDATE_LAS_POINTER0(hHeader, "LASReader_SetHeader");
 
307
 
 
308
    liblas::Reader* reader = (liblas::Reader*)hReader;
 
309
    liblas::HeaderPtr* header = (liblas::HeaderPtr*)hHeader;
 
310
    if (header->get())
 
311
        reader->SetHeader(*header->get());
 
312
}
 
313
 
 
314
LAS_DLL void LASReader_Destroy(LASReaderH hReader)
 
315
{
 
316
    VALIDATE_LAS_POINTER0(hReader, "LASReader_Destroy");
 
317
 
 
318
    try { 
 
319
        liblas::Reader* reader = (liblas::Reader*)hReader;
 
320
        
 
321
        std::map<liblas::Reader*, std::istream*>::iterator it = readers.find(reader);
 
322
        if (it == readers.end())
 
323
        {
 
324
            LASError_PushError(LE_Failure, "Unable to find reader stream", "LASReader_Destroy");
 
325
            return;            
 
326
        }
 
327
        std::istream* istrm = it->second;
 
328
 
 
329
        delete reader;
 
330
        hReader = NULL;
 
331
    
 
332
        if ( istrm == NULL )
 
333
        {
 
334
            LASError_PushError(LE_Failure, "Got 99 problems, but the stream ain't one", "LASReader_Destroy");
 
335
            return;            
 
336
        }
 
337
        
 
338
        liblas::Cleanup(istrm);
 
339
            
 
340
        readers.erase(reader);
 
341
        istrm = NULL;
 
342
  
 
343
        }  catch (std::runtime_error const& e/* e */) 
 
344
        {
 
345
            LASError_PushError(LE_Failure, e.what(), "LASReader_Destroy");
 
346
            return;
 
347
        }
 
348
 
 
349
 
 
350
    hReader = NULL;
 
351
}
 
352
 
 
353
 
 
354
 
 
355
LAS_DLL const LASPointH LASReader_GetNextPoint(const LASReaderH hReader)
 
356
{
 
357
    VALIDATE_LAS_POINTER1(hReader, "LASReader_GetNextPoint", NULL);
 
358
 
 
359
    try {
 
360
        liblas::Reader *reader = ((liblas::Reader*) hReader);
 
361
        if (reader->ReadNextPoint()) 
 
362
            // return (LASPointH) new LASPoint(reader->GetPoint());
 
363
            return (LASPointH) &(reader->GetPoint());
 
364
        else 
 
365
            return NULL;
 
366
    } catch (invalid_point_data const& e /*e */) {
 
367
        LASError_PushError(LE_Failure, e.what(), "LASReader_GetNextPoint Invalid Point");
 
368
    } catch (std::exception const& e)
 
369
    {
 
370
        LASError_PushError(LE_Failure, e.what(), "LASReader_GetNextPoint");
 
371
    }
 
372
 
 
373
    return NULL;
 
374
}
 
375
 
 
376
LAS_DLL const LASPointH LASReader_GetPointAt(const LASReaderH hReader, boost::uint32_t position)
 
377
{
 
378
    VALIDATE_LAS_POINTER1(hReader, "LASReader_GetPointAt", NULL);
 
379
 
 
380
    try {
 
381
        liblas::Reader *reader = ((liblas::Reader*) hReader);
 
382
        if (reader->ReadPointAt((std::size_t) position)) 
 
383
            // return (LASPointH) new LASPoint(reader->GetPoint());
 
384
            return (LASPointH) &(reader->GetPoint());
 
385
        else 
 
386
            return NULL;
 
387
    } catch (invalid_point_data const& e /*e */) {
 
388
        LASError_PushError(LE_Failure, e.what(), "LASReader_GetPointAt Invalid Point");
 
389
    } catch (std::exception const& e)
 
390
    {
 
391
        LASError_PushError(LE_Failure, e.what(), "LASReader_GetPointAt");
 
392
    }
 
393
 
 
394
    return NULL;
 
395
 
 
396
}
 
397
 
 
398
LAS_DLL LASErrorEnum LASReader_Seek(LASReaderH hReader, boost::uint32_t position)
 
399
{
 
400
    VALIDATE_LAS_POINTER1(hReader, "LASReader_Seek", LE_None);
 
401
 
 
402
    try {
 
403
        liblas::Reader *reader = ((liblas::Reader*) hReader);
 
404
        if (reader->Seek((std::size_t) position)) 
 
405
            return LE_None;
 
406
        else 
 
407
            return LE_Failure;
 
408
    } catch (invalid_point_data const& e /*e */) {
 
409
        LASError_PushError(LE_Failure, e.what(), "LASReader_Seek Invalid location");
 
410
    } catch (std::exception const& e)
 
411
    {
 
412
        LASError_PushError(LE_Failure, e.what(), "LASReader_Seek");
 
413
    }
 
414
 
 
415
    return LE_None;
 
416
 
 
417
}
 
418
 
 
419
LAS_DLL char* LASReader_GetSummaryXML(const LASReaderH hReader)
 
420
{
 
421
 
 
422
    VALIDATE_LAS_POINTER1(hReader, "LASReader_GetSummaryXML", NULL);
 
423
    liblas::Reader* r = (liblas::Reader*)hReader;
 
424
    liblas::Summary s;
 
425
 
 
426
    r->Reset();
 
427
    bool read = r->ReadNextPoint();
 
428
    if (!read)
 
429
    {
 
430
        LASError_PushError(LE_Failure, "Unable to read point", "LASReader_GetSummaryXML");
 
431
        return NULL;
 
432
    }
 
433
        
 
434
    while (read) 
 
435
    {
 
436
        liblas::Point const& p = r->GetPoint();
 
437
        s.AddPoint(p);
 
438
        read = r->ReadNextPoint();
 
439
    }
 
440
 
 
441
    r->Reset();
 
442
    
 
443
    std::ostringstream oss;
 
444
    
 
445
    liblas::property_tree::write_xml(oss, s.GetPTree());
 
446
    return LASCopyString(oss.str().c_str());
 
447
        
 
448
}
 
449
 
 
450
LAS_DLL LASErrorEnum LASReader_SetInputSRS(LASReaderH hReader, const LASSRSH hSRS) {
 
451
    
 
452
    VALIDATE_LAS_POINTER1(hReader, "LASReader_SetInputSRS", LE_Failure);
 
453
    VALIDATE_LAS_POINTER1(hSRS, "LASReader_SetInputSRS", LE_Failure);
 
454
 
 
455
    try {
 
456
        liblas::Reader* reader = ((liblas::Reader*) hReader);
 
457
        liblas::Header h = reader->GetHeader();
 
458
        liblas::SpatialReference* ref = ((liblas::SpatialReference*) hSRS);
 
459
        h.SetSRS(*ref);
 
460
        reader->SetHeader(h);
 
461
    }
 
462
    catch (std::exception const& e) {
 
463
        LASError_PushError(LE_Failure, e.what(), "LASReader_SetInputSRS");
 
464
        return LE_Failure;
 
465
    }
 
466
 
 
467
    return LE_None;
 
468
}
 
469
 
 
470
 
 
471
LAS_DLL LASHeaderH LASReader_GetHeader(const LASReaderH hReader)
 
472
{
 
473
    VALIDATE_LAS_POINTER1(hReader, "LASReader_GetHeader", new liblas::HeaderPtr());
 
474
 
 
475
    liblas::Header header = ((liblas::Reader*) hReader)->GetHeader();
 
476
    return (LASHeaderH) new liblas::HeaderPtr(new liblas::Header(header));
 
477
}
 
478
 
 
479
 
 
480
 
 
481
 
 
482
 
 
483
LAS_DLL LASErrorEnum LASReader_SetOutputSRS(LASReaderH hReader, const LASSRSH hSRS) {
 
484
    
 
485
    VALIDATE_LAS_POINTER1(hReader, "LASReader_SetOutputSRS", LE_Failure);
 
486
    VALIDATE_LAS_POINTER1(hSRS, "LASReader_SetOutputSRS", LE_Failure);
 
487
 
 
488
    try {
 
489
        liblas::Reader* reader = ((liblas::Reader*) hReader);
 
490
        liblas::Header const& h = reader->GetHeader();
 
491
        liblas::SpatialReference in_ref = h.GetSRS();
 
492
        liblas::SpatialReference* out_ref = ((liblas::SpatialReference*) hSRS);
 
493
        std::vector<liblas::TransformPtr> transforms = reader->GetTransforms();
 
494
        
 
495
        transforms.erase( std::remove_if( transforms.begin(), 
 
496
                                  transforms.end(),
 
497
                                  boost::bind( &IsReprojectionTransform, _1 ) ),
 
498
                  transforms.end());
 
499
        
 
500
        liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, *out_ref, &h));
 
501
        if (transforms.size())
 
502
            transforms.insert(transforms.begin(), srs_transform);
 
503
        else
 
504
            transforms.push_back(srs_transform);
 
505
        reader->SetTransforms(transforms);
 
506
        
 
507
        // ((liblas::Reader*) hReader)->SetOutputSRS(*((liblas::SpatialReference*)hSRS));
 
508
    }
 
509
    catch (std::exception const& e) {
 
510
        LASError_PushError(LE_Failure, e.what(), "LASReader_SetOutputSRS");
 
511
        return LE_Failure;
 
512
    }
 
513
 
 
514
    return LE_None;
 
515
}
 
516
 
 
517
LAS_DLL LASErrorEnum LASReader_SetSRS(LASReaderH hReader, const LASSRSH hSRS) {
 
518
    
 
519
    VALIDATE_LAS_POINTER1(hReader, "LASReader_SetSRS", LE_Failure);
 
520
    VALIDATE_LAS_POINTER1(hSRS, "LASReader_SetSRS", LE_Failure);
 
521
 
 
522
    return LASReader_SetOutputSRS(hReader, hSRS);
 
523
}
 
524
 
 
525
LAS_DLL LASHeaderH LASHeader_Create(void) {
 
526
        return (LASHeaderH) new liblas::HeaderPtr(new liblas::Header());
 
527
}
 
528
 
 
529
LAS_DLL LASPointH LASPoint_Create(void) {
 
530
        return (LASPointH) new liblas::Point();
 
531
}
 
532
 
 
533
LAS_DLL LASPointH LASPoint_Copy(const LASPointH hPoint) {
 
534
        return (LASPointH) new liblas::Point(*((liblas::Point*) hPoint));
 
535
}
 
536
 
 
537
LAS_DLL LASHeaderH LASPoint_GetHeader(const LASPointH hPoint)
 
538
{
 
539
    VALIDATE_LAS_POINTER1(hPoint    , "LASPoint_GetHeader", new liblas::HeaderPtr());
 
540
 
 
541
    liblas::Point const& p= *((liblas::Point*) hPoint);
 
542
    liblas::Header const* h = p.GetHeader();
 
543
    return (LASHeaderH) new liblas::HeaderPtr(new liblas::Header(*h));
 
544
        
 
545
}
 
546
 
 
547
LAS_DLL void LASPoint_SetHeader( LASPointH hPoint, const LASHeaderH hHeader) 
 
548
 
 
549
{
 
550
    VALIDATE_LAS_POINTER0(hPoint, "LASPoint_SetHeader");
 
551
    VALIDATE_LAS_POINTER0(hHeader, "LASPoint_SetHeader");
 
552
 
 
553
    liblas::Point* point = (liblas::Point*)hPoint;
 
554
    liblas::HeaderPtr h = (liblas::HeaderPtr)*hHeader;
 
555
    liblas::Header const& header = *h;
 
556
    point->SetHeader(&header);
 
557
}
 
558
 
 
559
LAS_DLL LASErrorEnum LASPoint_SetData(LASPointH hPoint, unsigned char* data) {
 
560
    
 
561
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetData", LE_Failure);
 
562
    VALIDATE_LAS_POINTER1(data, "LASPoint_SetData", LE_Failure);
 
563
    
 
564
    try {
 
565
        liblas::Point* p = ((liblas::Point*) hPoint);
 
566
        boost::uint16_t size = 0;
 
567
 
 
568
        liblas::Header const* h = p->GetHeader();
 
569
        size = h->GetDataRecordLength();
 
570
        
 
571
        std::vector<boost::uint8_t> & d = p->GetData();
 
572
        if (d.size() != size)
 
573
        {
 
574
            d.resize(size);
 
575
            d.assign(static_cast<boost::uint32_t>(0), d.size());
 
576
        }
 
577
                
 
578
        for (boost::uint16_t i=0; i < size; i++) {
 
579
            d[i] = data[i];
 
580
        }
 
581
    }
 
582
    catch (std::exception const& e) {
 
583
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetData");
 
584
        return LE_Failure;
 
585
    }
 
586
 
 
587
 
 
588
    return LE_None;
 
589
}
 
590
 
 
591
LAS_DLL LASErrorEnum LASPoint_GetData( const LASPointH hPoint, boost::uint8_t* data) {
 
592
    
 
593
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetData", LE_Failure);
 
594
    VALIDATE_LAS_POINTER1(data, "LASPoint_GetData", LE_Failure);
 
595
    
 
596
    try {
 
597
        liblas::Point* p = ((liblas::Point*) hPoint);
 
598
        boost::uint16_t size = 0;
 
599
        std::vector<boost::uint8_t> const& d = p->GetData();
 
600
 
 
601
        liblas::Header const* h = p->GetHeader();
 
602
        size = h->GetDataRecordLength();
 
603
 
 
604
        for (boost::uint16_t i=0; i < size; i++) {
 
605
            data[i] = d[i];
 
606
        }
 
607
    }
 
608
    catch (std::exception const& e) {
 
609
        LASError_PushError(LE_Failure, e.what(), "LASPoint_GetData");
 
610
        return LE_Failure;
 
611
    }
 
612
 
 
613
 
 
614
    return LE_None;
 
615
}
 
616
 
 
617
 
 
618
LAS_DLL void LASPoint_Destroy(LASPointH hPoint) {
 
619
    VALIDATE_LAS_POINTER0(hPoint, "LASPoint_Destroy");
 
620
    delete (liblas::Point*) hPoint;
 
621
    hPoint = NULL;
 
622
}
 
623
 
 
624
LAS_DLL double LASPoint_GetX(const LASPointH hPoint) {
 
625
 
 
626
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetX", 0.0);
 
627
    
 
628
    double value = ((liblas::Point*) hPoint)->GetX();
 
629
    return value;
 
630
}
 
631
 
 
632
LAS_DLL LASErrorEnum LASPoint_SetX(LASPointH hPoint, double value) {
 
633
 
 
634
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetX", LE_Failure);
 
635
 
 
636
    try {
 
637
            ((liblas::Point*) hPoint)->SetX(value);
 
638
    } catch (std::exception const& e)
 
639
    {
 
640
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetX");
 
641
        return LE_Failure;
 
642
    }
 
643
 
 
644
    return LE_None;
 
645
 
 
646
}
 
647
 
 
648
LAS_DLL boost::int32_t LASPoint_GetRawX(const LASPointH hPoint) {
 
649
 
 
650
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetRawX", 0);
 
651
    
 
652
    long value = static_cast<long>(((liblas::Point*) hPoint)->GetRawX());
 
653
    return value;
 
654
}
 
655
 
 
656
LAS_DLL LASErrorEnum LASPoint_SetRawX(LASPointH hPoint, boost::int32_t value) {
 
657
 
 
658
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetRawX", LE_Failure);
 
659
 
 
660
    try {
 
661
            ((liblas::Point*) hPoint)->SetRawX(value);
 
662
    } catch (std::exception const& e)
 
663
    {
 
664
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetRawX");
 
665
        return LE_Failure;
 
666
    }
 
667
 
 
668
    return LE_None;
 
669
 
 
670
}
 
671
 
 
672
LAS_DLL double LASPoint_GetY(const LASPointH hPoint) {
 
673
    
 
674
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetY", 0.0);
 
675
    
 
676
    double value = ((liblas::Point*) hPoint)->GetY();
 
677
    return value;
 
678
}
 
679
 
 
680
LAS_DLL LASErrorEnum LASPoint_SetY(LASPointH hPoint, double value) {
 
681
 
 
682
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetY", LE_Failure);
 
683
 
 
684
    try {
 
685
            ((liblas::Point*) hPoint)->SetY(value);
 
686
    } catch (std::exception const& e)
 
687
    {
 
688
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetY");
 
689
        return LE_Failure;
 
690
    }
 
691
 
 
692
    return LE_None;
 
693
 
 
694
}
 
695
 
 
696
LAS_DLL boost::int32_t LASPoint_GetRawY(const LASPointH hPoint) {
 
697
 
 
698
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetRawY", 0);
 
699
    
 
700
    long value = static_cast<long>(((liblas::Point*) hPoint)->GetRawY());
 
701
    return value;
 
702
}
 
703
 
 
704
LAS_DLL LASErrorEnum LASPoint_SetRawY(LASPointH hPoint, boost::int32_t value) {
 
705
 
 
706
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetRawY", LE_Failure);
 
707
 
 
708
    try {
 
709
            ((liblas::Point*) hPoint)->SetRawY(value);
 
710
    } catch (std::exception const& e)
 
711
    {
 
712
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetRawY");
 
713
        return LE_Failure;
 
714
    }
 
715
 
 
716
    return LE_None;
 
717
 
 
718
}
 
719
LAS_DLL double LASPoint_GetZ(const LASPointH hPoint) {
 
720
    
 
721
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetZ", 0.0);
 
722
    
 
723
    double value = ((liblas::Point*) hPoint)->GetZ();
 
724
    return value;
 
725
}
 
726
 
 
727
LAS_DLL LASErrorEnum LASPoint_SetZ(LASPointH hPoint, double value) {
 
728
 
 
729
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetZ", LE_Failure);
 
730
 
 
731
    try {
 
732
            ((liblas::Point*) hPoint)->SetZ(value);
 
733
    } catch (std::exception const& e)
 
734
    {
 
735
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetZ");
 
736
        return LE_Failure;
 
737
    }
 
738
 
 
739
    return LE_None;
 
740
 
 
741
}
 
742
 
 
743
LAS_DLL boost::int32_t LASPoint_GetRawZ(const LASPointH hPoint) {
 
744
 
 
745
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetRawZ", 0);
 
746
    
 
747
    long value = static_cast<long>(((liblas::Point*) hPoint)->GetRawZ());
 
748
    return value;
 
749
}
 
750
 
 
751
LAS_DLL LASErrorEnum LASPoint_SetRawZ(LASPointH hPoint, boost::int32_t value) {
 
752
 
 
753
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetRawZ", LE_Failure);
 
754
 
 
755
    try {
 
756
            ((liblas::Point*) hPoint)->SetRawZ(value);
 
757
    } catch (std::exception const& e)
 
758
    {
 
759
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetRawZ");
 
760
        return LE_Failure;
 
761
    }
 
762
 
 
763
    return LE_None;
 
764
 
 
765
}
 
766
 
 
767
LAS_DLL boost::uint16_t LASPoint_GetIntensity(const LASPointH hPoint) {
 
768
    
 
769
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetIntensity", 0);
 
770
    
 
771
    boost::uint16_t value = ((liblas::Point*) hPoint)->GetIntensity();
 
772
    return value;
 
773
}
 
774
 
 
775
LAS_DLL LASErrorEnum LASPoint_SetIntensity(LASPointH hPoint, boost::uint16_t value) {
 
776
 
 
777
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetIntensity", LE_Failure);
 
778
 
 
779
    try {
 
780
            ((liblas::Point*) hPoint)->SetIntensity(value);
 
781
    } catch (std::exception const& e)
 
782
    {
 
783
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetIntensity");
 
784
        return LE_Failure;
 
785
    }
 
786
 
 
787
    return LE_None;
 
788
 
 
789
}
 
790
 
 
791
LAS_DLL boost::uint16_t LASPoint_GetReturnNumber(const LASPointH hPoint) {
 
792
    
 
793
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetReturnNumber", 0);
 
794
    
 
795
    boost::uint16_t value = ((liblas::Point*) hPoint)->GetReturnNumber();
 
796
    return value;
 
797
}
 
798
 
 
799
LAS_DLL LASErrorEnum LASPoint_SetReturnNumber(LASPointH hPoint, boost::uint16_t value) {
 
800
 
 
801
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetReturnNumber", LE_Failure);
 
802
 
 
803
    try {
 
804
            ((liblas::Point*) hPoint)->SetReturnNumber(value);
 
805
    } catch (std::exception const& e)
 
806
    {
 
807
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetReturnNumber");
 
808
        return LE_Failure;
 
809
    }
 
810
 
 
811
    return LE_None;
 
812
 
 
813
}
 
814
 
 
815
LAS_DLL boost::uint16_t LASPoint_GetNumberOfReturns(const LASPointH hPoint) {
 
816
    
 
817
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetNumberOfReturns", 0);
 
818
    
 
819
    boost::uint16_t value = ((liblas::Point*) hPoint)->GetNumberOfReturns();
 
820
    return value;
 
821
}
 
822
 
 
823
LAS_DLL LASErrorEnum LASPoint_SetNumberOfReturns(LASPointH hPoint, boost::uint16_t value) {
 
824
 
 
825
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetNumberOfReturns", LE_Failure);
 
826
 
 
827
    try {
 
828
            ((liblas::Point*) hPoint)->SetNumberOfReturns(value);
 
829
    } catch (std::exception const& e)
 
830
    {
 
831
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetNumberOfReturns");
 
832
        return LE_Failure;
 
833
    }
 
834
 
 
835
    return LE_None;
 
836
 
 
837
}
 
838
 
 
839
LAS_DLL boost::uint16_t LASPoint_GetScanDirection(const LASPointH hPoint) {
 
840
    
 
841
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetScanDirection", 0);
 
842
    
 
843
    boost::uint16_t value = ((liblas::Point*) hPoint)->GetScanDirection();
 
844
    return value;
 
845
}
 
846
 
 
847
LAS_DLL LASErrorEnum LASPoint_SetScanDirection(LASPointH hPoint, boost::uint16_t value) {
 
848
 
 
849
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetScanDirection", LE_Failure);
 
850
 
 
851
    try {
 
852
            ((liblas::Point*) hPoint)->SetScanDirection(value);
 
853
    } catch (std::exception const& e)
 
854
    {
 
855
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetScanDirection");
 
856
        return LE_Failure;
 
857
    }
 
858
 
 
859
    return LE_None;
 
860
 
 
861
}
 
862
 
 
863
LAS_DLL boost::uint16_t LASPoint_GetFlightLineEdge(const LASPointH hPoint) {
 
864
    
 
865
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetFlightLineEdge", 0);
 
866
    
 
867
    boost::uint16_t value = ((liblas::Point*) hPoint)->GetFlightLineEdge();
 
868
    return value;
 
869
}
 
870
 
 
871
LAS_DLL LASErrorEnum LASPoint_SetFlightLineEdge(LASPointH hPoint, boost::uint16_t value) {
 
872
 
 
873
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetFlightLineEdge", LE_Failure);
 
874
 
 
875
    try {
 
876
            ((liblas::Point*) hPoint)->SetFlightLineEdge(value);
 
877
    } catch (std::exception const& e)
 
878
    {
 
879
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetFlightLineEdge");
 
880
        return LE_Failure;
 
881
    }
 
882
 
 
883
    return LE_None;
 
884
 
 
885
}
 
886
 
 
887
LAS_DLL boost::uint8_t LASPoint_GetScanFlags(const LASPointH hPoint) {
 
888
    
 
889
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetScanFlags", 0);
 
890
    
 
891
    boost::uint8_t value = ((liblas::Point*) hPoint)->GetScanFlags();
 
892
    return value;
 
893
}
 
894
 
 
895
LAS_DLL LASErrorEnum LASPoint_SetScanFlags(LASPointH hPoint, boost::uint8_t value) {
 
896
 
 
897
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetScanFlags", LE_Failure);
 
898
 
 
899
    try {
 
900
            ((liblas::Point*) hPoint)->SetScanFlags(value);
 
901
    } catch (std::exception const& e)
 
902
    {
 
903
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetScanFlags");
 
904
        return LE_Failure;
 
905
    }
 
906
 
 
907
    return LE_None;
 
908
 
 
909
}
 
910
 
 
911
LAS_DLL boost::uint8_t LASPoint_GetClassification(const LASPointH hPoint) {
 
912
    
 
913
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetClassification", 0);
 
914
 
 
915
    liblas::Classification::bitset_type clsflags(((liblas::Point*) hPoint)->GetClassification());
 
916
    boost::uint8_t value = static_cast<boost::uint8_t>(clsflags.to_ulong());
 
917
    return value;
 
918
}
 
919
 
 
920
LAS_DLL LASErrorEnum LASPoint_SetClassification(LASPointH hPoint, boost::uint8_t value) {
 
921
 
 
922
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetClassification", LE_Failure);
 
923
 
 
924
    try {
 
925
            ((liblas::Point*) hPoint)->SetClassification(value);
 
926
    } catch (std::exception const& e)
 
927
    {
 
928
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetClassification");
 
929
        return LE_Failure;
 
930
    }
 
931
 
 
932
    return LE_None;
 
933
 
 
934
}
 
935
 
 
936
LAS_DLL LASErrorEnum LASPoint_SetTime(LASPointH hPoint, double value) {
 
937
 
 
938
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetTime", LE_Failure);
 
939
 
 
940
    try {
 
941
            ((liblas::Point*) hPoint)->SetTime(value);
 
942
    
 
943
    }
 
944
    catch (std::runtime_error const&) 
 
945
    {
 
946
        // drop the value on the floor.  If the point has a schema that 
 
947
        // doesn't have time, the user needs to change the point's header.
 
948
    }
 
949
    catch (std::exception const& e)
 
950
    {
 
951
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetTime");
 
952
        return LE_Failure;
 
953
    }
 
954
 
 
955
    return LE_None;
 
956
 
 
957
}
 
958
 
 
959
LAS_DLL double LASPoint_GetTime(const LASPointH hPoint) {
 
960
    
 
961
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetTime", 0.0);
 
962
    
 
963
    double value = 0.0;
 
964
    try {
 
965
        value = ((liblas::Point*) hPoint)->GetTime();
 
966
        
 
967
    } catch (std::runtime_error const&) 
 
968
    {
 
969
        
 
970
    }
 
971
    return value;
 
972
}
 
973
 
 
974
LAS_DLL char LASPoint_GetScanAngleRank(const LASPointH hPoint) {
 
975
    
 
976
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetScanAngleRank", 0);
 
977
    
 
978
    boost::int8_t value = ((liblas::Point*) hPoint)->GetScanAngleRank();
 
979
    return static_cast<char>(value);
 
980
}
 
981
 
 
982
LAS_DLL LASErrorEnum LASPoint_SetScanAngleRank(LASPointH hPoint, char value) {
 
983
 
 
984
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetScanAngleRank", LE_Failure);
 
985
 
 
986
    try {
 
987
            ((liblas::Point*) hPoint)->SetScanAngleRank(static_cast<boost::int8_t>(value));
 
988
    } catch (std::exception const& e)
 
989
    {
 
990
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetScanAngleRank");
 
991
        return LE_Failure;
 
992
    }
 
993
 
 
994
    return LE_None;
 
995
 
 
996
}
 
997
 
 
998
LAS_DLL boost::uint16_t LASPoint_GetPointSourceId(const LASPointH hPoint) {
 
999
    
 
1000
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetPointSourceId", 0);
 
1001
    
 
1002
    boost::uint16_t value = ((liblas::Point*) hPoint)->GetPointSourceID();
 
1003
    return value;
 
1004
}
 
1005
 
 
1006
LAS_DLL LASErrorEnum LASPoint_SetPointSourceId(LASPointH hPoint, boost::uint16_t value) {
 
1007
 
 
1008
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetPointSourceId", LE_Failure);
 
1009
 
 
1010
    try {
 
1011
            ((liblas::Point*) hPoint)->SetPointSourceID(value);
 
1012
    } catch (std::exception const& e)
 
1013
    {
 
1014
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetPointSourceId");
 
1015
        return LE_Failure;
 
1016
    }
 
1017
 
 
1018
    return LE_None;
 
1019
 
 
1020
}
 
1021
 
 
1022
 
 
1023
LAS_DLL boost::uint8_t LASPoint_GetUserData(const LASPointH hPoint) {
 
1024
    
 
1025
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetUserData", 0);
 
1026
    
 
1027
    boost::uint8_t value = ((liblas::Point*) hPoint)->GetUserData();
 
1028
    return value;
 
1029
}
 
1030
 
 
1031
LAS_DLL char* LASPoint_GetXML(const LASPointH hPoint) 
 
1032
{
 
1033
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetXML", NULL);
 
1034
    liblas::Point* p = (liblas::Point*)hPoint;
 
1035
    
 
1036
    std::ostringstream oss;
 
1037
    
 
1038
    liblas::property_tree::ptree tree= p->GetPTree();
 
1039
    liblas::property_tree::write_xml(oss, tree);
 
1040
    return LASCopyString(oss.str().c_str());
 
1041
    
 
1042
}
 
1043
 
 
1044
LAS_DLL LASErrorEnum LASPoint_SetUserData(LASPointH hPoint, boost::uint8_t value) {
 
1045
 
 
1046
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetUserData", LE_Failure);
 
1047
 
 
1048
    try {
 
1049
            ((liblas::Point*) hPoint)->SetUserData(value);
 
1050
    } catch (std::exception const& e)
 
1051
    {
 
1052
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetUserData");
 
1053
        return LE_Failure;
 
1054
    }
 
1055
 
 
1056
    return LE_None;
 
1057
 
 
1058
}
 
1059
 
 
1060
LAS_DLL int LASPoint_Equal(const LASPointH hPoint1, const LASPointH hPoint2) {
 
1061
    VALIDATE_LAS_POINTER1(hPoint1, "LASPoint_Equal", 0);
 
1062
    VALIDATE_LAS_POINTER1(hPoint2, "LASPoint_Equal", 0);
 
1063
 
 
1064
    liblas::Point* point1 = ((liblas::Point*) hPoint1);
 
1065
    liblas::Point* point2 = ((liblas::Point*) hPoint2);
 
1066
 
 
1067
    return (point1 == point2);
 
1068
 
 
1069
}
 
1070
 
 
1071
LAS_DLL int LASPoint_Validate(LASPointH hPoint) {
 
1072
 
 
1073
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_Validate", LE_Failure);
 
1074
 
 
1075
    try {
 
1076
            ((liblas::Point*) hPoint)->Validate();
 
1077
    } catch (invalid_point_data const& e /*e */) {
 
1078
        return e.who();
 
1079
    } catch (std::exception const& e)
 
1080
    {
 
1081
        LASError_PushError(LE_Failure, e.what(), "LASPoint_Validate");
 
1082
        return LE_Failure;
 
1083
    }
 
1084
 
 
1085
    return LE_None;
 
1086
}
 
1087
 
 
1088
LAS_DLL int LASPoint_IsValid(LASPointH hPoint) {
 
1089
 
 
1090
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_IsValid", LE_Failure);
 
1091
    return ((liblas::Point*) hPoint)->IsValid();
 
1092
}
 
1093
 
 
1094
LAS_DLL char* LASHeader_GetFileSignature(const LASHeaderH hHeader) {
 
1095
    // caller owns it
 
1096
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetFileSignature", NULL);
 
1097
    
 
1098
    std::string signature = ((liblas::HeaderPtr*) hHeader)->get()->GetFileSignature();
 
1099
    return LASCopyString(signature.c_str());
 
1100
}
 
1101
 
 
1102
LAS_DLL boost::uint16_t LASHeader_GetFileSourceId(const LASHeaderH hHeader) {
 
1103
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetFileSourceId", 0);
 
1104
 
 
1105
    unsigned short value = ((liblas::HeaderPtr*) hHeader)->get()->GetFileSourceId();
 
1106
    return value;
 
1107
}
 
1108
 
 
1109
LAS_DLL LASErrorEnum LASHeader_SetFileSourceId(LASHeaderH hHeader, boost::uint16_t value) {
 
1110
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetFileSourceId", LE_Failure);
 
1111
    ((liblas::HeaderPtr*) hHeader)->get()->SetFileSourceId(value);    
 
1112
    return LE_None;
 
1113
}
 
1114
 
 
1115
 
 
1116
LAS_DLL boost::uint16_t LASHeader_GetReserved(const LASHeaderH hHeader) {
 
1117
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetReserved", 0);
 
1118
 
 
1119
    unsigned short value = ((liblas::HeaderPtr*) hHeader)->get()->GetReserved();
 
1120
    return value;
 
1121
}
 
1122
 
 
1123
LAS_DLL LASErrorEnum LASHeader_SetReserved(LASHeaderH hHeader, boost::uint16_t value) {
 
1124
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetReserved", LE_Failure);
 
1125
    ((liblas::HeaderPtr*) hHeader)->get()->SetReserved(value);    
 
1126
    return LE_None;
 
1127
}
 
1128
 
 
1129
LAS_DLL char* LASHeader_GetProjectId(const LASHeaderH hHeader) {
 
1130
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetProjectId", 0);
 
1131
    
 
1132
    liblas::guid id = ((liblas::HeaderPtr*) hHeader)->get()->GetProjectId();
 
1133
    return LASCopyString(id.to_string().c_str());
 
1134
}
 
1135
 
 
1136
LAS_DLL LASErrorEnum LASHeader_SetProjectId(LASHeaderH hHeader, const char* value) {
 
1137
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetProjectId", LE_Failure);
 
1138
 
 
1139
    try {
 
1140
        liblas::guid id;
 
1141
        id = liblas::guid(value);
 
1142
        ((liblas::HeaderPtr*) hHeader)->get()->SetProjectId(id);    
 
1143
    } catch (std::exception const& e)
 
1144
    {
 
1145
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetGUID");
 
1146
        return LE_Failure;
 
1147
    }
 
1148
 
 
1149
    return LE_None;
 
1150
}
 
1151
 
 
1152
LAS_DLL boost::uint8_t LASHeader_GetVersionMajor(const LASHeaderH hHeader) {
 
1153
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetVersionMajor", 0);
 
1154
 
 
1155
    long value = ((liblas::HeaderPtr*) hHeader)->get()->GetVersionMajor();
 
1156
    return boost::uint8_t(value);
 
1157
}
 
1158
 
 
1159
LAS_DLL LASErrorEnum LASHeader_SetVersionMajor(LASHeaderH hHeader, boost::uint8_t value) {
 
1160
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetVersionMajor", LE_Failure);
 
1161
 
 
1162
    try {
 
1163
        ((liblas::HeaderPtr*) hHeader)->get()->SetVersionMajor(value);    
 
1164
    } catch (std::exception const& e)
 
1165
    {
 
1166
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetVersionMajor");
 
1167
        return LE_Failure;
 
1168
    }
 
1169
 
 
1170
    return LE_None;
 
1171
}
 
1172
 
 
1173
LAS_DLL boost::uint8_t LASHeader_GetVersionMinor(const LASHeaderH hHeader) {
 
1174
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetVersionMinor", 0);
 
1175
 
 
1176
    long value = ((liblas::HeaderPtr*) hHeader)->get()->GetVersionMinor();
 
1177
    return boost::uint8_t(value);
 
1178
}
 
1179
 
 
1180
LAS_DLL LASErrorEnum LASHeader_SetVersionMinor(LASHeaderH hHeader, boost::uint8_t value) {
 
1181
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetVersionMinor", LE_Failure);
 
1182
 
 
1183
    // TODO: Maybe this should be a fatal error -- hobu
 
1184
    try {
 
1185
        ((liblas::HeaderPtr*) hHeader)->get()->SetVersionMinor(value);    
 
1186
    } catch (std::exception const& e)
 
1187
    {
 
1188
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetVersionMinor");
 
1189
        return LE_Failure;
 
1190
    }
 
1191
 
 
1192
    return LE_None;
 
1193
}
 
1194
 
 
1195
LAS_DLL char* LASHeader_GetSystemId(const LASHeaderH hHeader) {
 
1196
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetSystemId", NULL);
 
1197
 
 
1198
    // caller owns it
 
1199
    std::string sysid = ((liblas::HeaderPtr*) hHeader)->get()->GetSystemId();
 
1200
    return LASCopyString(sysid.c_str());
 
1201
}
 
1202
 
 
1203
LAS_DLL LASErrorEnum LASHeader_SetSystemId(LASHeaderH hHeader, const char* value) {
 
1204
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetSystemId", LE_Failure); 
 
1205
 
 
1206
    try {
 
1207
            ((liblas::HeaderPtr*) hHeader)->get()->SetSystemId(value);
 
1208
    } catch (std::exception const& e)
 
1209
    {
 
1210
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetSystemId");
 
1211
        return LE_Failure;
 
1212
    }
 
1213
 
 
1214
    return LE_None;
 
1215
}
 
1216
 
 
1217
LAS_DLL char* LASHeader_GetSoftwareId(const LASHeaderH hHeader) {
 
1218
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetSoftwareId", NULL);
 
1219
 
 
1220
    // caller owns it
 
1221
    std::string softid = ((liblas::HeaderPtr*) hHeader)->get()->GetSoftwareId();
 
1222
    return LASCopyString(softid.c_str());
 
1223
}
 
1224
 
 
1225
LAS_DLL LASErrorEnum LASHeader_SetSoftwareId(LASHeaderH hHeader, const char* value) {
 
1226
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetSoftwareId", LE_Failure); 
 
1227
 
 
1228
    try {
 
1229
            ((liblas::HeaderPtr*) hHeader)->get()->SetSoftwareId(value);
 
1230
    } catch (std::exception const& e)
 
1231
    {
 
1232
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetSoftwareId");
 
1233
        return LE_Failure;
 
1234
    }
 
1235
 
 
1236
    return LE_None;
 
1237
}
 
1238
 
 
1239
LAS_DLL boost::uint16_t LASHeader_GetCreationDOY(const LASHeaderH hHeader) {
 
1240
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetCreationDOY", 0);
 
1241
 
 
1242
    unsigned short value = ((liblas::HeaderPtr*) hHeader)->get()->GetCreationDOY();
 
1243
    return value;
 
1244
}
 
1245
 
 
1246
LAS_DLL LASErrorEnum LASHeader_SetCreationDOY(LASHeaderH hHeader, boost::uint16_t value) {
 
1247
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetCreationDOY", LE_Failure);
 
1248
    ((liblas::HeaderPtr*) hHeader)->get()->SetCreationDOY(value);    
 
1249
    return LE_None;
 
1250
}
 
1251
 
 
1252
LAS_DLL boost::uint16_t LASHeader_GetCreationYear(const LASHeaderH hHeader) {
 
1253
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetCreationYear", 0);
 
1254
 
 
1255
    unsigned short value = ((liblas::HeaderPtr*) hHeader)->get()->GetCreationYear();
 
1256
    return value;
 
1257
}
 
1258
 
 
1259
LAS_DLL LASErrorEnum LASHeader_SetCreationYear(LASHeaderH hHeader, boost::uint16_t value) {
 
1260
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetCreationYear", LE_Failure);
 
1261
    ((liblas::HeaderPtr*) hHeader)->get()->SetCreationYear(value);    
 
1262
    return LE_None;
 
1263
}
 
1264
 
 
1265
LAS_DLL boost::uint16_t LASHeader_GetHeaderSize(const LASHeaderH hHeader) {
 
1266
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetHeaderSize", 0);
 
1267
 
 
1268
    unsigned short value = ((liblas::HeaderPtr*) hHeader)->get()->GetHeaderSize();
 
1269
    return value;
 
1270
}
 
1271
 
 
1272
LAS_DLL boost::uint32_t LASHeader_GetDataOffset(const LASHeaderH hHeader) {
 
1273
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetDataOffset", 0);
 
1274
 
 
1275
    unsigned long value = ((liblas::HeaderPtr*) hHeader)->get()->GetDataOffset();
 
1276
    return value;
 
1277
}
 
1278
 
 
1279
LAS_DLL LASErrorEnum LASHeader_SetDataOffset(const LASHeaderH hHeader, boost::uint32_t value) {
 
1280
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetDataOffset", LE_Failure);
 
1281
 
 
1282
    try {
 
1283
        ((liblas::HeaderPtr*) hHeader)->get()->SetDataOffset(value);    
 
1284
    } catch (std::exception const& e)
 
1285
    {
 
1286
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetDataOffset");
 
1287
        return LE_Failure;
 
1288
    }
 
1289
 
 
1290
    return LE_None;    
 
1291
}
 
1292
 
 
1293
LAS_DLL boost::uint32_t LASHeader_GetHeaderPadding(const LASHeaderH hHeader) {
 
1294
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetHeaderPadding", 0);
 
1295
 
 
1296
    unsigned long value = ((liblas::HeaderPtr*) hHeader)->get()->GetHeaderPadding();
 
1297
    return value;
 
1298
}
 
1299
 
 
1300
LAS_DLL LASErrorEnum LASHeader_SetHeaderPadding(const LASHeaderH hHeader, boost::uint32_t value) {
 
1301
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetHeaderPadding", LE_Failure);
 
1302
 
 
1303
    try {
 
1304
        ((liblas::HeaderPtr*) hHeader)->get()->SetHeaderPadding(value);    
 
1305
    } catch (std::exception const& e)
 
1306
    {
 
1307
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetHeaderPadding");
 
1308
        return LE_Failure;
 
1309
    }
 
1310
 
 
1311
    return LE_None;    
 
1312
}
 
1313
 
 
1314
LAS_DLL boost::uint32_t LASHeader_GetRecordsCount(const LASHeaderH hHeader) {
 
1315
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetRecordsCount", 0);
 
1316
 
 
1317
    unsigned long value = ((liblas::HeaderPtr*) hHeader)->get()->GetRecordsCount();
 
1318
    return value;
 
1319
}
 
1320
 
 
1321
LAS_DLL boost::uint8_t LASHeader_GetDataFormatId(const LASHeaderH hHeader) {
 
1322
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetDataFormatId", 0);
 
1323
    
 
1324
    liblas::PointFormatName id = ((liblas::HeaderPtr*) hHeader)->get()->GetDataFormatId();
 
1325
    return static_cast<boost::uint8_t>(id);
 
1326
}
 
1327
 
 
1328
LAS_DLL LASErrorEnum LASHeader_SetDataFormatId(LASHeaderH hHeader, boost::uint8_t value) {
 
1329
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_SetDataFormatId", LE_Failure); 
 
1330
    
 
1331
    try {
 
1332
            ((liblas::HeaderPtr*) hHeader)->get()->SetDataFormatId((liblas::PointFormatName)value);
 
1333
    } catch (std::exception const& e)
 
1334
    {
 
1335
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetDataFormatId");
 
1336
        return LE_Failure;
 
1337
    }
 
1338
 
 
1339
    return LE_None;
 
1340
}
 
1341
 
 
1342
LAS_DLL boost::uint16_t LASHeader_GetDataRecordLength(const LASHeaderH hHeader) {
 
1343
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetDataRecordLength", 0);
 
1344
 
 
1345
    unsigned short value = ((liblas::HeaderPtr*) hHeader)->get()->GetDataRecordLength();
 
1346
    return value;
 
1347
}
 
1348
 
 
1349
 
 
1350
 
 
1351
LAS_DLL boost::uint32_t LASHeader_GetPointRecordsByReturnCount(const LASHeaderH hHeader, int index) {
 
1352
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetPointRecordsByReturnCount", 0);
 
1353
 
 
1354
    std::vector<boost::uint32_t> counts  = ((liblas::HeaderPtr*) hHeader)->get()->GetPointRecordsByReturnCount();
 
1355
    if ( (index < 5) && (index >= 0)) {
 
1356
        return counts[index];
 
1357
    } 
 
1358
 
 
1359
    return 0;
 
1360
    
 
1361
}
 
1362
 
 
1363
LAS_DLL LASErrorEnum LASHeader_SetPointRecordsByReturnCount(const LASHeaderH hHeader, int index, boost::uint32_t value) {
 
1364
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetPointRecordsByReturnCount", LE_Failure);
 
1365
 
 
1366
    try {
 
1367
        ((liblas::HeaderPtr*) hHeader)->get()->SetPointRecordsByReturnCount(index, value);    
 
1368
    } catch (std::exception const& e)
 
1369
    {
 
1370
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetPointRecordsByReturnCount");
 
1371
        return LE_Failure;
 
1372
    }
 
1373
 
 
1374
    return LE_None;    
 
1375
}
 
1376
 
 
1377
 
 
1378
LAS_DLL boost::uint32_t LASHeader_GetPointRecordsCount(const LASHeaderH hHeader) {
 
1379
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetPointRecordsCount", 0);
 
1380
 
 
1381
    unsigned long value = ((liblas::HeaderPtr*) hHeader)->get()->GetPointRecordsCount();
 
1382
    return value;
 
1383
}
 
1384
 
 
1385
LAS_DLL LASErrorEnum LASHeader_SetPointRecordsCount(const LASHeaderH hHeader, boost::uint32_t value) {
 
1386
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetPointRecordsCount", LE_Failure);
 
1387
 
 
1388
    try {
 
1389
        ((liblas::HeaderPtr*) hHeader)->get()->SetPointRecordsCount(value);    
 
1390
    } catch (std::exception const& e)
 
1391
    {
 
1392
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetPointRecordsCount");
 
1393
        return LE_Failure;
 
1394
    }
 
1395
 
 
1396
    return LE_None;    
 
1397
}
 
1398
 
 
1399
LAS_DLL double LASHeader_GetScaleX(const LASHeaderH hHeader) {
 
1400
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetScaleX", 0.0);
 
1401
 
 
1402
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetScaleX();
 
1403
    return value;
 
1404
}
 
1405
 
 
1406
LAS_DLL double LASHeader_GetScaleY(const LASHeaderH hHeader) {
 
1407
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetScaleY", 0.0);
 
1408
 
 
1409
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetScaleY();
 
1410
    return value;
 
1411
}
 
1412
 
 
1413
LAS_DLL double LASHeader_GetScaleZ(const LASHeaderH hHeader) {
 
1414
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetScaleZ", 0.0);
 
1415
 
 
1416
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetScaleZ();
 
1417
    return value;
 
1418
}
 
1419
 
 
1420
LAS_DLL LASErrorEnum LASHeader_SetScale(LASHeaderH hHeader, double x, double y, double z) {
 
1421
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetScale", LE_Failure); 
 
1422
    
 
1423
    try {
 
1424
            ((liblas::HeaderPtr*) hHeader)->get()->SetScale(x,y,z);
 
1425
    } catch (std::exception const& e)
 
1426
    {
 
1427
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetScale");
 
1428
        return LE_Failure;
 
1429
    }
 
1430
 
 
1431
    return LE_None;
 
1432
}
 
1433
 
 
1434
LAS_DLL double LASHeader_GetOffsetX(const LASHeaderH hHeader) {
 
1435
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetOffsetX", 0.0);
 
1436
 
 
1437
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetOffsetX();
 
1438
    return value;
 
1439
}
 
1440
 
 
1441
LAS_DLL double LASHeader_GetOffsetY(const LASHeaderH hHeader) {
 
1442
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetOffsetY", 0.0);
 
1443
 
 
1444
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetOffsetY();
 
1445
    return value;
 
1446
}
 
1447
 
 
1448
LAS_DLL double LASHeader_GetOffsetZ(const LASHeaderH hHeader) {
 
1449
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetOffsetZ", 0.0);
 
1450
 
 
1451
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetOffsetZ();
 
1452
    return value;
 
1453
}
 
1454
 
 
1455
LAS_DLL LASErrorEnum LASHeader_SetOffset(LASHeaderH hHeader, double x, double y, double z) {
 
1456
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetOffset", LE_Failure); 
 
1457
    
 
1458
    try {
 
1459
            ((liblas::HeaderPtr*) hHeader)->get()->SetOffset(x,y,z);
 
1460
    } catch (std::exception const& e)
 
1461
    {
 
1462
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetOffset");
 
1463
        return LE_Failure;
 
1464
    }
 
1465
 
 
1466
    return LE_None;
 
1467
}
 
1468
 
 
1469
LAS_DLL double LASHeader_GetMinX(const LASHeaderH hHeader) {
 
1470
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetMinX", 0.0);
 
1471
 
 
1472
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetMinX();
 
1473
    return value;
 
1474
}
 
1475
 
 
1476
LAS_DLL double LASHeader_GetMinY(const LASHeaderH hHeader) {
 
1477
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetMinY", 0.0);
 
1478
 
 
1479
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetMinY();
 
1480
    return value;
 
1481
}
 
1482
 
 
1483
LAS_DLL double LASHeader_GetMinZ(const LASHeaderH hHeader) {
 
1484
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetMinZ", 0.0);
 
1485
 
 
1486
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetMinZ();
 
1487
    return value;
 
1488
}
 
1489
 
 
1490
LAS_DLL LASErrorEnum LASHeader_SetMin(LASHeaderH hHeader, double x, double y, double z) {
 
1491
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetMin", LE_Failure); 
 
1492
    
 
1493
    try {
 
1494
            ((liblas::HeaderPtr*) hHeader)->get()->SetMin(x,y,z);
 
1495
    } catch (std::exception const& e)
 
1496
    {
 
1497
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetMin");
 
1498
        return LE_Failure;
 
1499
    }
 
1500
 
 
1501
    return LE_None;
 
1502
}
 
1503
 
 
1504
LAS_DLL double LASHeader_GetMaxX(const LASHeaderH hHeader) {
 
1505
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetMaxX", 0.0);
 
1506
 
 
1507
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetMaxX();
 
1508
    return value;
 
1509
}
 
1510
 
 
1511
LAS_DLL double LASHeader_GetMaxY(const LASHeaderH hHeader) {
 
1512
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetMaxY", 0.0);
 
1513
 
 
1514
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetMaxY();
 
1515
    return value;
 
1516
}
 
1517
 
 
1518
LAS_DLL double LASHeader_GetMaxZ(const LASHeaderH hHeader) {
 
1519
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetMaxZ", 0.0);
 
1520
 
 
1521
    double value = ((liblas::HeaderPtr*) hHeader)->get()->GetMaxZ();
 
1522
    return value;
 
1523
}
 
1524
 
 
1525
LAS_DLL LASErrorEnum LASHeader_SetMax(LASHeaderH hHeader, double x, double y, double z) {
 
1526
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetMax", LE_Failure); 
 
1527
    
 
1528
    try {
 
1529
            ((liblas::HeaderPtr*) hHeader)->get()->SetMax(x,y,z);
 
1530
    } catch (std::exception const& e)
 
1531
    {
 
1532
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetMax");
 
1533
        return LE_Failure;
 
1534
    }
 
1535
 
 
1536
    return LE_None;
 
1537
}
 
1538
 
 
1539
LAS_DLL char* LASHeader_GetXML(const LASHeaderH hHeader) 
 
1540
{
 
1541
    VALIDATE_LAS_POINTER1(hHeader, "LASHeader_GetXML", NULL);
 
1542
    liblas::Header* h = (liblas::Header*)hHeader->get();
 
1543
    
 
1544
    std::ostringstream oss;
 
1545
    
 
1546
    liblas::property_tree::ptree tree= h->GetPTree();
 
1547
    liblas::property_tree::write_xml(oss, tree);
 
1548
    return LASCopyString(oss.str().c_str());
 
1549
    
 
1550
}
 
1551
 
 
1552
 
 
1553
LAS_DLL void LASHeader_Destroy(LASHeaderH hHeader)
 
1554
{
 
1555
    VALIDATE_LAS_POINTER0(hHeader, "LASHeader_Destroy");
 
1556
    // delete ((liblas::Header*) hHeader);
 
1557
    // hHeader=NULL;
 
1558
}
 
1559
 
 
1560
LAS_DLL LASHeaderH LASHeader_Copy(const LASHeaderH hHeader) {
 
1561
    liblas::HeaderPtr* header = ((liblas::HeaderPtr*) hHeader);
 
1562
    return (LASHeaderH) new liblas::HeaderPtr(new liblas::Header(*header->get()));
 
1563
}
 
1564
 
 
1565
LAS_DLL int LASHeader_Equal(const LASHeaderH hHeader1, const LASHeaderH hHeader2) {
 
1566
    VALIDATE_LAS_POINTER1(hHeader1->get(), "LASHeader_Equal", 0);
 
1567
    VALIDATE_LAS_POINTER1(hHeader2->get(), "LASHeader_Equal", 0);
 
1568
 
 
1569
    liblas::HeaderPtr* header1 = ((liblas::HeaderPtr*) hHeader1);
 
1570
    liblas::HeaderPtr* header2 = ((liblas::HeaderPtr*) hHeader2);
 
1571
 
 
1572
    return (*header1->get() == *header2->get());
 
1573
}
 
1574
 
 
1575
LAS_DLL LASGuidH LASHeader_GetGUID(const LASHeaderH hHeader) {
 
1576
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetGUID", 0);
 
1577
    
 
1578
    liblas::guid id = ((liblas::HeaderPtr*) hHeader)->get()->GetProjectId();
 
1579
    return (LASGuidH) new liblas::guid(id);
 
1580
}
 
1581
 
 
1582
 
 
1583
LAS_DLL LASErrorEnum LASHeader_SetGUID(LASHeaderH hHeader, LASGuidH hId) {
 
1584
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetGUID", LE_Failure);
 
1585
 
 
1586
    try {
 
1587
        liblas::guid* id = (liblas::guid*) hId;
 
1588
        
 
1589
        ((liblas::HeaderPtr*) hHeader)->get()->SetProjectId(*id);    
 
1590
    } catch (std::exception const& e)
 
1591
    {
 
1592
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetGUID");
 
1593
        return LE_Failure;
 
1594
    }
 
1595
 
 
1596
    return LE_None;
 
1597
}
 
1598
 
 
1599
LAS_DLL LASVLRH LASHeader_GetVLR(const LASHeaderH hHeader, boost::uint32_t i) {
 
1600
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetVLR", 0);
 
1601
    
 
1602
    liblas::VariableRecord vlr = ((liblas::HeaderPtr*) hHeader)->get()->GetVLR(i);
 
1603
    return (LASVLRH) new liblas::VariableRecord(vlr);
 
1604
}
 
1605
 
 
1606
LAS_DLL LASErrorEnum LASHeader_DeleteVLR(LASHeaderH hHeader, boost::uint32_t index) {
 
1607
    
 
1608
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_DeleteVLR", LE_Failure);
 
1609
 
 
1610
    try {
 
1611
        ((liblas::HeaderPtr*) hHeader)->get()->DeleteVLR(index);
 
1612
    }
 
1613
    catch (std::exception const& e) {
 
1614
        LASError_PushError(LE_Failure, e.what(), "LASHeader_DeleteVLR");
 
1615
        return LE_Failure;
 
1616
    }
 
1617
 
 
1618
 
 
1619
    return LE_None;
 
1620
}
 
1621
 
 
1622
LAS_DLL LASErrorEnum LASHeader_AddVLR(LASHeaderH hHeader, const LASVLRH hVLR) {
 
1623
    
 
1624
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_AddVLR", LE_Failure);
 
1625
    VALIDATE_LAS_POINTER1(hVLR, "LASHeader_AddVLR", LE_Failure);
 
1626
 
 
1627
    try {
 
1628
        ((liblas::HeaderPtr*) hHeader)->get()->AddVLR(*((liblas::VariableRecord*)hVLR));
 
1629
    }
 
1630
    catch (std::exception const& e) {
 
1631
        LASError_PushError(LE_Failure, e.what(), "LASHeader_AddVLR");
 
1632
        return LE_Failure;
 
1633
    }
 
1634
 
 
1635
 
 
1636
    return LE_None;
 
1637
}
 
1638
 
 
1639
 
 
1640
 
 
1641
 
 
1642
LAS_DLL LASWriterH LASWriter_Create(const char* filename, const LASHeaderH hHeader, int mode) {
 
1643
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASWriter_Create", NULL); 
 
1644
    
 
1645
    if (filename == NULL) {
 
1646
        LASError_PushError(LE_Failure, "Input filename was null", "LASWriter_Create");
 
1647
        return NULL;
 
1648
    }
 
1649
    std::ostream* ostrm = NULL;
 
1650
    try 
 
1651
    {
 
1652
        std::ios::openmode m;
 
1653
        if ( (mode > 2) || (mode < 1)) {
 
1654
            throw std::runtime_error("File mode must be eWrite or eAppend");
 
1655
        }
 
1656
        
 
1657
        
 
1658
 
 
1659
        // append mode 
 
1660
        if (mode == 2) {
 
1661
            m = std::ios::out | std::ios::in | std::ios::binary | std::ios::ate;
 
1662
        }
 
1663
        // write mode
 
1664
        else {
 
1665
            m = std::ios::out | std::ios::binary | std::ios::ate;
 
1666
        }
 
1667
 
 
1668
        ostrm = liblas::Create(filename, m);
 
1669
 
 
1670
        
 
1671
 
 
1672
    } catch (std::exception const& e)
 
1673
    {
 
1674
        if (ostrm)
 
1675
            delete ostrm;
 
1676
        LASError_PushError(LE_Failure, e.what(), "LASWriter_Create");
 
1677
        return NULL;
 
1678
    }
 
1679
 
 
1680
 
 
1681
    try {
 
1682
 
 
1683
        liblas::HeaderPtr* header = ((liblas::HeaderPtr*) hHeader);
 
1684
        liblas::Writer* writer = new liblas::Writer(*ostrm, *header->get());
 
1685
 
 
1686
        writers.insert(std::pair<liblas::Writer*, std::ostream*>(writer, ostrm));
 
1687
        return (LASWriterH) writer;
 
1688
        
 
1689
 
 
1690
    } catch (std::exception const& e)
 
1691
    {
 
1692
        LASError_PushError(LE_Failure, e.what(), "LASWriter_Create");
 
1693
        return NULL;
 
1694
    }
 
1695
 
 
1696
    
 
1697
}
 
1698
 
 
1699
LAS_DLL LASErrorEnum LASWriter_WritePoint(const LASWriterH hWriter, const LASPointH hPoint) {
 
1700
 
 
1701
    VALIDATE_LAS_POINTER1(hPoint, "LASWriter_WritePoint", LE_Failure);
 
1702
    int ret;
 
1703
 
 
1704
    try {
 
1705
            ret = ((liblas::Writer*) hWriter)->WritePoint(*((liblas::Point*) hPoint));
 
1706
            if (!ret) {
 
1707
                LASError_PushError( LE_Warning, 
 
1708
                                    "Failed to write point because it was invalid", 
 
1709
                                    "LASWriter_WritePoint");
 
1710
                return LE_Warning;                
 
1711
            }
 
1712
    } catch (std::exception const& e)
 
1713
    {
 
1714
        LASError_PushError(LE_Failure, e.what(), "LASWriter_WritePoint");
 
1715
        return LE_Failure;
 
1716
    }
 
1717
 
 
1718
    return LE_None;    
 
1719
}
 
1720
 
 
1721
LAS_DLL LASErrorEnum LASWriter_WriteHeader(const LASWriterH hWriter, const LASHeaderH hHeader) {
 
1722
 
 
1723
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASWriter_WriteHeader", LE_Failure);
 
1724
    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_WriteHeader", LE_Failure);
 
1725
    
 
1726
    try {
 
1727
        ((liblas::Writer*) hWriter)->SetHeader(*((liblas::HeaderPtr*) hHeader)->get());
 
1728
        ((liblas::Writer*) hWriter)->WriteHeader();
 
1729
    } catch (std::exception const& e)
 
1730
    {
 
1731
        LASError_PushError(LE_Failure, e.what(), "LASWriter_WriteHeader");
 
1732
        return LE_Failure;
 
1733
    }
 
1734
 
 
1735
    return LE_None;    
 
1736
}
 
1737
 
 
1738
LAS_DLL LASErrorEnum LASWriter_WriteOwnedHeader(const LASWriterH hWriter)
 
1739
{
 
1740
    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_WriteOwnedHeader", LE_Failure);
 
1741
 
 
1742
    try {
 
1743
        ((liblas::Writer*) hWriter)->WriteHeader();
 
1744
    } catch (std::exception const& e)
 
1745
    {
 
1746
        LASError_PushError(LE_Failure, e.what(), "LASWriter_WriteOwnedHeader");
 
1747
        return LE_Failure;
 
1748
    }
 
1749
 
 
1750
    return LE_None;    
 
1751
}
 
1752
 
 
1753
 
 
1754
LAS_DLL void LASWriter_SetHeader(  LASWriterH hWriter, const LASHeaderH hHeader) 
 
1755
 
 
1756
{
 
1757
    VALIDATE_LAS_POINTER0(hWriter, "LASWriter_SetHeader");
 
1758
    VALIDATE_LAS_POINTER0(hHeader, "LASWriter_SetHeader");
 
1759
 
 
1760
    liblas::Writer* writer = (liblas::Writer*)hWriter;
 
1761
    liblas::HeaderPtr* header = (liblas::HeaderPtr*)hHeader;
 
1762
    if (header->get())
 
1763
        writer->SetHeader(*header->get());
 
1764
}
 
1765
 
 
1766
LAS_DLL void LASWriter_Destroy(LASWriterH hWriter)
 
1767
{
 
1768
    VALIDATE_LAS_POINTER0(hWriter, "LASWriter_Destroy");
 
1769
 
 
1770
    try { 
 
1771
        liblas::Writer* writer = (liblas::Writer*)hWriter;
 
1772
 
 
1773
        std::map<liblas::Writer*, std::ostream*>::iterator it = writers.find(writer);
 
1774
        if (it == writers.end())
 
1775
        {
 
1776
            LASError_PushError(LE_Failure, "Unable to find writer stream", "LASWriter_Destroy");
 
1777
            return;            
 
1778
        }
 
1779
        std::ostream* ostrm = it->second;
 
1780
 
 
1781
        delete writer;
 
1782
        hWriter = NULL;
 
1783
 
 
1784
        if ( ostrm == NULL )
 
1785
        {
 
1786
            LASError_PushError(LE_Failure, "Got 99 problems, but the stream ain't one", "LASWriter_Destroy");
 
1787
            return;            
 
1788
        }
 
1789
    
 
1790
        liblas::Cleanup(ostrm);
 
1791
        
 
1792
        writers.erase(writer);
 
1793
        
 
1794
        ostrm = NULL;
 
1795
  
 
1796
        }  catch (std::runtime_error const& e/* e */) 
 
1797
        {
 
1798
            LASError_PushError(LE_Failure, e.what(), "LASWriter_Destroy");
 
1799
            return;
 
1800
        }
 
1801
 
 
1802
}
 
1803
 
 
1804
LAS_DLL LASErrorEnum LASWriter_SetInputSRS(LASWriterH hWriter, const LASSRSH hSRS) {
 
1805
    
 
1806
    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_SetInputSRS", LE_Failure);
 
1807
    VALIDATE_LAS_POINTER1(hSRS, "LASWriter_SetInputSRS", LE_Failure);
 
1808
 
 
1809
    try {
 
1810
        liblas::Writer* writer = ((liblas::Writer*) hWriter);
 
1811
        liblas::Header h = writer->GetHeader();
 
1812
        liblas::SpatialReference* srs =  ((liblas::SpatialReference*) hSRS);
 
1813
        h.SetSRS(*srs);
 
1814
        writer->SetHeader(h);
 
1815
    }
 
1816
    catch (std::exception const& e) {
 
1817
        LASError_PushError(LE_Failure, e.what(), "LASWriter_SetInputSRS");
 
1818
        return LE_Failure;
 
1819
    }
 
1820
 
 
1821
    return LE_None;
 
1822
}
 
1823
 
 
1824
LAS_DLL LASErrorEnum LASWriter_SetOutputSRS(LASWriterH hWriter, const LASSRSH hSRS) {
 
1825
    
 
1826
    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_SetOutputSRS", LE_Failure);
 
1827
    VALIDATE_LAS_POINTER1(hSRS, "LASWriter_SetOutputSRS", LE_Failure);
 
1828
 
 
1829
    try {
 
1830
        liblas::Writer* writer = ((liblas::Writer*) hWriter);
 
1831
        liblas::Header const& h = writer->GetHeader();
 
1832
        liblas::SpatialReference in_ref = h.GetSRS();
 
1833
        liblas::SpatialReference* out_ref = ((liblas::SpatialReference*) hSRS);
 
1834
        std::vector<liblas::TransformPtr> transforms = writer->GetTransforms();
 
1835
        
 
1836
        transforms.erase( std::remove_if( transforms.begin(), 
 
1837
                                  transforms.end(),
 
1838
                                  boost::bind( &IsReprojectionTransform, _1 ) ),
 
1839
                  transforms.end());
 
1840
        
 
1841
        liblas::TransformPtr srs_transform = liblas::TransformPtr(new liblas::ReprojectionTransform(in_ref, *out_ref, &h));
 
1842
        if (transforms.size())
 
1843
            transforms.insert(transforms.begin(), srs_transform);
 
1844
        else
 
1845
            transforms.push_back(srs_transform);
 
1846
        writer->SetTransforms(transforms);
 
1847
    }
 
1848
    catch (std::exception const& e) {
 
1849
        LASError_PushError(LE_Failure, e.what(), "LASWriter_SetOutputSRS");
 
1850
        return LE_Failure;
 
1851
    }
 
1852
 
 
1853
    return LE_None;
 
1854
}
 
1855
 
 
1856
LAS_DLL LASErrorEnum LASWriter_SetSRS(LASWriterH hWriter, const LASSRSH hSRS) {
 
1857
    
 
1858
    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_SetSRS", LE_Failure);
 
1859
    VALIDATE_LAS_POINTER1(hSRS, "LASWriter_SetSRS", LE_Failure);
 
1860
 
 
1861
    return LASWriter_SetOutputSRS(hWriter, hSRS);
 
1862
}
 
1863
 
 
1864
LAS_DLL LASHeaderH LASWriter_GetHeader(const LASWriterH hWriter)
 
1865
{
 
1866
    VALIDATE_LAS_POINTER1(hWriter, "LASWriter_GetHeader", new liblas::HeaderPtr());
 
1867
 
 
1868
    liblas::Header header = ((liblas::Writer*) hWriter)->GetHeader();
 
1869
    return (LASHeaderH) new liblas::HeaderPtr( new liblas::Header(header) );
 
1870
}
 
1871
 
 
1872
LAS_DLL void LASError_Print(const char* message) {
 
1873
 
 
1874
    char* errmsg= NULL;
 
1875
    char* errmethod = NULL;
 
1876
    errmsg = LASError_GetLastErrorMsg();
 
1877
    errmethod = LASError_GetLastErrorMethod();
 
1878
    if (LASError_GetErrorCount()) {
 
1879
        fprintf(stderr, 
 
1880
            "%s: %s (%d) from method %s\n",
 
1881
            message,
 
1882
            errmsg,
 
1883
            LASError_GetLastErrorNum(),
 
1884
            errmethod
 
1885
        ); 
 
1886
        if (errmsg) free(errmsg);
 
1887
        if (errmethod) free(errmethod);
 
1888
    } else {
 
1889
        fprintf(stderr, 
 
1890
            "You have encountered an error. '%s'\n",
 
1891
            message
 
1892
        );         
 
1893
    }
 
1894
 
 
1895
}
 
1896
 
 
1897
LAS_DLL char* LAS_GetVersion() {
 
1898
    return LASCopyString(liblas::GetVersion().c_str());
 
1899
}
 
1900
 
 
1901
LAS_DLL char* LAS_GetFullVersion(void) {
 
1902
    return LASCopyString(liblas::GetFullVersion().c_str());
 
1903
}
 
1904
 
 
1905
 
 
1906
LAS_DLL LASVLRH LASVLR_Create(void) {
 
1907
    return (LASVLRH) new liblas::VariableRecord();
 
1908
}
 
1909
 
 
1910
LAS_DLL void LASVLR_Destroy(LASVLRH hVLR){
 
1911
    VALIDATE_LAS_POINTER0(hVLR, "LASVLR_Destroy");
 
1912
    delete (liblas::VariableRecord*)hVLR;
 
1913
    hVLR = NULL;
 
1914
    
 
1915
}
 
1916
 
 
1917
LAS_DLL char* LASVLR_GetUserId(const LASVLRH hVLR) {
 
1918
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetUserId", 0);
 
1919
    liblas::VariableRecord* vlr = (liblas::VariableRecord*)hVLR;
 
1920
    return LASCopyString(vlr->GetUserId(true).c_str());
 
1921
}
 
1922
 
 
1923
LAS_DLL LASErrorEnum LASVLR_SetUserId(LASVLRH hVLR, const char* value) {
 
1924
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetUserId", LE_Failure); 
 
1925
 
 
1926
    try {
 
1927
            ((liblas::VariableRecord*) hVLR)->SetUserId(value);
 
1928
    } catch (std::exception const& e)
 
1929
    {
 
1930
        LASError_PushError(LE_Failure, e.what(), "LASVLR_SetUserId");
 
1931
        return LE_Failure;
 
1932
    }
 
1933
 
 
1934
    return LE_None;
 
1935
}
 
1936
 
 
1937
LAS_DLL char* LASVLR_GetDescription(const LASVLRH hVLR) {
 
1938
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetDescription", 0);
 
1939
    liblas::VariableRecord* vlr = (liblas::VariableRecord*)hVLR;
 
1940
    return LASCopyString(vlr->GetDescription(true).c_str());
 
1941
}
 
1942
 
 
1943
LAS_DLL LASErrorEnum LASVLR_SetDescription(LASVLRH hVLR, const char* value) {
 
1944
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetDescription", LE_Failure); 
 
1945
 
 
1946
    try {
 
1947
            ((liblas::VariableRecord*) hVLR)->SetDescription(value);
 
1948
    } catch (std::exception const& e)
 
1949
    {
 
1950
        LASError_PushError(LE_Failure, e.what(), "LASVLR_SetDescription");
 
1951
        return LE_Failure;
 
1952
    }
 
1953
 
 
1954
    return LE_None;
 
1955
}
 
1956
 
 
1957
LAS_DLL boost::uint16_t LASVLR_GetRecordLength(const LASVLRH hVLR) {
 
1958
    
 
1959
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetRecordLength", 0);
 
1960
    
 
1961
    boost::uint16_t value = ((liblas::VariableRecord*) hVLR)->GetRecordLength();
 
1962
    return value;
 
1963
}
 
1964
LAS_DLL LASErrorEnum LASVLR_SetRecordLength(LASVLRH hVLR, boost::uint16_t value) {
 
1965
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetRecordLength", LE_Failure);
 
1966
    ((liblas::VariableRecord*) hVLR)->SetRecordLength(value);    
 
1967
    return LE_None;
 
1968
}
 
1969
 
 
1970
LAS_DLL boost::uint16_t LASVLR_GetRecordId(const LASVLRH hVLR) {
 
1971
    
 
1972
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetRecordId", 0);
 
1973
    
 
1974
    boost::uint16_t value = ((liblas::VariableRecord*) hVLR)->GetRecordId();
 
1975
    return value;
 
1976
}
 
1977
LAS_DLL LASErrorEnum LASVLR_SetRecordId(LASVLRH hVLR, boost::uint16_t value) {
 
1978
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetRecordId", LE_Failure);
 
1979
    ((liblas::VariableRecord*) hVLR)->SetRecordId(value);    
 
1980
    return LE_None;
 
1981
}
 
1982
 
 
1983
 
 
1984
LAS_DLL LASErrorEnum LASVLR_SetReserved(LASVLRH hVLR, boost::uint16_t value) {
 
1985
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetReserved", LE_Failure);
 
1986
    ((liblas::VariableRecord*) hVLR)->SetReserved(value);    
 
1987
    return LE_None;
 
1988
}
 
1989
 
 
1990
LAS_DLL boost::uint16_t LASVLR_GetReserved(const LASVLRH hVLR) {
 
1991
    
 
1992
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetReserved", 0);
 
1993
    
 
1994
    boost::uint16_t value = ((liblas::VariableRecord*) hVLR)->GetReserved();
 
1995
    return value;
 
1996
}
 
1997
 
 
1998
LAS_DLL LASErrorEnum LASVLR_GetData(const LASVLRH hVLR, boost::uint8_t* data) {
 
1999
    
 
2000
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_GetData", LE_Failure);
 
2001
 
 
2002
    try {
 
2003
        liblas::VariableRecord* vlr = ((liblas::VariableRecord*) hVLR);
 
2004
        std::vector<boost::uint8_t> const& d = vlr->GetData();
 
2005
        boost::uint16_t length = vlr->GetRecordLength();
 
2006
        for (boost::uint16_t i=0; i < length; i++) {
 
2007
            data[i] = d[i];
 
2008
        }
 
2009
    }
 
2010
    catch (std::exception const& e) {
 
2011
        LASError_PushError(LE_Failure, e.what(), "LASVLR_GetData");
 
2012
        return LE_Failure;
 
2013
    }
 
2014
 
 
2015
 
 
2016
    return LE_None;
 
2017
}
 
2018
 
 
2019
LAS_DLL LASErrorEnum LASVLR_SetData(const LASVLRH hVLR, boost::uint8_t* data, boost::uint16_t length) {
 
2020
    
 
2021
    VALIDATE_LAS_POINTER1(hVLR, "LASVLR_SetData", LE_Failure);
 
2022
 
 
2023
    try {
 
2024
        liblas::VariableRecord* vlr = ((liblas::VariableRecord*) hVLR);
 
2025
        std::vector<boost::uint8_t> d;
 
2026
        d.resize(length);
 
2027
        for (boost::uint16_t i=0; i < length; i++) {
 
2028
            d[i] = data[i];
 
2029
        }
 
2030
        vlr->SetData(d);
 
2031
    }
 
2032
    catch (std::exception const& e) {
 
2033
        LASError_PushError(LE_Failure, e.what(), "LASVLR_GetData");
 
2034
        return LE_Failure;
 
2035
    }
 
2036
 
 
2037
 
 
2038
    return LE_None;
 
2039
}
 
2040
 
 
2041
LAS_DLL LASGuidH LASGuid_Create() {
 
2042
    liblas::guid random;
 
2043
    try {
 
2044
        random = liblas::guid::create();
 
2045
        return (LASGuidH) new liblas::guid(random);
 
2046
    }
 
2047
    catch (std::exception const& e) {
 
2048
        LASError_PushError(LE_Failure, e.what(), "LASGuid_Create");
 
2049
        return NULL;
 
2050
    }
 
2051
}
 
2052
 
 
2053
LAS_DLL LASGuidH LASGuid_CreateFromString(const char* string) {
 
2054
    VALIDATE_LAS_POINTER1(string, "LASGuid_CreateFromString", NULL);    
 
2055
    liblas::guid id;
 
2056
    try {
 
2057
        id = liblas::guid(string);
 
2058
        return (LASGuidH) new liblas::guid(id);
 
2059
    }
 
2060
    catch (std::exception const& e) {
 
2061
        LASError_PushError(LE_Failure, e.what(), "LASGuid_CreateFromString");
 
2062
        return NULL;
 
2063
    }
 
2064
}
 
2065
 
 
2066
LAS_DLL void LASGuid_Destroy(LASGuidH hId) {
 
2067
    VALIDATE_LAS_POINTER0(hId, "LASGuid_Destroy");
 
2068
    delete (liblas::guid*) hId;
 
2069
    hId = NULL;
 
2070
}
 
2071
 
 
2072
LAS_DLL int LASGuid_Equals(LASGuidH hId1, LASGuidH hId2) {
 
2073
    VALIDATE_LAS_POINTER1(hId1, "LASGuid_Equals", LE_Failure);
 
2074
    VALIDATE_LAS_POINTER1(hId2, "LASGuid_Equals", LE_Failure);
 
2075
 
 
2076
    liblas::guid* id1 = (liblas::guid*)hId1;
 
2077
    liblas::guid* id2 = (liblas::guid*)hId2;
 
2078
    try {
 
2079
 
 
2080
        return( *id1 == *id2);
 
2081
    }
 
2082
    catch (std::exception const& e) {
 
2083
        LASError_PushError(LE_Failure, e.what(), "LASGuid_Equals");
 
2084
        return LE_Failure;
 
2085
    }
 
2086
}
 
2087
 
 
2088
LAS_DLL char* LASGuid_AsString(LASGuidH hId) {
 
2089
    VALIDATE_LAS_POINTER1(hId, "LASGuid_AsString", 0);
 
2090
    liblas::guid* id= (liblas::guid*)hId;
 
2091
    return LASCopyString(id->to_string().c_str());
 
2092
}
 
2093
 
 
2094
 
 
2095
 
 
2096
LAS_DLL LASColorH LASColor_Create(void) {
 
2097
    return (LASColorH) new liblas::Color();
 
2098
}
 
2099
 
 
2100
LAS_DLL void LASColor_Destroy(LASColorH hColor){
 
2101
    VALIDATE_LAS_POINTER0(hColor, "LASColor_Destroy");
 
2102
    delete (liblas::Color*)hColor;
 
2103
    hColor = NULL;
 
2104
}
 
2105
 
 
2106
LAS_DLL LASErrorEnum LASColor_SetRed(LASColorH hColor, boost::uint16_t value) {
 
2107
    
 
2108
    VALIDATE_LAS_POINTER1(hColor, "LASColor_SetRed", LE_Failure);
 
2109
 
 
2110
    try {
 
2111
        liblas::Color* color = ((liblas::Color*) hColor);
 
2112
        color->SetRed(value);
 
2113
    }
 
2114
    catch (std::exception const& e) {
 
2115
        LASError_PushError(LE_Failure, e.what(), "LASColor_SetRed");
 
2116
        return LE_Failure;
 
2117
    }
 
2118
 
 
2119
    return LE_None;
 
2120
}
 
2121
 
 
2122
LAS_DLL boost::uint16_t LASColor_GetRed(LASColorH hColor) {
 
2123
    
 
2124
    VALIDATE_LAS_POINTER1(hColor, "LASColor_GetRed", 0);
 
2125
    
 
2126
    boost::uint16_t value = ((liblas::Color*) hColor)->GetRed();
 
2127
    return value;
 
2128
}
 
2129
 
 
2130
LAS_DLL LASErrorEnum LASColor_SetBlue(LASColorH hColor, boost::uint16_t value) {
 
2131
    
 
2132
    VALIDATE_LAS_POINTER1(hColor, "LASColor_SetBlue", LE_Failure);
 
2133
 
 
2134
    try {
 
2135
        liblas::Color* color = ((liblas::Color*) hColor);
 
2136
        color->SetBlue(value);
 
2137
    }
 
2138
    catch (std::exception const& e) {
 
2139
        LASError_PushError(LE_Failure, e.what(), "LASColor_SetBlue");
 
2140
        return LE_Failure;
 
2141
    }
 
2142
 
 
2143
    return LE_None;
 
2144
}
 
2145
 
 
2146
LAS_DLL boost::uint16_t LASColor_GetBlue(LASColorH hColor) {
 
2147
    
 
2148
    VALIDATE_LAS_POINTER1(hColor, "LASColor_GetBlue", 0);
 
2149
    
 
2150
    boost::uint16_t value = ((liblas::Color*) hColor)->GetBlue();
 
2151
    return value;
 
2152
}
 
2153
 
 
2154
LAS_DLL LASErrorEnum LASColor_SetGreen(LASColorH hColor, boost::uint16_t value) {
 
2155
    
 
2156
    VALIDATE_LAS_POINTER1(hColor, "LASColor_SetGreen", LE_Failure);
 
2157
 
 
2158
    try {
 
2159
        liblas::Color* color = ((liblas::Color*) hColor);
 
2160
        color->SetGreen(value);
 
2161
    }
 
2162
    catch (std::exception const& e) {
 
2163
        LASError_PushError(LE_Failure, e.what(), "LASColor_SetGreen");
 
2164
        return LE_Failure;
 
2165
    }
 
2166
 
 
2167
    return LE_None;
 
2168
}
 
2169
 
 
2170
LAS_DLL boost::uint16_t LASColor_GetGreen(LASColorH hColor) {
 
2171
    
 
2172
    VALIDATE_LAS_POINTER1(hColor, "LASColor_GetGreen", 0);
 
2173
    
 
2174
    boost::uint16_t value = ((liblas::Color*) hColor)->GetGreen();
 
2175
    return value;
 
2176
}
 
2177
 
 
2178
LAS_DLL LASColorH LASPoint_GetColor(const LASPointH hPoint) {
 
2179
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_GetColor", 0);
 
2180
    
 
2181
    liblas::Color color;
 
2182
    try {
 
2183
        color = ((liblas::Point*) hPoint)->GetColor();
 
2184
        
 
2185
    } catch (std::runtime_error const&) 
 
2186
    {
 
2187
        
 
2188
    }
 
2189
    return (LASColorH) new liblas::Color(color);
 
2190
}
 
2191
 
 
2192
LAS_DLL LASErrorEnum LASPoint_SetColor(LASPointH hPoint, const LASColorH hColor) {
 
2193
    
 
2194
    VALIDATE_LAS_POINTER1(hPoint, "LASPoint_SetColor", LE_Failure);
 
2195
    VALIDATE_LAS_POINTER1(hColor, "LASPoint_SetColor", LE_Failure);
 
2196
 
 
2197
    try {
 
2198
        ((liblas::Point*) hPoint)->SetColor(*((liblas::Color*)hColor));
 
2199
    }
 
2200
    catch (std::runtime_error const&) 
 
2201
    {
 
2202
        // drop the value on the floor.  If the point has a schema that 
 
2203
        // doesn't have color, the user needs to change the point's header.
 
2204
        
 
2205
    }
 
2206
    catch (std::exception const& e) {
 
2207
        LASError_PushError(LE_Failure, e.what(), "LASPoint_SetColor");
 
2208
        return LE_Failure;
 
2209
    }
 
2210
 
 
2211
    return LE_None;
 
2212
}
 
2213
 
 
2214
LAS_DLL LASSRSH LASSRS_Create(void) {
 
2215
    return (LASSRSH) new liblas::SpatialReference();
 
2216
}
 
2217
 
 
2218
LAS_DLL void LASSRS_Destroy(LASSRSH hSRS){
 
2219
    VALIDATE_LAS_POINTER0(hSRS, "LASSRS_Destroy");
 
2220
    delete (liblas::SpatialReference*)hSRS;
 
2221
    hSRS = NULL;
 
2222
}
 
2223
 
 
2224
LAS_DLL const void* LASSRS_GetGTIF(LASSRSH hSRS) {
 
2225
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetGTIF", 0);
 
2226
    
 
2227
    try {
 
2228
        return (const void *) ((liblas::SpatialReference*) hSRS)->GetGTIF();
 
2229
    }
 
2230
    catch (std::exception const& e) {
 
2231
        LASError_PushError(LE_Failure, e.what(), "LASSRS_GetGTIF");
 
2232
        return 0;
 
2233
    }
 
2234
}
 
2235
 
 
2236
LAS_DLL LASErrorEnum LASSRS_SetGTIF(LASSRSH hSRS, const void* pgtiff, const void* ptiff)
 
2237
{
 
2238
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_SetGTIF", LE_Failure);
 
2239
    VALIDATE_LAS_POINTER1(pgtiff, "LASSRS_SetGTIF", LE_Failure);
 
2240
    VALIDATE_LAS_POINTER1(ptiff, "LASSRS_SetGTIF", LE_Failure);
 
2241
    try {
 
2242
        const GTIF* cgtiff = static_cast<const GTIF*>(pgtiff);
 
2243
        const ST_TIFF* ctiff = static_cast<const ST_TIFF*>(ptiff);
 
2244
        GTIF* gtiff = const_cast<GTIF*>(cgtiff);
 
2245
        ST_TIFF* tiff = const_cast<ST_TIFF*>(ctiff);
 
2246
        
 
2247
        ((liblas::SpatialReference*) hSRS)->SetGTIF(gtiff, tiff);
 
2248
    }
 
2249
    catch (std::exception const& e) {
 
2250
        LASError_PushError(LE_Failure, e.what(), "LASSRS_SetGTIF");
 
2251
        return LE_Failure;
 
2252
    }
 
2253
 
 
2254
    return LE_None;    
 
2255
}
 
2256
LAS_DLL char* LASSRS_GetProj4(LASSRSH hSRS) 
 
2257
{
 
2258
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetProj4", NULL);
 
2259
    liblas::SpatialReference* srs = (liblas::SpatialReference*)hSRS;
 
2260
 
 
2261
    return LASCopyString((srs)->GetProj4().c_str());
 
2262
    
 
2263
}
 
2264
 
 
2265
LAS_DLL LASErrorEnum LASSRS_SetProj4(LASSRSH hSRS, const char* value)
 
2266
{
 
2267
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_SetProj4", LE_Failure);
 
2268
    VALIDATE_LAS_POINTER1(value, "LASSRS_SetProj4", LE_Failure);
 
2269
 
 
2270
    try {
 
2271
         ((liblas::SpatialReference*) hSRS)->SetProj4(value);
 
2272
    }
 
2273
    catch (std::exception const& e) {
 
2274
        LASError_PushError(LE_Failure, e.what(), "LASSRS_SetProj4");
 
2275
        return LE_Failure;
 
2276
    }
 
2277
 
 
2278
    return LE_None;
 
2279
}
 
2280
 
 
2281
LAS_DLL char* LASSRS_GetWKT(LASSRSH hSRS) 
 
2282
{
 
2283
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetWKT", NULL);
 
2284
    liblas::SpatialReference* srs = (liblas::SpatialReference*)hSRS;
 
2285
 
 
2286
    return LASCopyString((srs)->GetWKT(liblas::SpatialReference::eHorizontalOnly).c_str());
 
2287
    
 
2288
}
 
2289
 
 
2290
LAS_DLL char* LASSRS_GetWKT_CompoundOK(LASSRSH hSRS) 
 
2291
{
 
2292
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetWKT_CompoundOK", NULL);
 
2293
    liblas::SpatialReference* srs = (liblas::SpatialReference*)hSRS;
 
2294
 
 
2295
    return LASCopyString((srs)->GetWKT(liblas::SpatialReference::eCompoundOK).c_str());
 
2296
    
 
2297
}
 
2298
 
 
2299
LAS_DLL LASErrorEnum LASSRS_SetWKT(LASSRSH hSRS, const char* value)
 
2300
{
 
2301
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_SetWKT", LE_Failure);
 
2302
    VALIDATE_LAS_POINTER1(value, "LASSRS_SetWKT", LE_Failure);
 
2303
 
 
2304
    try {
 
2305
         ((liblas::SpatialReference*) hSRS)->SetWKT(value);
 
2306
    }
 
2307
    catch (std::exception const& e) {
 
2308
        LASError_PushError(LE_Failure, e.what(), "LASSRS_SetWKT");
 
2309
        return LE_Failure;
 
2310
    }
 
2311
 
 
2312
    return LE_None;
 
2313
}
 
2314
 
 
2315
LAS_DLL LASErrorEnum LASSRS_SetVerticalCS(LASSRSH hSRS, 
 
2316
                                          int verticalCSType,
 
2317
                                          const char *citation,
 
2318
                                          int verticalDatum, 
 
2319
                                          int verticalUnits ) {
 
2320
    
 
2321
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_SetVerticalCS", LE_Failure);
 
2322
 
 
2323
    try {
 
2324
        ((liblas::SpatialReference*) hSRS)->SetVerticalCS( verticalCSType, citation,
 
2325
                                                      verticalDatum, 
 
2326
                                                      verticalUnits);
 
2327
    }
 
2328
    catch (std::exception const& e) {
 
2329
        LASError_PushError(LE_Failure, e.what(), "LASSRS_SetVerticalCS");
 
2330
        return LE_Failure;
 
2331
    }
 
2332
 
 
2333
    return LE_None;
 
2334
}
 
2335
 
 
2336
LAS_DLL LASErrorEnum LASSRS_SetFromUserInput(LASSRSH hSRS, const char* value)
 
2337
{
 
2338
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_SetFromUserInput", LE_Failure);
 
2339
    VALIDATE_LAS_POINTER1(value, "LASSRS_SetFromUserInput", LE_Failure);
 
2340
 
 
2341
    try {
 
2342
         ((liblas::SpatialReference*) hSRS)->SetFromUserInput(value);
 
2343
    }
 
2344
    catch (std::exception const& e) {
 
2345
        LASError_PushError(LE_Failure, e.what(), "LASSRS_SetFromUserInput");
 
2346
        return LE_Failure;
 
2347
    }
 
2348
 
 
2349
    return LE_None;
 
2350
}
 
2351
 
 
2352
LAS_DLL LASErrorEnum LASSRS_AddVLR(LASSRSH hSRS, const LASVLRH hVLR) {
 
2353
    
 
2354
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_AddVLR", LE_Failure);
 
2355
    VALIDATE_LAS_POINTER1(hVLR, "LASSRS_AddVLR", LE_Failure);
 
2356
 
 
2357
    try {
 
2358
        ((liblas::SpatialReference*) hSRS)->AddVLR(*((liblas::VariableRecord*)hVLR));
 
2359
    }
 
2360
    catch (std::exception const& e) {
 
2361
        LASError_PushError(LE_Failure, e.what(), "LASSRS_AddVLR");
 
2362
        return LE_Failure;
 
2363
    }
 
2364
 
 
2365
    return LE_None;
 
2366
}
 
2367
 
 
2368
LAS_DLL LASVLRH LASSRS_GetVLR(const LASSRSH hSRS, boost::uint32_t i) {
 
2369
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetVLR", 0);
 
2370
    
 
2371
    liblas::VariableRecord vlr = ((liblas::SpatialReference*) hSRS)->GetVLRs()[i];
 
2372
    return (LASVLRH) new liblas::VariableRecord(vlr);
 
2373
}
 
2374
 
 
2375
LAS_DLL boost::uint32_t LASSRS_GetVLRCount(const LASSRSH hSRS) {
 
2376
    VALIDATE_LAS_POINTER1(hSRS, "LASSRS_GetVLR", 0);
 
2377
    
 
2378
    using boost::uint32_t;
 
2379
    uint32_t size = static_cast<uint32_t>(((liblas::SpatialReference*) hSRS)->GetVLRs().size());
 
2380
    return size;
 
2381
}
 
2382
 
 
2383
LAS_DLL LASErrorEnum LASHeader_SetSRS(LASHeaderH hHeader, const LASSRSH hSRS) {
 
2384
    
 
2385
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetSRS", LE_Failure);
 
2386
    VALIDATE_LAS_POINTER1(hSRS, "LASHeader_SetSRS", LE_Failure);
 
2387
 
 
2388
    try {
 
2389
        ((liblas::HeaderPtr*) hHeader)->get()->SetSRS(*((liblas::SpatialReference*)hSRS));
 
2390
    }
 
2391
    catch (std::exception const& e) {
 
2392
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetSRS");
 
2393
        return LE_Failure;
 
2394
    }
 
2395
 
 
2396
 
 
2397
    return LE_None;
 
2398
}
 
2399
 
 
2400
LAS_DLL LASSRSH LASHeader_GetSRS(const LASHeaderH hHeader) {
 
2401
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetSRS", 0);
 
2402
    
 
2403
    liblas::SpatialReference srs = ((liblas::HeaderPtr*) hHeader)->get()->GetSRS();
 
2404
    return (LASSRSH) new liblas::SpatialReference(srs);
 
2405
}
 
2406
 
 
2407
 
 
2408
LAS_DLL void LASString_Free(char* string) {
 
2409
    if (string)
 
2410
        free(string);
 
2411
}
 
2412
 
 
2413
 
 
2414
LAS_DLL LASSchemaH LASSchema_Create(  liblas::PointFormatName point_format) {
 
2415
    liblas::Schema* schema = new liblas::Schema(point_format);
 
2416
    return (LASSchemaH) schema;
 
2417
}
 
2418
 
 
2419
 
 
2420
LAS_DLL unsigned int LASSchema_GetByteSize( LASSchemaH hFormat)
 
2421
{
 
2422
    VALIDATE_LAS_POINTER1(hFormat, "LASSchema_GetByteSize", 0);
 
2423
    
 
2424
    liblas::Schema* format = ((liblas::Schema*) hFormat);
 
2425
    return static_cast<unsigned int>(format->GetByteSize());    
 
2426
}
 
2427
 
 
2428
 
 
2429
LAS_DLL unsigned int LASSchema_GetBaseByteSize( LASSchemaH hFormat)
 
2430
{
 
2431
    VALIDATE_LAS_POINTER1(hFormat, "LASSchema_GetBaseByteSize", 0);
 
2432
    
 
2433
    liblas::Schema* format = ((liblas::Schema*) hFormat);
 
2434
    return static_cast<unsigned int>(format->GetBaseByteSize());    
 
2435
}
 
2436
 
 
2437
 
 
2438
LAS_DLL void LASSchema_Destroy(LASSchemaH hFormat) {
 
2439
    VALIDATE_LAS_POINTER0(hFormat, "LASSchema_Destroy");
 
2440
    delete (liblas::Schema*) hFormat;
 
2441
    hFormat = NULL;    
 
2442
}
 
2443
 
 
2444
LAS_DLL LASSchemaH LASHeader_GetSchema( LASHeaderH hHeader )
 
2445
{
 
2446
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_GetSchema", 0);
 
2447
    
 
2448
    liblas::Schema format = ((liblas::HeaderPtr*) hHeader)->get()->GetSchema();
 
2449
    return (LASSchemaH) new liblas::Schema(format);
 
2450
 
 
2451
}
 
2452
 
 
2453
LAS_DLL LASErrorEnum LASHeader_SetSchema( LASHeaderH hHeader, const LASSchemaH hFormat)
 
2454
{
 
2455
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetSchema", LE_Failure);
 
2456
    VALIDATE_LAS_POINTER1(hFormat, "LASHeader_SetSchema", LE_Failure);
 
2457
    
 
2458
    try {
 
2459
        ((liblas::HeaderPtr*) hHeader)->get()->SetSchema(*((liblas::Schema*)hFormat));
 
2460
    }
 
2461
    catch (std::exception const& e) {
 
2462
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetSchema");
 
2463
        return LE_Failure;
 
2464
    }
 
2465
 
 
2466
    return LE_None;
 
2467
}
 
2468
 
 
2469
LAS_DLL int LASHeader_Compressed(const LASHeaderH hHeader )
 
2470
{
 
2471
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_Compressed", 0);
 
2472
    return ((liblas::HeaderPtr*) hHeader)->get()->Compressed();
 
2473
}
 
2474
 
 
2475
LAS_DLL LASErrorEnum LASHeader_SetCompressed( LASHeaderH hHeader, int value)
 
2476
{
 
2477
    VALIDATE_LAS_POINTER1(hHeader->get(), "LASHeader_SetCompressed", LE_Failure);
 
2478
    
 
2479
    try {
 
2480
        bool v(false);
 
2481
        if (value == 0) v = false;
 
2482
        else v = true;
 
2483
      ((liblas::HeaderPtr*) hHeader)->get()->SetCompressed(v);
 
2484
    }
 
2485
    catch (std::exception const& e) {
 
2486
        LASError_PushError(LE_Failure, e.what(), "LASHeader_SetCompressed");
 
2487
        return LE_Failure;
 
2488
    }
 
2489
 
 
2490
    return LE_None;
 
2491
}
 
2492
    
 
2493
 
 
2494
LAS_C_END
 
2495
 
 
2496
#ifdef _MSC_VER
 
2497
# pragma warning(default: 4127) // enable warning C4127: conditional expression is constant
 
2498
# pragma warning(default: 4702)  // unreachable code
 
2499
#endif