Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release/3.9] GRIB: adjust longitude range from [180, xxx] to [-180, xxx] #10734

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading