【问题标题】:Getting Wrong values while Longitude has negative in Grib2 file当 Grib2 文件中的经度为负时获取错误的值
【发布时间】:2016-01-12 01:17:50
【问题描述】:

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

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

注意:

我正在使用GribCS 库从Grib File 中提取天气信息,如果经度值是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.

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

【问题讨论】:

    标签: c# grib


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      干杯!!

      【讨论】:

        猜你喜欢
        • 2011-11-14
        • 2016-10-03
        • 1970-01-01
        • 2018-03-30
        • 2020-04-25
        • 2016-01-14
        • 2015-03-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多