c# - 在 Grib2 文件中经度为负值时获取错误值

标签 c# grib

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

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

Negative Value

注意:

我正在使用 GribCSGrib 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.

我不明白,有没有我写错/读错的地方?

最佳答案

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

关于c# - 在 Grib2 文件中经度为负值时获取错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33117071/

相关文章:

compiler-errors - 配置: error: C compiler cannot create executables when installing Jasper libraries using cygwin

c# - 如何在单击按钮时将数据从 View 发送到 Controller

c# - 通用 Windows 平台应用程序中的 MySql 数据库连接

c# - IWizard 带有多项目模板来获取 nuget 预发布包

python - 如何从 Grib1/.grb 文件转储值

python - 解释 NOAA 紫外线指数预测如何计算预测文件中的小时数?

python - 错误 : Command '[' dot', '-V' ]' 返回非零退出状态 -5 使用 Iris 时

c# - Microsoft Access 中的 bool 列和使用 linq 过滤数据

c# - 来自自定义 JsonConverter(Web API)的 Json.Net JsonSerializer 中的自引用循环

python - 读取数据时pygrib GRIB2段错误