Ouvre-fichiers Java GRIB


Je travaille actuellement sur un projet d'application mobile qui peut afficher les prévisions météo sur une carte (par exemple PocketGrib). J'ai décidé d'utiliser des fichiers GRIB mais je ne sais pas comment les décoder. J'ai trouvé une bibliothèque JGRIB pour les ouvrir mais je n'ai pas encore compris comment l'utiliser. La meilleure façon pour moi serait de convertir les données GRIB en txt et de les analyser plus loin pour obtenir les valeurs nécessaires.

Quelqu'un a-t-il de l'expérience avec cela? Tous les conseils sont appréciés. Désolé pour mon mauvais anglais.

Author: Mike Laren, 2015-03-25

2 answers

Il est possible d'utiliser la bibliothèque NetCDF-java pour ouvrir les fichiers GRIB: https://www.unidata.ucar.edu/software/thredds/current/netcdf-java/documentation.htm

 2
Author: DopplerShift, 2015-03-25 17:35:55

Ok, j'ai fait quelque chose en utilisant NetCDF. Pour mon utilisation, cela semble être suffisant. Bien sûr, pour chaque grib, les variables seront différentes.

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();
    }
 1
Author: Leszek Bulawa, 2015-05-07 18:44:34