Skip to content

Commit

Permalink
GRIB: adjust longitude range from [180, xxx] to [-180, xxx]
Browse files Browse the repository at this point in the history
Fixes #10655
  • Loading branch information
rouault authored and github-actions[bot] committed Sep 5, 2024
1 parent e8ac270 commit b1ea2db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Binary file added autotest/gdrivers/data/grib/minx_180.grib2
Binary file not shown.
7 changes: 7 additions & 0 deletions autotest/gdrivers/grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2419,3 +2419,10 @@ def test_grib_grib2_template_5_42_CCDS_aes_decompression():
assert ds.GetRasterBand(1).Checksum() == 41970
else:
assert ds.GetRasterBand(1).Checksum() == -1


# https://github.com/OSGeo/gdal/issues/10655
def test_grib_grib2_minx_180():
ds = gdal.Open("data/grib/minx_180.grib2")
gt = ds.GetGeoTransform()
assert gt == pytest.approx((-180.0625, 0.125, 0.0, 90.0625, 0.0, -0.125), rel=1e-6)
7 changes: 7 additions & 0 deletions frmts/grib/gribdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,13 @@ void GRIBDataset::SetGribMetaData(grib_MetaData *meta)
if (rPixelSizeX * nRasterXSize > 360 + rPixelSizeX / 4)
CPLDebug("GRIB", "Cannot properly handle GRIB2 files with "
"overlaps and 0-360 longitudes");
else if (rMinX == 180)
{
// Case of https://github.com/OSGeo/gdal/issues/10655
CPLDebug("GRIB", "Shifting longitudes from %lf:%lf to %lf:%lf",
rMinX, rMaxX, -180.0, Lon360to180(rMaxX));
rMinX = -180;
}
else if (fabs(360 - rPixelSizeX * nRasterXSize) < rPixelSizeX / 4 &&
rMinX <= 180 && meta->gds.projType == GS3_LATLON)
{
Expand Down

0 comments on commit b1ea2db

Please sign in to comment.