Extracting data from grib file based on latitude and longitude

Pawan Tejwani picture Pawan Tejwani · Jun 15, 2012 · Viewed 8.4k times · Source

If i have a grib2 file that contains information for whole world (for some parameters) and I want to extract data from it using wgrib2 based on latitude and longitude given by user (client software to server). I tried following command but I am getting complete grib2 file only:

wgrib2.exe input.grb -undefine out-box 10:90 -10:10 -grib output.grb

Please tell me where am I going wrong? Thanks.

Answer

user1165471 picture user1165471 · May 27, 2019

This is still the top hit on Google, so even though it is a bit old, here is a more detailed explanation.

First, you need wgrib2 from the National Weather Service Climate Prediction Centre. (The installation of that is straightforward, but not too well explained. See this page, or this gist for help.)

Next, you need to use the lola function (for LOngitude-LAtitude grid).

You need to give wgrib2 several arguments:

  • the grib file that has the data
  • the longitude information:
    • the longitude of the southwest corner of your bounding box
    • the length of the bounding box in degrees
    • the spacing of the points in this direction
  • the latitude information, the same as above
    • the latitude of the southwest corner of your bounding box
    • the length of the bounding box in degrees
    • the spacing of the points in this direction
  • the file name to write to
  • the format of the file to write (either bin for binary, text for simple text, spread for spreadsheet format, or grib for grib2).

For example:

wgrib2 input.grb 220:100:1 20:50:1 output.grb2 grib

will create an output file that covers north america (220 E - 320 E; 20 N - 70 N) at 1 degree intervals in both directions.

Rob