[GIS] Grib to CSV use lat lon

csvgriblatitude longitudepython

I have some grib files that I converted to csv. I would like to view the data in a table using the lat, lon, and variable as column headers. How can I do this using the grid data/dimensions within the file? In other words, I don't know how to assign each data point(var1) it's corresponding lat/lon point. Right now I have a Excel table full of data with 1441 rows/2880 columns.

  dimensions:
    lon = 2880;
    lat = 1441;
    time = 1;
  variables:
    int LatLon_Projection;
      :grid_mapping_name = "latitude_longitude";
      :earth_radius = 6367470.0; // double

    float lat(lat=1441);
      :units = "degrees_north";

    float lon(lon=2880);
      :units = "degrees_east";  


    float var1(time=1, lat=1441, lon=2880);
      :long_name = "variable1";
      :units = "";
      :missing_value = NaNf; // float
      :grid_mapping = "LatLon_Projection";
      :coordinates = "reftime time lat lon ";
      :Grib_Variable_Id = "var1";
      :Grib2_Parameter = 0, 20, 132; // int

Best Answer

you might be able to skip the part where you make a csv, by using gdal_translate (part of GDAL/OGR) which supports GRIB files and ASCII XYZ

I don't have any GRIB files to test this on, but something like this should work and give you an XYZ file (3 columns, space as separator). The Z will be the value from the corresponding cell.

gdal_translate -of XYZ input.grib grid.xyz

Example output...

266475 799925 315
266525 799925 315
266575 799925 315
266625 799925 315
266675 799925 270
266725 799925 270
266775 799925 270
266825 799925 315
266875 799925 315
266925 799925 315
266975 799925 360
Related Question