2015-03-24 102 views
1

我目前正在開發一個可以在地圖上顯示天氣預報的移動應用程序項目(例如PocketGrib)。我決定使用GRIB文件,但我不知道如何解碼它們。我發現一個庫JGRIB打開這些,但我還沒有弄清楚如何使用它。對我來說最好的辦法是將GRIB數據轉換爲txt,並以我的方式進一步解析以獲得所需的值。Java GRIB文件打開器

有沒有人有經驗呢?任何提示都表示讚賞。對不起,我英文很差。

+1

你有沒有看過API? – Alexander 2015-03-25 00:06:36

+0

什麼API?我還沒有找到。 – 2015-05-04 20:49:54

+0

有像http://data.planetos.com/datasets/noaa_gfs_global_sflux_0.12d這樣的服務提供天氣模型的API-s,你有沒有考慮過? – kakk11 2016-11-29 20:40:12

回答

1

好,我使用的NetCDF做什麼。對於我的用法來說,似乎就夠了。當然對於每個grib變量都會有所不同。

try { 
      NetcdfFile ncf = NetcdfFile.open("gribfilename.grb"); //loading grib file 
      System.out.println("Variable names are:"); 
      List<Variable> vars = ncf.getVariables(); //listing variables 
      for (Variable var : vars) { 
      System.out.println(var.getName()); 
      } 

      Variable Uwind = ncf.findVariable("u-component_of_wind_height_above_ground"); 
      Variable Vwind = ncf.findVariable("v-component_of_wind_height_above_ground"); 
      Variable lat = ncf.findVariable("lat"); 
      Variable lon = ncf.findVariable("lon"); 
      Variable time = ncf.findVariable("time"); 
      Variable reftime = ncf.findVariable("reftime"); 
      Variable reftime_ISO = ncf.findVariable("reftime_ISO"); 
      Variable height_above_ground = ncf.findVariable("height_above_ground"); 
      Variable height_above_ground1 = ncf.findVariable("height_above_ground1"); 
      Variable Temperature_height_above_ground = ncf.findVariable("Temperature_height_above_ground"); 
      Variable Pressure_reduced_to_MSL_msl = ncf.findVariable("Pressure_reduced_to_MSL_msl"); 



      Array u_data = Uwind.read(); //reading variables to Array type 
      Array v_data = Vwind.read(); 
      Array lat_data = lat.read(); 
      Array lon_data = lon.read(); 
      Array time_data = time.read(); 
      Array reftime_data = reftime.read(); 
      Array reftime_ISO_data = reftime_ISO.read(); 
      Array height_above_ground_data = height_above_ground.read(); 
      Array height_above_ground1_data = height_above_ground1.read(); 
      Array Temperature_height_above_ground_data = Temperature_height_above_ground.read(); 
      Array Pressure_reduced_to_MSL_msl_data = Pressure_reduced_to_MSL_msl.read(); 

      ncf.close(); 


    } 
    catch (Exception exc) { 
     exc.printStackTrace(); 
    }