173 lines
4.0 KiB
C#
173 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace LASRead.LASFormat
|
|
{
|
|
static class DataHelpers
|
|
{
|
|
/// <summary>
|
|
/// Converts an array of characters into an array of bytes. Trims values > 255 to 255.
|
|
/// </summary>
|
|
/// <param name="characters"></param>
|
|
/// <returns></returns>
|
|
public static byte[] ToByteArray(char[] characters)
|
|
{
|
|
byte[] outBytes = new byte[characters.Length];
|
|
for (int i = 0; i < characters.Length; i++)
|
|
{
|
|
outBytes[i] = (byte)Math.Min((ushort)255, characters[i]);
|
|
}
|
|
return outBytes;
|
|
}
|
|
|
|
public static byte[] ToByteArray(uint[] values)
|
|
{
|
|
byte[] outBytes = new byte[4 * values.Length];
|
|
for (int i = 0; i < values.Length; i++)
|
|
{
|
|
byte[] tBytes = BitConverter.GetBytes(values[i]);
|
|
tBytes.CopyTo(outBytes, i * 4);
|
|
}
|
|
return outBytes;
|
|
}
|
|
public static byte[] ToByteArray(ulong[] values)
|
|
{
|
|
byte[] outBytes = new byte[8 * values.Length];
|
|
for (int i = 0; i < values.Length; i++)
|
|
{
|
|
byte[] tBytes = BitConverter.GetBytes(values[i]);
|
|
tBytes.CopyTo(outBytes, i * 8);
|
|
}
|
|
return outBytes;
|
|
}
|
|
|
|
public static char[] ToCharArray(byte[] values, int start, int length)
|
|
{
|
|
char[] characters = new char[length];
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
characters[i] = (char)values[start + i];
|
|
}
|
|
return characters;
|
|
}
|
|
|
|
public static char[] ToCharArray(byte[] values)
|
|
{
|
|
return ToCharArray(values, 0, values.Length);
|
|
}
|
|
|
|
public static uint[] ToUintArray(byte[] values, int start, int length)
|
|
{
|
|
uint[] tUints = new uint[length / 4];
|
|
for (int i = 0; i < length / 4; i++)
|
|
{
|
|
tUints[i] = BitConverter.ToUInt32(values, start + i * 4);
|
|
}
|
|
return tUints;
|
|
}
|
|
|
|
public static ulong[] ToULongArray(byte[] values, int start, int length)
|
|
{
|
|
ulong[] tULongs = new ulong[length / 8];
|
|
|
|
for (int i = 0; i < length / 8; i++)
|
|
{
|
|
tULongs[i] = BitConverter.ToUInt64(values, start + i * 8);
|
|
}
|
|
return tULongs;
|
|
}
|
|
|
|
public static bool VerifySize(byte[] source, int headerSize)
|
|
{
|
|
if (source.Length < headerSize)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
public static byte[] ReadBytes(Stream s, int count)
|
|
{
|
|
byte[] bytes = new byte[count];
|
|
s.Read(bytes, 0, count);
|
|
return bytes;
|
|
}
|
|
}
|
|
enum Classifications
|
|
{
|
|
Created,
|
|
Unclassified,
|
|
Ground,
|
|
Vegetation_Low,
|
|
Vegetation_Med,
|
|
Vegetation_High,
|
|
Building,
|
|
LowPoint,
|
|
r8,
|
|
Water,
|
|
Rail,
|
|
RoadSurface,
|
|
r12,
|
|
Wire_Guard,
|
|
Wire_Conductor,
|
|
TransmissionTower,
|
|
Wire_StructureConnector,
|
|
BridgeDeck,
|
|
HighNoise,
|
|
OverheadStructure,
|
|
IgnoredGround,
|
|
Snow,
|
|
TemporalExclusion,
|
|
r23,
|
|
r24,
|
|
r25,
|
|
r26,
|
|
r27,
|
|
r28,
|
|
r29,
|
|
r30,
|
|
r31,
|
|
r32,
|
|
r33,
|
|
r34,
|
|
r36,
|
|
r37,
|
|
r38,
|
|
r39,
|
|
r40,
|
|
r41,
|
|
r42,
|
|
r43,
|
|
r44,
|
|
r45,
|
|
r46,
|
|
r47,
|
|
r48,
|
|
r49,
|
|
r50,
|
|
r51,
|
|
r52,
|
|
r53,
|
|
r54,
|
|
r55,
|
|
r56,
|
|
r57,
|
|
r58,
|
|
r59,
|
|
r60,
|
|
r61,
|
|
r62,
|
|
r63,
|
|
u64,
|
|
u65,
|
|
u66,
|
|
u67,
|
|
u68,
|
|
u69,
|
|
u70
|
|
}
|
|
}
|