~ubuntu-branches/ubuntu/utopic/liblas/utopic

« back to all changes in this revision

Viewing changes to csharp/dotnetLibLAS/LASVariableLengthRecord.cs

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2013-11-26 16:03:56 UTC
  • mto: (2.1.1 experimental) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20131126160356-r94gc8jmp4lm0yix
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

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:  
 
6
 * Author:   Martin Vales, martin_gnu@mundo-r.com
 
7
 *
 
8
 ******************************************************************************
 
9
 * Copyright (c) 2008, Martin Vales
 
10
 *
 
11
 * All rights reserved.
 
12
 * 
 
13
 * Redistribution and use in source and binary forms, with or without 
 
14
 * modification, are permitted provided that the following 
 
15
 * conditions are met:
 
16
 * 
 
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.
 
27
 * 
 
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 
 
39
 * OF SUCH DAMAGE.
 
40
 ****************************************************************************/
 
41
 
 
42
using System;
 
43
using System.Collections.Generic;
 
44
using System.Text;
 
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;
 
52
 
 
53
namespace LibLAS
 
54
{
 
55
    /// <summary>
 
56
    /// LASVariableLengthRecord class
 
57
    /// </summary>
 
58
    public class LASVariableLengthRecord : IDisposable
 
59
    {
 
60
        private LASVLRH hvlrh;
 
61
 
 
62
        /// <summary>
 
63
        /// The object user should call this method when they finished with the object.
 
64
        /// </summary>
 
65
        public void Dispose()
 
66
        {
 
67
            CAPI.LASVLR_Destroy(hvlrh);
 
68
            // Clean up unmanaged resources here.
 
69
            // Dispose other contained disposable objects.
 
70
        }
 
71
 
 
72
        /// <summary>
 
73
        /// Default constructor.
 
74
        /// </summary>
 
75
        public LASVariableLengthRecord()
 
76
        {
 
77
            hvlrh = CAPI.LASVLR_Create();
 
78
        }
 
79
 
 
80
        /// <summary>
 
81
        /// Creates a new variable length record uing the LASVLRH opaque pointer
 
82
        /// </summary>
 
83
        /// <param name="hVlrh">LASVLRH opaque pointer</param>
 
84
        public LASVariableLengthRecord(LASVLRH hVlrh)
 
85
        {
 
86
            hvlrh = hVlrh;
 
87
        }
 
88
 
 
89
        //public override string ToString()
 
90
        //{
 
91
        //    return CAPI.LASGuid_AsString(hguid);
 
92
        //}
 
93
 
 
94
        /// <summary>
 
95
        /// Get the LASVLRH opaque pointer.
 
96
        /// </summary>
 
97
        /// <returns>LASVLRH opaque pointer </returns>
 
98
        public LASVLRH GetPointer()
 
99
        {
 
100
            return hvlrh;
 
101
        }
 
102
 
 
103
        /// <summary>
 
104
        /// the User Id for the variable length record.
 
105
        /// </summary>
 
106
        /// <remarks> It will be clipped to fit within 16 characters</remarks>
 
107
        public string UserId
 
108
        {
 
109
            get
 
110
            {
 
111
                return CAPI.LASVLR_GetUserId(hvlrh);
 
112
            }
 
113
 
 
114
            set
 
115
            {
 
116
                LASError error = CAPI.LASVLR_SetUserId(hvlrh, value);
 
117
                if ((Int32)error != 0)
 
118
                {
 
119
                    LASException e = new LASException("Exception in Set VLR UserId.");
 
120
                    throw e;
 
121
                }
 
122
            }
 
123
        }
 
124
 
 
125
        /// <summary>
 
126
        /// the description for the variable length record.
 
127
        /// </summary>
 
128
        /// <remarks> It will be clipped to fit within 32 characters</remarks>
 
129
        public string Description
 
130
        {
 
131
            get
 
132
            {
 
133
                return CAPI.LASVLR_GetDescription(hvlrh);
 
134
            }
 
135
 
 
136
            set
 
137
            {
 
138
                LASError error = CAPI.LASVLR_SetDescription(hvlrh, value);
 
139
                if ((Int32)error != 0)
 
140
                {
 
141
                    LASException e = new LASException("Exception in Set VLR Description.");
 
142
                    throw e;
 
143
                }
 
144
            }
 
145
        }
 
146
 
 
147
        /// <summary>
 
148
        /// the record length of the data stored in the variable length record.
 
149
        /// </summary>
 
150
        public UInt16 RecordLength
 
151
        {
 
152
            get
 
153
            {
 
154
                return CAPI.LASVLR_GetRecordLength(hvlrh);
 
155
            }
 
156
 
 
157
            set
 
158
            {
 
159
                LASError error = CAPI.LASVLR_SetRecordLength(hvlrh, value);
 
160
                if ((Int32)error != 0)
 
161
                {
 
162
                    LASException e = new LASException("Exception in Set VLR RecordLength.");
 
163
                    throw e;
 
164
                }
 
165
            }
 
166
        }
 
167
 
 
168
        /// <summary>
 
169
        /// the record id for the variable length record.
 
170
        /// </summary>
 
171
        public UInt16 RecordId
 
172
        {
 
173
            get
 
174
            {
 
175
                return CAPI.LASVLR_GetRecordId(hvlrh);
 
176
            }
 
177
 
 
178
            set
 
179
            {
 
180
                LASError error = CAPI.LASVLR_SetRecordId(hvlrh, value);
 
181
                if ((Int32)error != 0)
 
182
                {
 
183
                    LASException e = new LASException("Exception in Set VLR RecordId.");
 
184
                    throw e;
 
185
                }
 
186
            }
 
187
        }
 
188
 
 
189
        /// <summary>
 
190
        /// the reserved value of the variable length record.  
 
191
        /// </summary>
 
192
        /// <remarks>This should be 0 and should always be 0.</remarks>
 
193
        public UInt16 Reserved
 
194
        {
 
195
            get
 
196
            {
 
197
                return CAPI.LASVLR_GetReserved(hvlrh);
 
198
            }
 
199
 
 
200
            set
 
201
            {
 
202
                LASError error = CAPI.LASVLR_SetReserved(hvlrh, value);
 
203
                if ((Int32)error != 0)
 
204
                {
 
205
                    LASException e = new LASException("Exception in Set VLR Reserved.");
 
206
                    throw e;
 
207
                }
 
208
            }
 
209
        }
 
210
 
 
211
        /// <summary>
 
212
        /// Gets the data stream for the variable length record as an array of bytes
 
213
        /// </summary>
 
214
        /// <param name="data">a empty array of bytes where place the array</param>
 
215
        public void GetData(out byte[] data)
 
216
        {
 
217
            LASError error = CAPI.LASVLR_GetData(hvlrh, out data);
 
218
            if ((Int32)error != 0)
 
219
            {
 
220
                LASException e = new LASException("Exception in VLR GetData.");
 
221
                throw e;
 
222
            }
 
223
        }
 
224
 
 
225
        /// <summary>
 
226
        /// Sets the data stream for the variable length record as an array of bytes
 
227
        /// </summary>
 
228
        /// <param name="data">array of bytes</param>
 
229
        public void SetData(ref byte[] data)
 
230
        {
 
231
            UInt16 lenght = (UInt16)data.Length;
 
232
            LASError error = CAPI.LASVLR_SetData(hvlrh, ref data, lenght);
 
233
            if ((Int32)error != 0)
 
234
            {
 
235
                LASException e = new LASException("Exception in VLR SetData.");
 
236
                throw e;
 
237
            }
 
238
        }
 
239
    }
 
240
}