1
/******************************************************************************
4
* Project: libLAS - http://liblas.org - A BSD library for LAS format data.
6
* Author: Martin Vales, martin_gnu@mundo-r.com
8
******************************************************************************
9
* Copyright (c) 2008, Martin Vales
11
* All rights reserved.
13
* Redistribution and use in source and binary forms, with or without
14
* modification, are permitted provided that the following
17
* * Redistributions of source code must retain the above copyright
18
* notice, this list of conditions and the following disclaimer.
19
* * Redistributions in binary form must reproduce the above copyright
20
* notice, this list of conditions and the following disclaimer in
21
* the documentation and/or other materials provided
22
* with the distribution.
23
* * Neither the name of the Martin Isenburg or Iowa Department
24
* of Natural Resources nor the names of its contributors may be
25
* used to endorse or promote products derived from this software
26
* without specific prior written permission.
28
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
35
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
40
****************************************************************************/
43
using System.Collections.Generic;
45
using LASError = System.Int32;
46
using LASWriterH = System.IntPtr;
47
using LASReaderH = System.IntPtr;
48
using LASPointH = System.IntPtr;
49
using LASGuidH = System.IntPtr;
50
using LASVLRH = System.IntPtr;
51
using LASHeaderH = System.IntPtr;
58
public class LASHeader : IDisposable
62
/// The object user should call this method when they finished with the object.
63
/// In .NET is magaged by the GC.
68
CAPI.LASHeader_Destroy(hHeader);
69
// Clean up unmanaged resources here.
70
// Dispose other contained disposable objects.
75
/// Minimum of major component
77
///Maximum of major component
79
/// Minimum of minor component
81
/// Maximum of minor component
85
/// Versions of point record format.
86
public enum PointFormat
88
///Point Data Format \e 0
90
/// Point Data Format \e 1
94
/// Number of bytes of point record storage in particular format.
97
///Size of point record in data format \e 0
99
/// Size of point record in data format \e 1
103
//// Official signature of ASPRS LAS file format, always \b "LASF".
104
//public static readonly string FileSignature_;
106
//// Default system identifier used by libLAS, always \b "libLAS".
107
//public static readonly string SystemIdentifier;
109
////Default software identifier used by libLAS, always \b "libLAS X.Y".
110
//public static readonly string SoftwareIdentifier;
112
private LASHeaderH hHeader;
115
/// gets the opaque pointer to the LASHeaderH instance.
117
/// <returns>opaque pointer to the LASHeaderH instance.</returns>
118
internal LASHeaderH GetPointer()
124
/// LASHeader constructor using the LASHeaderH opaque pointer.
126
/// <param name="hLASHeader"></param>
127
public LASHeader(LASHeaderH hLASHeader)
129
hHeader = hLASHeader;
133
/// Default constructor.
135
/// <remarks>The default constructed header is configured according
136
/// to the ASPRS LAS 1.1 Specification, point data format set to 0.
137
/// Other fields filled with 0.</remarks>
140
hHeader = CAPI.LASHeader_Create();
144
/// Copy the LASHeader in a new instance
146
/// <returns>new LASHeader instance.</returns>
147
public LASHeader Copy()
149
return new LASHeader(CAPI.LASHeader_Copy(hHeader));
153
/// Destroy the unmanaged resources to the instance.
155
/// <remarks>The user could call this method when they finished with the object.</remarks>
156
public void Destroy()
158
CAPI.LASHeader_Destroy(hHeader);
162
/// Comparison overload to the LASHeader
164
/// <param name="lasHeader1">LASHeader instance to be compared</param>
165
/// <param name="lasHeader2">LASHeader instance to be compared</param>
166
/// <returns>true if lasHeader1==lasHeader2</returns>
167
public static bool operator ==(LASHeader lasHeader1, LASHeader lasHeader2)
169
return lasHeader1.Equals(lasHeader2);
173
/// Comparison overload to the LASHeader
175
/// <param name="lasHeader1">LASHeader instance to be compared</param>
176
/// <param name="lasHeader2">LASHeader instance to be compared</param>
177
/// <returns></returns>
178
public static bool operator !=(LASHeader lasHeader1, LASHeader lasHeader2)
180
return !(lasHeader1 == lasHeader2);
184
/// Get ASPRS LAS file signature.
186
/// <remarks>The only value allowed as file signature is "LASF",</remarks>
187
public string FileSignature
191
return CAPI.LASHeader_GetFileSignature(hHeader);
196
/// file source identifier.
198
/// <remarks> should be set to a value between 1 and 65535.</remarks>
199
public UInt16 FileSourceId
203
return CAPI.LASHeader_GetFileSourceId(hHeader);
207
LASError error = CAPI.LASHeader_SetFileSourceId(hHeader, value);
208
if ((Int32)error != 0)
210
LASException e = new LASException("Exception in Set Header SetFileSourceId.");
217
/// Get value field reserved by the ASPRS LAS Specification.
219
/// <remarks>This field is always filled with 0.</remarks>
220
public Int16 Reserved
224
return CAPI.LASHeader_GetReserved(hHeader);
229
/// Get project identifier.
231
/// <remarks>return Global Unique Identifier.</remarks>
232
public String ProjectId
236
return CAPI.LASHeader_GetProjectId(hHeader);
241
/// major component of version of LAS format.
243
/// <remarks>Always 1 as the only valid value. value between
244
/// eVersionMajorMin and eVersionMajorMax (always 1).</remarks>
245
public byte VersionMajor
249
return CAPI.LASHeader_GetVersionMajor(hHeader);
253
LASError error = CAPI.LASHeader_SetVersionMajor(hHeader, value);
254
if ((Int32)error != 0)
256
LASException e = new LASException("Exception in Set Header VersionMajor.");
263
/// minor component of version of LAS format.
265
/// <remarks>Valid values are 1 or 0. value between
266
/// eVersionMinorMin and eVersionMinorMax.</remarks>
267
public byte VersionMinor
272
return CAPI.LASHeader_GetVersionMinor(hHeader);
276
LASError error = CAPI.LASHeader_SetVersionMinor(hHeader, value);
277
if ((Int32)error != 0)
279
LASException e = new LASException("Exception in Set Header VersionMinor.");
286
/// system identifier
288
/// <remarks>Default value is "libLAS" specified as the SystemIdentifier constant.
289
/// string is padded right with spaces and its length is 32 bytes.</remarks>
290
public String SystemId
294
return CAPI.LASHeader_GetSystemId(hHeader);
298
LASError error = CAPI.LASHeader_SetSystemId(hHeader, value);
299
if ((Int32)error != 0)
301
LASException e = new LASException("Exception in Set Header SystemId.");
308
/// software identifier
310
/// <remarks>Default value is "libLAS 1.0", specified as the SoftwareIdentifier constant.
311
/// String is padded right with spaces and its length is 32 bytes.</remarks>
312
public String SoftwareId
317
return CAPI.LASHeader_GetSoftwareId(hHeader);
321
LASError error = CAPI.LASHeader_SetSoftwareId(hHeader, value);
322
if ((Int32)error != 0)
324
LASException e = new LASException("Exception in Set Header SoftwareId.");
331
/// day of year of file creation date.
333
/// <remarks>Use full date structure instead of Julian date number.
334
/// value is lower than number 366.</remarks>
335
public UInt16 CreationDOY
339
return CAPI.LASHeader_GetCreationDOY(hHeader);
343
LASError error = CAPI.LASHeader_SetCreationDOY(hHeader, value);
344
if ((Int32)error != 0)
346
LASException e = new LASException("Exception in Set Header CreationDOY.");
353
/// year of file creation date.
355
/// <remarks>value is lower than number 9999.</remarks>
356
public UInt16 CreationYear
360
return CAPI.LASHeader_GetCreationYear(hHeader);
364
LASError error = CAPI.LASHeader_SetCreationYear(hHeader, value);
365
if ((Int32)error != 0)
367
LASException e = new LASException("Exception in Set Header CreationYear.");
374
/// number of bytes of generic verion of public header block storage.
376
/// <remarks>Standard version of the public header block is 227 bytes long.</remarks>
377
public UInt16 HeaderSize
381
return CAPI.LASHeader_GetHeaderSize(hHeader);
386
/// number of bytes from the beginning to the first point record.
388
public UInt32 DataOffset
392
return CAPI.LASHeader_GetDataOffset(hHeader);
397
/// Returns the number of variable length records in the header
399
public UInt32 VariableLengthRecordsCount
403
return CAPI.LASHeader_GetRecordsCount(hHeader);
408
/// the data format id for the file.
410
/// <remarks>The value should be 1 or 0, with 1 being points that contain
411
/// time values and 0 being points that do not.</remarks>
412
public byte DataFormatId
416
return CAPI.LASHeader_GetDataFormatId(hHeader);
420
LASError error = CAPI.LASHeader_SetDataFormatId(hHeader, value);
421
if ((Int32)error != 0)
423
LASException e = new LASException("Exception in Set Header DataFormatId.");
430
/// return the record length for the points based on their data format id in bytes.
432
public UInt16 DataRecordLength
436
return CAPI.LASHeader_GetDataRecordLength(hHeader);
441
/// number of point records in the file.
443
/// <remarks>This value may not reflect the actual number of point
444
/// records in the file.</remarks>
445
public UInt32 PointRecordsCount
449
//Get total number of point records stored in the LAS file.
450
return CAPI.LASHeader_GetPointRecordsCount(hHeader);
454
//Set number of point records that will be stored in a new LAS file.
455
LASError error = CAPI.LASHeader_SetPointRecordsCount(hHeader, value);
456
if ((Int32)error != 0)
458
LASException e = new LASException("Exception in Set Header PointRecordsCount.");
465
/// Returns the number of point records by return.
467
/// <param name="index">the return number to fetch the count for</param>
468
/// <returns>the number of point records for a given return</returns>
469
public UInt32 GetPointRecordsByReturnCount(int index)
471
// Get array of the total point records per return.
472
return CAPI.LASHeader_GetPointRecordsByReturnCount(hHeader, index);
475
// /// Set values of 5-elements array of total point records per return.
476
// /// \exception std::out_of_range - if index is bigger than 4.
477
// /// \param index - subscript (0-4) of array element being updated.
478
// /// \param v - new value to assign to array element identified by index.
480
/// Sets the number of point records for a given return
482
/// <param name="index">the return number to set the count for</param>
483
/// <param name="value">the number of point records for the return </param>
484
public void SetPointRecordsByReturnCount(int index, UInt32 value)
486
LASError error = CAPI.LASHeader_SetPointRecordsByReturnCount(hHeader, index, value);
487
if ((Int32)error != 0)
489
LASException e = new LASException("Exception in Set Header SetPointRecordsByReturnCount.");
495
/// Get scale factor for X coordinate.
497
/// <returns>scale factor for X coordinate.</returns>
498
public double GetScaleX()
500
return CAPI.LASHeader_GetScaleX(hHeader);
504
/// Get scale factor for Y coordinate.
506
/// <returns>scale factor for Y coordinate.</returns>
507
public double GetScaleY()
509
return CAPI.LASHeader_GetScaleY(hHeader);
513
/// Get scale factor for Z coordinate.
515
/// <returns>scale factor for Z coordinate.</returns>
516
public double GetScaleZ()
518
return CAPI.LASHeader_GetScaleZ(hHeader);
522
/// Set values of scale factor for X, Y and Z coordinates.
524
/// <param name="x">X scale factor of the coordinate</param>
525
/// <param name="y">Y scale factor of the coordinate</param>
526
/// <param name="z">Z scale factor of the coordinate</param>
527
public void SetScale(double x, double y, double z)
529
LASError error = CAPI.LASHeader_SetScale(hHeader, x, y, z);
530
if ((Int32)error != 0)
532
LASException e = new LASException("Exception in Set Header SetScale.");
538
/// Get X coordinate offset.
540
/// <returns>X coordinate offset.</returns>
541
public double GetOffsetX()
543
return CAPI.LASHeader_GetOffsetX(hHeader);
547
/// Get Y coordinate offset.
549
/// <returns>Y coordinate offset.</returns>
550
public double GetOffsetY()
552
return CAPI.LASHeader_GetOffsetY(hHeader);
556
/// Get Z coordinate offset.
558
/// <returns>Z coordinate offset.</returns>
559
public double GetOffsetZ()
561
return CAPI.LASHeader_GetOffsetZ(hHeader);
564
//Set values of X, Y and Z coordinates offset.
566
/// Set values of X, Y and Z coordinates offset.
568
/// <param name="x">X coordinate offset.</param>
569
/// <param name="y">Y coordinate offset.</param>
570
/// <param name="z">Z coordinate offset.</param>
571
public void SetOffset(double x, double y, double z)
573
LASError error = CAPI.LASHeader_SetOffset(hHeader, x, y, z);
574
if ((Int32)error != 0)
576
LASException e = new LASException("Exception in Set Header SetOffset.");
582
/// Get maximum value of extent of X coordinate.
584
/// <returns>maximum value of extent of X coordinate.</returns>
587
return CAPI.LASHeader_GetMaxX(hHeader);
591
/// Get maximum value of extent of Y coordinate.
593
/// <returns>maximum value of extent of Y coordinate.</returns>
594
public double GetMaxY()
596
return CAPI.LASHeader_GetMaxY(hHeader);
600
/// Get maximum value of extent of Z coordinate.
602
/// <returns>maximum value of extent of Z coordinate.</returns>
603
public double GetMaxZ()
605
return CAPI.LASHeader_GetMaxZ(hHeader);
609
/// Get minimum value of extent of X coordinate.
611
/// <returns>minimum value of extent of X coordinate.</returns>
612
public double GetMinX()
614
return CAPI.LASHeader_GetMinX(hHeader);
618
/// Get minimum value of extent of Y coordinate.
620
/// <returns>minimum value of extent of Y coordinate.</returns>
621
public double GetMinY()
623
return CAPI.LASHeader_GetMinY(hHeader);
627
/// Get minimum value of extent of Z coordinate.
629
/// <returns>minimum value of extent of Z coordinate.</returns>
630
public double GetMinZ()
632
return CAPI.LASHeader_GetMinZ(hHeader);
636
/// Set maximum values of extent of X, Y and Z coordinates.
638
/// <param name="x">maximum value of extent of X coordinate.</param>
639
/// <param name="y">maximum value of extent of Y coordinate.</param>
640
/// <param name="z">maximum value of extent of Z coordinate.</param>
641
public void SetMax(double x, double y, double z)
643
LASError error = CAPI.LASHeader_SetMax(hHeader, x, y, z);
644
if ((Int32)error != 0)
646
LASException e = new LASException("Exception in Set Header SetMax.");
652
/// Set minimum values of extent of X, Y and Z coordinates.
654
/// <param name="x">Set minimum value of extent of X coordinate.</param>
655
/// <param name="y">Set minimum value of extent of Y coordinate.</param>
656
/// <param name="z">Set minimum value of extent of Z coordinate.</param>
657
public void SetMin(double x, double y, double z)
659
LASError error = CAPI.LASHeader_SetMin(hHeader, x, y, z);
660
if ((Int32)error != 0)
662
LASException e = new LASException("Exception in Set Header SetMin.");
668
/// Adds a variable length record instance to the header.
670
/// <param name="variableLengthRecord">variable Length record instance to add</param>
671
public void AddVariableLengthRecord(LASVariableLengthRecord variableLengthRecord)
673
LASError error = CAPI.LASHeader_AddVLR(hHeader, variableLengthRecord.GetPointer());
674
if ((Int32)error != 0)
676
LASException e = new LASException("Exception in Header AddVariableLengthRecord.");
682
/// Returns the variable length record for the given index.
684
/// <param name="i">the index starting from 0 of the variable length record to fetch</param>
685
/// <returns>a new variable length record instance</returns>
686
/// <remarks>Use VariableLengthRecordsCount property to determine the number of
687
/// variable length records available on the header.</remarks>
688
public LASVariableLengthRecord GetVariableLengthRecord(UInt32 i)
690
LASVLRH vlrh = CAPI.LASHeader_GetVLR(hHeader, i);
691
return new LASVariableLengthRecord(vlrh);
695
/// Deletes a variable length record from the header for the given index.
697
/// <param name="index">the index starting from 0 of the variable length record to delete</param>
698
public void DeleteVariableLengthRecord(UInt32 index)
700
LASError error = CAPI.LASHeader_DeleteVLR(hHeader, index);
701
if ((Int32)error != 0)
703
LASException e = new LASException("Exception in Header DeleteVariableLengthRecord.");
709
/// GUID value for the header.
711
/// <remarks>sets and gets the LASGuid instance of the header.</remarks>
716
LASGuidH guidh = CAPI.LASHeader_GetGUID(hHeader);
717
return new LASGuid(guidh);
722
LASError error = CAPI.LASHeader_SetGUID(hHeader, value.GetPointer());
723
if ((Int32)error != 0)
725
LASException e = new LASException("Exception in Set Header GUID.");
732
/// sets and gets the Proj4 in the header.
738
return CAPI.LASHeader_GetProj4(hHeader);
742
LASError error = CAPI.LASHeader_SetProj4(hHeader, value);
743
if ((Int32)error != 0)
745
LASException e = new LASException("Exception in Set Header Proj4.");