Skip to content

Commit c80c4c9

Browse files
authored
Merge pull request OSGeo#12549 from rouault/netcdf_read_rotated_pole_without_geogcrs_def
netCDF: support reading SRS/geotransfrom from Rotated Latitude Longitude grid mapping without ellipsoid definition
2 parents 8b71ddc + 7dadda5 commit c80c4c9

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed
Binary file not shown.

autotest/gdrivers/netcdf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6761,3 +6761,17 @@ def test_netcdf_geotransform_preserved_createcopy(tmp_path):
67616761
dst = gdal.GetDriverByName("netCDF").CreateCopy(tmp_path / "test.nc", src)
67626762

67636763
assert dst.GetGeoTransform() == src.GetGeoTransform()
6764+
6765+
6766+
###############################################################################
6767+
#
6768+
6769+
6770+
@pytest.mark.require_proj(8, 2)
6771+
def test_netcdf_read_rotated_pole_without_geogcrs_def():
6772+
6773+
ds = gdal.Open("data/netcdf/rotated_pole_without_geogcrs_def.nc")
6774+
assert ds.GetSpatialRef().IsDerivedGeographic()
6775+
assert [x for x in ds.GetGeoTransform()] == pytest.approx(
6776+
[144.0, 0.1, 0.0, -27.9, 0.0, -0.1]
6777+
)

ogr/ogr_srs_cf1.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,16 @@ OGRErr OGRSpatialReference::importFromCF1(CSLConstList papszKeyValues,
728728
const double dfNorthPoleGridLong = FetchDoubleParam(
729729
papszKeyValues, CF_PP_NORTH_POLE_GRID_LONGITUDE, 0.0);
730730

731+
if (!bGotGeogCS)
732+
SetWellKnownGeogCS("WGS84");
733+
731734
bRotatedPole = true;
732735
SetDerivedGeogCRSWithPoleRotationNetCDFCFConvention(
733736
"Rotated_pole", dfGridNorthPoleLat, dfGridNorthPoleLong,
734737
dfNorthPoleGridLong);
735738
}
736739

737-
if (IsProjected())
740+
if (IsProjected() && !bRotatedPole)
738741
{
739742
const char *pszProjectedCRSName =
740743
CSLFetchNameValue(papszKeyValues, CF_PROJECTED_CRS_NAME);
@@ -748,7 +751,7 @@ OGRErr OGRSpatialReference::importFromCF1(CSLConstList papszKeyValues,
748751
SetAngularUnits(SRS_UA_DEGREE, CPLAtof(SRS_UA_DEGREE_CONV));
749752
SetAuthority("GEOGCS|UNIT", "EPSG", 9122);
750753
}
751-
else if (pszUnits != nullptr && !EQUAL(pszUnits, ""))
754+
else if (pszUnits != nullptr && !EQUAL(pszUnits, "") && !bRotatedPole)
752755
{
753756
if (EQUAL(pszUnits, "m") || EQUAL(pszUnits, "metre") ||
754757
EQUAL(pszUnits, "meter"))

0 commit comments

Comments
 (0)