Sunday, December 09, 2007

LAS 2.0 data types and corresponding data types in .NET

The LAS2.0's specification defines the data types it supports in table 3.1 on page 4.

The following table shows the corresponding .NET data types as well as the C# built in data type.

LAS 2.0 Moniker Data Type Size (in bytes) .NET Data Type C# Type Range
BOOL Logical 1 Boolean bool true or false
B1 Byte 1 SByte sbyte -128 to 127
UI1 Unsigned Byte 1 Byte byte 0 to 255
I2 Signed Short Integer 2 Int16 short -32768 to 32767
UI2 Unsigned Short Integer 2 UInt16 ushort 0 to 65535
I4 Signed Long Integer 4 Int32 int 2,147,483,648 to 2,147,483,647
UI4 Unsigned Long
Integer
4 UInt32 uint 0 to 4,294,967,295
I8 Signed 8 byte integer 8 Int64 long -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
UI8 Unsigned 8 byte integer 8 UInt64 ulong 0 to
18,446,744,073,709,551,615
R4 Real Float 4 Single float  
R8 Real Double 8 Double double  
R10 Real Extended precision Double 10 ?? ??  
STR STR zero (null – binary
0000 0000)
terminated variable
length string
VAR Byte[] byte[] Even though the data is stored as an array of bytes, one can use the string data type and use convertors to convert the string to the byte values. Also remember the values are not the .NET Char type which is 2 bytes in size
BFx bit field x, where x = 1,2,4,8 Byte, UInt16, UInt32, UInt64 byte, ushort, uint, ulong data types are used as bit fields
[n] Array VAR Array Array of any of the types defined above for example UI[4] is uint[4]

Notes:

  • The BitConvertor class as well as the BinaryReader class can be used to convert bytes to their corresponding .NET data types.
  • To convert a byte array to string one can do the following:
public static byte[] StrToByteArray(string str)
{  
    System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();  
    return encoding.GetBytes(str);
}
  • And to do the reverse
byte [] dBytes = ...
string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(dBytes);
  • The BitArray class (System.Collections namespace) can be used as a helper class to work with the BFx data type. It can handle arbitrary length bit fields and provides methods that allow you to perform bit arithmetic.
  • An important thing to remember is that bool in .NET is actual 4 bytes long (which corresponds to a WIN BOOL). So if you need to marshal your structure to native code or need to convert the data to bytes - you will need to use the Marshal As attribute to do it as a byte (UI1)

More information:
C# Data Type:
http://msdn2.microsoft.com/en-us/library/1dhd7f2x(VS.71).aspx 
LAS 2.0 Specification:
http://www.asprs.org/society/divisions/ppd/standards/incitsl1_las_format_v20.pdf 
LAS Documents:
http://www.asprs.org/society/divisions/ppd/standards/lidar_exchange_format.htm

1 comment:

Anonymous said...

"BOOL. It's really not that Logical."