Skip to content

Commit

Permalink
GTiff writing: workaround PROJ 6.3.0 bug when writing a EPSG:4937 ETR…
Browse files Browse the repository at this point in the history
…S89 Geog3D CRS

PROJ fix is in OSGeo/PROJ#1880
  • Loading branch information
rouault committed Jan 24, 2020
1 parent ef65c84 commit 3090465
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions autotest/gcore/tiff_srs.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,22 @@ def test_tiff_srs_write_epsg4979_geotiff1_1():
_create_geotiff1_1_from_copy_and_compare('data/epsg4979_geotiff1_1.tif')


def test_tiff_srs_write_epsg4937_etrs89_3D_geotiff1_1():
if int(gdal.GetDriverByName('GTiff').GetMetadataItem('LIBGEOTIFF')) < 1600:
pytest.skip()
tmpfile = '/vsimem/tmp.tif'
ds = gdal.GetDriverByName('GTiff').Create(tmpfile, 1, 1)
sr = osr.SpatialReference()
sr.ImportFromEPSG(4937)
ds.SetSpatialRef(sr)
ds = None
ds = gdal.Open(tmpfile)
assert sr.GetName() == 'ETRS89'
assert sr.GetAuthorityCode(None) == '4937'
ds = None
gdal.Unlink(tmpfile)


# Deprecated way of conveying GeographicCRS 3D
def test_tiff_srs_read_epsg4326_5030_geotiff1_1():
ds = gdal.Open('data/epsg4326_5030_geotiff1_1.tif')
Expand Down
11 changes: 10 additions & 1 deletion gdal/frmts/gtiff/gt_wkt_srs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,16 @@ int GTIFSetFromOGISDefnEx( GTIF * psGTIF, const char *pszOGCWKT,
int nVerticalCSKeyValue = 0;
bool hasEllipsoidHeight = !poSRS->IsCompound() &&
poSRS->IsGeographic() && poSRS->GetAxesCount() == 3;
if( nGCS != KvUserDefined )
if( nGCS == 4937 && eVersion >= GEOTIFF_VERSION_1_1 )
{
// Workaround a bug of PROJ 6.3.0
// See https://github.com/OSGeo/PROJ/pull/1880
// EPSG:4937 = ETRS89 3D
hasEllipsoidHeight = true;
nVerticalCSKeyValue = nGCS;
nGCS = 4258; // ETRS89 2D
}
else if( nGCS != KvUserDefined )
{
OGRSpatialReference oGeogCRS;
if( oGeogCRS.importFromEPSG(nGCS) == OGRERR_NONE &&
Expand Down

0 comments on commit 3090465

Please sign in to comment.