Skip to content

Commit

Permalink
Merge pull request #11414 from OSGeo/backport-11382-to-release/3.10
Browse files Browse the repository at this point in the history
[Backport release/3.10] netCDF multidim: report correct axis order when reading SRS with EPSG geographic CRS + geoid model
  • Loading branch information
rouault authored Dec 2, 2024
2 parents 0bc2d8c + 8ca24d7 commit 31a4e9c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
27 changes: 27 additions & 0 deletions autotest/gdrivers/netcdf_multidim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4157,3 +4157,30 @@ def check_metadata():

assert os.path.exists(pam_filename)
os.unlink(pam_filename)


###############################################################################


@gdaltest.enable_exceptions()
@pytest.mark.require_proj(9)
def test_netcdf_multidim_WGS84_and_EGM96_height(tmp_path):

tmp_filename = str(tmp_path / "out.nc")
with gdal.GetDriverByName("netCDF").Create(tmp_filename, 3, 3) as ds:
srs = osr.SpatialReference()
srs.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER)
srs.ImportFromEPSG(9707)
ds.SetSpatialRef(srs)
ds.SetGeoTransform([2, 1, 0, 49, 0, -1])
with gdal.Open(tmp_filename) as ds:
srs = ds.GetSpatialRef()
assert srs.GetAuthorityCode(None) == "9707"
# We currently report a 3rd axis, which is dubious
assert srs.GetDataAxisToSRSAxisMapping()[0:2] == [2, 1]
with gdal.OpenEx(tmp_filename, gdal.OF_MULTIDIM_RASTER) as ds:
rg = ds.GetRootGroup()
ar = rg.OpenMDArray("Band1")
srs = ar.GetSpatialRef()
assert srs.GetAuthorityCode(None) == "9707"
assert srs.GetDataAxisToSRSAxisMapping() == [1, 2]
5 changes: 3 additions & 2 deletions frmts/netcdf/netcdfmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2645,8 +2645,9 @@ std::shared_ptr<OGRSpatialReference> netCDFVariable::GetSpatialRef() const
m_poSRS.reset(poSRS->Clone());
if (iDimX > 0 && iDimY > 0)
{
if (m_poSRS->GetDataAxisToSRSAxisMapping() ==
std::vector<int>{2, 1})
const auto &oMapping = m_poSRS->GetDataAxisToSRSAxisMapping();
if (oMapping == std::vector<int>{2, 1} ||
oMapping == std::vector<int>{2, 1, 3})
m_poSRS->SetDataAxisToSRSAxisMapping({iDimY, iDimX});
else
m_poSRS->SetDataAxisToSRSAxisMapping({iDimX, iDimY});
Expand Down

0 comments on commit 31a4e9c

Please sign in to comment.