Catfood.Shapefile.Header.Header C# (CSharp) Method

Header() public method

The header data for a Shapefile main file or Index file
Thrown if headerBytes is null Thrown if an error occurs parsing the header
public Header ( byte headerBytes ) : System
headerBytes byte The first 100 bytes of the Shapefile main file or Index file
return System
        public Header(byte[] headerBytes)
        {
            if (headerBytes == null)
            {
                throw new ArgumentNullException("headerBytes");
            }

            if (headerBytes.Length != HeaderLength)
            {
                throw new InvalidOperationException(string.Format("headerBytes must be {0} bytes long", 
                    HeaderLength));
            }

            //Position  Field           Value       Type        Order
            //Byte 0    File Code       9994        Integer     Big
            //Byte 4    Unused          0           Integer     Big
            //Byte 8    Unused          0           Integer     Big
            //Byte 12   Unused          0           Integer     Big
            //Byte 16   Unused          0           Integer     Big
            //Byte 20   Unused          0           Integer     Big
            //Byte 24   File Length     File Length Integer     Big
            //Byte 28   Version         1000        Integer     Little
            //Byte 32   Shape Type      Shape Type  Integer     Little
            //Byte 36   Bounding Box    Xmin        Double      Little
            //Byte 44   Bounding Box    Ymin        Double      Little
            //Byte 52   Bounding Box    Xmax        Double      Little
            //Byte 60   Bounding Box    Ymax        Double      Little
            //Byte 68*  Bounding Box    Zmin        Double      Little
            //Byte 76*  Bounding Box    Zmax        Double      Little
            //Byte 84*  Bounding Box    Mmin        Double      Little
            //Byte 92*  Bounding Box    Mmax        Double      Little
            
            _fileCode = EndianBitConverter.ToInt32(headerBytes, 0, ProvidedOrder.Big);
            if (_fileCode != ExpectedFileCode)
            {
                throw new InvalidOperationException(string.Format("Header File code is {0}, expected {1}",
                    _fileCode,
                    ExpectedFileCode));
            }

            _version = EndianBitConverter.ToInt32(headerBytes, 28, ProvidedOrder.Little);
            if (_version != ExpectedVersion)
            {
                throw new InvalidOperationException(string.Format("Header version is {0}, expected {1}",
                    _version,
                    ExpectedVersion));
            }

            _fileLength = EndianBitConverter.ToInt32(headerBytes, 24, ProvidedOrder.Big);
            _shapeType = (ShapeType)EndianBitConverter.ToInt32(headerBytes, 32, ProvidedOrder.Little);
            _xMin = EndianBitConverter.ToDouble(headerBytes, 36, ProvidedOrder.Little);
            _yMin = EndianBitConverter.ToDouble(headerBytes, 44, ProvidedOrder.Little);
            _xMax = EndianBitConverter.ToDouble(headerBytes, 52, ProvidedOrder.Little);
            _yMax = EndianBitConverter.ToDouble(headerBytes, 60, ProvidedOrder.Little);
            _zMin = EndianBitConverter.ToDouble(headerBytes, 68, ProvidedOrder.Little);
            _zMax = EndianBitConverter.ToDouble(headerBytes, 76, ProvidedOrder.Little);
            _mMin = EndianBitConverter.ToDouble(headerBytes, 84, ProvidedOrder.Little);
            _mMax = EndianBitConverter.ToDouble(headerBytes, 92, ProvidedOrder.Little);
        }
Header