1

我正在开发一个移动天气应用程序,我正在读取Grib2来自 NOAA 服务器的天气信息表单文件。一切正常,我正在获取所有天气信息并绘制到地图上。

现在,我有一个场景,我得到负经度值。如下图所示:

负值

笔记:

我正在使用GribCS库从Grib 文件中提取天气信息,如果经度值是11而不是-11 ,这似乎工作完美;我正在通过以下方式提取值:

    void GribTwo()
    {
        #region Grib 2 Code

        Grib2Input input = new Grib2Input(RandomAccessFile);

        if (!input.scan(false, false))
        {
            Console.WriteLine("Failed to successfully scan grib file");
            return;
        }
        Grib2Data data = new Grib2Data(RandomAccessFile);

        var records = input.Records;

        foreach (Grib2Record record in records)
        {
            IGrib2IndicatorSection iis = record.Is;
            IGrib2IdentificationSection id = record.ID;
            IGrib2ProductDefinitionSection pdsv = record.PDS;
            IGrib2GridDefinitionSection gdsv = record.GDS;

            float[] values = data.getData(record.getGdsOffset(), record.getPdsOffset());

            if ((iis.Discipline == 0) && (pdsv.ParameterCategory == 2) && (pdsv.ParameterNumber == 2))
            {
                // U-component_of_wind
                int c = 0;
                for (double lat = gdsv.La1; lat <= gdsv.La2; lat = lat - gdsv.Dy)
                {
                    //THIS is  gdsv.Lo1; always has wrong values. 349 value instead -11 whuile Lo2 has correct value 7.
                    for (double lon = gdsv.Lo1; lon <= gdsv.Lo2; lon = lon + gdsv.Dx)
                    {
                        Console.WriteLine("U-Wind " + lat + "\t" + lon + "\t" + values[c]);
                        c++;
                    }
                }
            }

        #endregion
    }

正如我在内部循环中提到的那样,gdsv.Lo1;在这种情况下,起点的值错误它有 349 而不是 -11 导致问题。

在深入挖掘时,我发现以下方法基本上从流中读取值并转换为可读形式。

    public static int int4(System.IO.Stream raf)
    {
        int a = raf.ReadByte();
        int b = raf.ReadByte();
        int c = raf.ReadByte();
        int d = raf.ReadByte();

        // all bits set to ones
        if (a == 0xff && b == 0xff && c == 0xff && d == 0xff)
            return UNDEFINED;

        int i2 = (1 - ((a & 128) >> 6)) * ((a & 127) << 24 | b << 16 | c << 8 | d);
        return i2;
    }
    //This method is available under GribNumbers.cs in GribCS library.

我不明白,有什么我写错/读错了吗?

4

2 回答 2

2

我正在使用同一个库GribApi.Net由于正在开发中,它现在有点错误,但是是的,您可以使用它来验证数据或找到更好的解决方案来解决现有库中的问题。

于 2015-10-16T05:21:34.233 回答
1

试试这个我累了,它也提取了那些负值。

结果

干杯!!

于 2015-10-16T03:35:21.937 回答