public GRIB2DataRepresentationSection(FileStream fs)
 {
     _sectionHeader = new GRIB2SectionHeader(fs);
     _dataPoints    = GribNumberHelper.Int4(fs);
     _dataTemplate  = (int)GribNumberHelper.Uint2(fs);
     SetOtherAttributeByDataTemplateNo(fs);
 }
        public GRIB2DataRepresentationSection(FileStream fs)
        {
            long position = fs.Position;

            _sectionHeader = new GRIB2SectionHeader(fs);
            _dataPoints    = GribNumberHelper.Int4(fs);
            _dataTemplate  = (int)GribNumberHelper.Uint2(fs);
            SetOtherAttributeByDataTemplateNo(fs);
            fs.Seek(position + _sectionHeader.SectionLength, SeekOrigin.Begin);
        }
Ejemplo n.º 3
0
 private void AdjustAttributes(byte[] array)
 {
     if (this.Resolution == 128)
     {
         _dx = (double)GribNumberHelper.Uint2(array[23], array[24]) / 1000.0;
         if (this.GridType == 4)
         {
             _np = GribNumberHelper.Uint2(array[25], array[26]);
             _dy = (double)_np / 1000.0;
         }
         else
         {
             _dy = (double)GribNumberHelper.Uint2(array[25], array[26]) / 1000.0;
         }
         _scanMode = Convert.ToInt32(array[27]);
     }
     else
     {
         _dx = (_lonEndPoint - _lonFirstPoint) / (double)(_nx - 1);
         _dy = (_latEndPoint - _latFirstPoint) / (double)(_ny - 1);
     }
     if ((_scanMode & 128) != 0)
     {
         _xReverse = true;
     }
     if (_latEndPoint < _latFirstPoint)
     {
         _yReverse = true;
     }
     if (_thinnedGrid)
     {
         _thinnedXNums   = new int[_ny];
         _thinnedGridNum = 0;
         for (int i = 0; i < _ny; i++)
         {
             _thinnedXNums[i] = GribNumberHelper.Int2(array[32 + i * 2], array[33 + i * 2]);
             _thinnedGridNum += this.ThinnedXNums[i];
             if (i == 0)
             {
                 _nx = this.ThinnedXNums[i];
             }
             else
             {
                 if (_nx < this.ThinnedXNums[i])
                 {
                     //取格点数最多那行的格点数为宽
                     _nx = this.ThinnedXNums[i];
                 }
             }
         }
         _dx = Math.Abs(_lonEndPoint - _lonFirstPoint) / (double)(_nx - 1);
     }
 }
Ejemplo n.º 4
0
        private void SetOtherAttribute(FileStream fs)
        {
            if (_gridType != 50)
            {
                // Nx - 沿x轴的点数量
                _nx = GribNumberHelper.Uint2(fs);// GribNumberHelper.Int2(fs);
                _nx = (_nx == -1) ? 1 : _nx;
                if (_nx >= 65535)
                {
                    _thinnedGrid = true;
                }
                // Ny - 沿y轴的点数量
                _ny            = GribNumberHelper.Uint2(fs);         // GribNumberHelper.Int2(fs);
                _ny            = (_ny == -1) ? 1 : _ny;
                _latFirstPoint = GribNumberHelper.Int3(fs) / 1000.0; // La1 - 第一个格网点的纬度
                _lonFirstPoint = GribNumberHelper.Int3(fs) / 1000.0; // Lo1 - 第一个格网点的经度
                _resolution    = fs.ReadByte();                      //分辨率和组件标识
            }
            switch (_gridType)
            {
            //  Latitude/Longitude  grids,Arakawa semi-staggered e-grid rotated
            //  Arakawa filled e-grid rotated

            case 0:                                               // Latitude/longitude grid
            case 4:                                               //Gaussian latitude/longitude grid
            case 40:
            case 201:
            case 202:
            {
                _latEndPoint = GribNumberHelper.Int3(fs) / 1000.0;          // La2 - 最后的格网点的纬度
                _lonEndPoint = GribNumberHelper.Int3(fs) / 1000.0;          // Lo2 - 最后的格网点的经度
                _dx          = GribNumberHelper.Int2(fs) / 1000.0;          // Dx - 经度方向增加量
                if (_gridType == 4)
                {
                    _np = GribNumberHelper.Int2(fs);                        // Np-极点与赤道间的纬度圈数
                }
                else
                {
                    _dy = GribNumberHelper.Int2(fs) / 1000.0; // Dy - 纬度方向增加量
                }
                _scanMode = fs.ReadByte();                    //扫描模式
                //29-32 reserved
                fs.Seek(4, SeekOrigin.Current);
                if (_sectionLength > 32)
                {
                    // Vertical coordinates (NV) and thinned grids (PL) not supported - skip this
                    fs.Seek(_sectionLength - 32, SeekOrigin.Current);
                }
                break;
            }

            //Mercator projection
            case 1:
                _latEndPoint = GribNumberHelper.Int3(fs) / 1000.0; // La2 - 最后格网点的纬度
                _lonEndPoint = GribNumberHelper.Int3(fs) / 1000.0; // Lo2 - 最后格网点的经度
                // octets 24-26 (Latin - latitude where cylinder intersects the earth
                _latin1 = GribNumberHelper.Int3(fs) / 1000.0;      //  Latin -圆柱体与地球相交处的高程
                fs.ReadByte();
                _scanMode = fs.ReadByte();                         //扫描模式
                _dx       = GribNumberHelper.Int3(fs);             // Dx - 经度方向增加量
                _dy       = GribNumberHelper.Int3(fs);             //  Dy - 纬度方向增加量
                fs.Seek(4, SeekOrigin.Current);
                if (_sectionLength > 42)
                {
                    // Vertical coordinates (NV) and thinned grids (PL) not supported - skip this
                    fs.Seek(_sectionLength - 42, SeekOrigin.Current);
                }
                break;

            //Lambert conformal, secant or tangent, conic or bi-polar, projection
            case 3:
                // Lov - Orientation of the grid - east lon parallel to y axis)
                _lov          = GribNumberHelper.Int3(fs) / 1000.0;
                _dx           = GribNumberHelper.Int3(fs); // Dx - X方向格网长度
                _dy           = GribNumberHelper.Int3(fs); // Dy - Y方向格网长度
                _projetcenter = fs.ReadByte();             //投影中心标识
                _scanMode     = fs.ReadByte();             //扫描模式
                // Latin1 - first lat where secant cone cuts spherical earth
                _latin1 = GribNumberHelper.Int3(fs) / 1000.0;
                // Latin2 - second lat where secant cone cuts spherical earth)
                _latin2 = GribNumberHelper.Int3(fs) / 1000.0;
                _latsp  = GribNumberHelper.Int3(fs) / 1000.0;   //南极点纬度
                _lonsp  = GribNumberHelper.Int3(fs) / 1000.0;   //南极点经度
                fs.Seek(2, SeekOrigin.Current);
                if (_sectionLength > 42)
                {
                    // Vertical coordinates (NV) and thinned grids (PL) not supported - skip this
                    fs.Seek(_sectionLength - 42, SeekOrigin.Current);
                }

                break;

            case 5:
                // Lov - Orientation of the grid - east lon parallel to y axis)
                _lov          = GribNumberHelper.Int3(fs) / 1000.0;
                _dx           = GribNumberHelper.Int3(fs); // Dx - 经度方向增加量
                _dy           = GribNumberHelper.Int3(fs); // Dy - 纬度方向增加量
                _projetcenter = fs.ReadByte();             //投影中心标识
                _scanMode     = fs.ReadByte();             //扫描模式
                fs.Seek(4, SeekOrigin.Current);
                if (_sectionLength > 32)
                {
                    // Vertical coordinates (NV) and thinned grids (PL) not supported - skip this
                    fs.Seek(_sectionLength - 32, SeekOrigin.Current);
                }
                break;

            default:
                break;
            }

            if ((_scanMode & 63) != 0)
            {
                throw new Exception("GDS: This scanning mode (" + _scanMode + ") is not supported.");
            }
            fs.Seek(_position, SeekOrigin.Begin);
            byte[] array = new byte[_sectionLength];
            fs.Read(array, 0, _sectionLength);
            AdjustAttributes(array);
        }