Ejemplo n.º 1
0
        public LASHeader(BinaryReader reader)
        {
            long length = reader.BaseStream.Length;

            if (length < c_minHeaderSize[LASVersion.LAS_1_0])
                throw new OpenFailedException("Invalid format: header too short");

            if (Encoding.ASCII.GetString(reader.ReadBytes(FILE_SIGNATURE.Length)) != FILE_SIGNATURE)
                throw new OpenFailedException("Invalid format: signature does not match");

            m_fileSourceID          = reader.ReadUInt16();

            m_globalEncoding        = reader.ReadLASGlobalEncoding();
            m_projectID             = reader.ReadLASProjectID();
            m_version               = reader.ReadLASVersionInfo();

            m_systemIdentifier      = reader.ReadBytes(32).ToAsciiString();
            m_generatingSoftware    = reader.ReadBytes(32).ToAsciiString();
            m_fileCreationDayOfYear = reader.ReadUInt16();
            m_fileCreationYear      = reader.ReadUInt16();

            m_headerSize            = reader.ReadUInt16();
            m_offsetToPointData     = reader.ReadUInt32();

            ushort minHeaderSize = c_minHeaderSize[m_version.Version];
            if (length < minHeaderSize)
                throw new OpenFailedException("Invalid format: header too short for version");
            if(minHeaderSize > m_headerSize)
                throw new OpenFailedException("Invalid format: header size incorrect");

            m_numberOfVariableLengthRecords = reader.ReadUInt32();
            m_pointDataRecordFormat         = reader.ReadByte();
            m_pointDataRecordLength         = reader.ReadUInt16();
            m_legacyNumberOfPointRecords    = reader.ReadUInt32();
            m_legacyNumberOfPointsByReturn  = reader.ReadUInt32Array(5);

            m_quantization = reader.ReadSQuantization3D();
            m_extent       = reader.ReadExtent3D();

            if (m_version.Version >= LASVersion.LAS_1_3)
            {
                m_startOfWaveformDataPacketRecord = reader.ReadUInt64();
            }

            if (m_version.Version >= LASVersion.LAS_1_4)
            {
                m_startOfFirstExtendedVariableLengthRecord = reader.ReadUInt64();
                m_numberOfExtendedVariableLengthRecords    = reader.ReadUInt32();
                m_numberOfPointRecords                     = reader.ReadUInt64();
                m_numberOfPointsByReturn                   = reader.ReadUInt64Array(15);
            }
            else
            {
                m_numberOfPointRecords = m_legacyNumberOfPointRecords;
                m_numberOfPointsByReturn = new ulong[15];
                for (int i = 0; i < m_legacyNumberOfPointsByReturn.Length; i++)
                    m_numberOfPointsByReturn[i] = m_legacyNumberOfPointsByReturn[i];
            }

            // This doesn't apply to LAZ files
            //ulong pointDataRegionLength = (ulong)length - m_offsetToPointData;
            //if (pointDataRegionLength < m_pointDataRecordLength * PointCount)
            //    throw new Exception("Invalid format: point data region is not the expected size");
        }
Ejemplo n.º 2
0
        public LASHeader(BinaryReader reader)
        {
            long length = reader.BaseStream.Length;

            if (length < c_minHeaderSize[LASVersion.LAS_1_0])
            {
                throw new OpenFailedException("Invalid format: header too short");
            }

            if (Encoding.ASCII.GetString(reader.ReadBytes(FILE_SIGNATURE.Length)) != FILE_SIGNATURE)
            {
                throw new OpenFailedException("Invalid format: signature does not match");
            }

            m_fileSourceID = reader.ReadUInt16();

            m_globalEncoding = reader.ReadLASGlobalEncoding();
            m_projectID      = reader.ReadLASProjectID();
            m_version        = reader.ReadLASVersionInfo();

            m_systemIdentifier      = reader.ReadBytes(32).ToAsciiString();
            m_generatingSoftware    = reader.ReadBytes(32).ToAsciiString();
            m_fileCreationDayOfYear = reader.ReadUInt16();
            m_fileCreationYear      = reader.ReadUInt16();

            m_headerSize        = reader.ReadUInt16();
            m_offsetToPointData = reader.ReadUInt32();

            ushort minHeaderSize = c_minHeaderSize[m_version.Version];

            if (length < minHeaderSize)
            {
                throw new OpenFailedException("Invalid format: header too short for version");
            }
            if (minHeaderSize > m_headerSize)
            {
                throw new OpenFailedException("Invalid format: header size incorrect");
            }

            m_numberOfVariableLengthRecords = reader.ReadUInt32();
            m_pointDataRecordFormat         = reader.ReadByte();
            m_pointDataRecordLength         = reader.ReadUInt16();
            m_legacyNumberOfPointRecords    = reader.ReadUInt32();
            m_legacyNumberOfPointsByReturn  = reader.ReadUInt32Array(5);

            m_quantization = reader.ReadSQuantization3D();
            m_extent       = reader.ReadExtent3D();

            if (m_version.Version >= LASVersion.LAS_1_3)
            {
                m_startOfWaveformDataPacketRecord = reader.ReadUInt64();
            }

            if (m_version.Version >= LASVersion.LAS_1_4)
            {
                m_startOfFirstExtendedVariableLengthRecord = reader.ReadUInt64();
                m_numberOfExtendedVariableLengthRecords    = reader.ReadUInt32();
                m_numberOfPointRecords   = reader.ReadUInt64();
                m_numberOfPointsByReturn = reader.ReadUInt64Array(15);
            }
            else
            {
                m_numberOfPointRecords   = m_legacyNumberOfPointRecords;
                m_numberOfPointsByReturn = new ulong[15];
                for (int i = 0; i < m_legacyNumberOfPointsByReturn.Length; i++)
                {
                    m_numberOfPointsByReturn[i] = m_legacyNumberOfPointsByReturn[i];
                }
            }

            // This doesn't apply to LAZ files
            //ulong pointDataRegionLength = (ulong)length - m_offsetToPointData;
            //if (pointDataRegionLength < m_pointDataRecordLength * PointCount)
            //    throw new Exception("Invalid format: point data region is not the expected size");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This will only work if point format, point length, offset, and scale are identical.
        /// </summary>
        public LASHeader(LASHeader[] headers, LASVLR[] vlrs, LASEVLR[] evlrs)
        {
            var header = headers[0];
            var extent = headers.Select(h => h.m_extent).Union3D();

            var points = (ulong)headers.Sum(h => (long)h.m_numberOfPointRecords);
            var pointsByReturn = new ulong[15];
            for (var i = 0; i < pointsByReturn.Length; i++)
            {
                pointsByReturn[i] = (ulong)headers.Sum(h => (long)h.m_numberOfPointsByReturn[i]);
            }

            uint legacyPoints = 0;
            uint[] legacyPointsByReturn;

            if (points > uint.MaxValue)
            {
                legacyPoints = 0;
                legacyPointsByReturn = new uint[5];
            }
            else
            {
                legacyPoints = (uint)points;
                legacyPointsByReturn = pointsByReturn.Take(5).Select(c => (uint)c).ToArray();
            }

            m_fileSourceID = header.m_fileSourceID;

            m_globalEncoding = header.m_globalEncoding;
            m_projectID = header.m_projectID;
            m_version = LASVersionInfo.Create(LASVersion.LAS_1_4);

            m_systemIdentifier = header.m_systemIdentifier;
            m_generatingSoftware = header.m_generatingSoftware;
            m_fileCreationDayOfYear = header.m_fileCreationDayOfYear;
            m_fileCreationYear = header.m_fileCreationYear;

            m_headerSize = c_minHeaderSize[LASVersion.LAS_1_4];
            m_offsetToPointData = m_headerSize + (uint)vlrs.Sum(vlr => vlr.Length);

            m_numberOfVariableLengthRecords = (uint)vlrs.Length;
            m_pointDataRecordFormat = header.m_pointDataRecordFormat;
            m_pointDataRecordLength = header.m_pointDataRecordLength;

            if (points > uint.MaxValue)
            {
                m_legacyNumberOfPointRecords = 0;
                m_legacyNumberOfPointsByReturn = new uint[5];
            }
            else
            {
                m_legacyNumberOfPointRecords = legacyPoints;
                m_legacyNumberOfPointsByReturn = legacyPointsByReturn;
            }

            m_quantization = header.m_quantization;
            m_extent = extent;

            m_startOfWaveformDataPacketRecord = 0;

            m_startOfFirstExtendedVariableLengthRecord = m_offsetToPointData + (points * m_pointDataRecordLength);
            m_numberOfExtendedVariableLengthRecords = (uint)evlrs.Length;
            m_numberOfPointRecords = points;

            m_numberOfPointsByReturn = pointsByReturn;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This will only work if point format, point length, offset, and scale are identical.
        /// </summary>
        public LASHeader(LASHeader[] headers, LASVLR[] vlrs, LASEVLR[] evlrs)
        {
            var header = headers[0];
            var extent = headers.Select(h => h.m_extent).Union3D();

            var points         = (ulong)headers.Sum(h => (long)h.m_numberOfPointRecords);
            var pointsByReturn = new ulong[15];

            for (var i = 0; i < pointsByReturn.Length; i++)
            {
                pointsByReturn[i] = (ulong)headers.Sum(h => (long)h.m_numberOfPointsByReturn[i]);
            }

            uint legacyPoints = 0;

            uint[] legacyPointsByReturn;

            if (points > uint.MaxValue)
            {
                legacyPoints         = 0;
                legacyPointsByReturn = new uint[5];
            }
            else
            {
                legacyPoints         = (uint)points;
                legacyPointsByReturn = pointsByReturn.Take(5).Select(c => (uint)c).ToArray();
            }

            m_fileSourceID = header.m_fileSourceID;

            m_globalEncoding = header.m_globalEncoding;
            m_projectID      = header.m_projectID;
            m_version        = LASVersionInfo.Create(LASVersion.LAS_1_4);

            m_systemIdentifier      = header.m_systemIdentifier;
            m_generatingSoftware    = header.m_generatingSoftware;
            m_fileCreationDayOfYear = header.m_fileCreationDayOfYear;
            m_fileCreationYear      = header.m_fileCreationYear;

            m_headerSize        = c_minHeaderSize[LASVersion.LAS_1_4];
            m_offsetToPointData = m_headerSize + (uint)vlrs.Sum(vlr => vlr.Length);

            m_numberOfVariableLengthRecords = (uint)vlrs.Length;
            m_pointDataRecordFormat         = header.m_pointDataRecordFormat;
            m_pointDataRecordLength         = header.m_pointDataRecordLength;

            if (points > uint.MaxValue)
            {
                m_legacyNumberOfPointRecords   = 0;
                m_legacyNumberOfPointsByReturn = new uint[5];
            }
            else
            {
                m_legacyNumberOfPointRecords   = legacyPoints;
                m_legacyNumberOfPointsByReturn = legacyPointsByReturn;
            }

            m_quantization = header.m_quantization;
            m_extent       = extent;

            m_startOfWaveformDataPacketRecord = 0;

            m_startOfFirstExtendedVariableLengthRecord = m_offsetToPointData + (points * m_pointDataRecordLength);
            m_numberOfExtendedVariableLengthRecords    = (uint)evlrs.Length;
            m_numberOfPointRecords = points;

            m_numberOfPointsByReturn = pointsByReturn;
        }