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.4] GTiff: only emit warnings on libgeotiff PROJ errors (fixes #4801) #4829

Merged
merged 1 commit into from
Nov 15, 2021
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 not shown.
9 changes: 9 additions & 0 deletions autotest/gcore/tiff_srs.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,12 @@ def test_tiff_srs_try_write_derived_geographic():
ds = None

gdal.Unlink(tmpfile)


def test_tiff_srs_read_GeogGeodeticDatumGeoKey_reserved_range():
ds = gdal.Open('data/gtiff/GeogGeodeticDatumGeoKey_reserved.tif')
with gdaltest.error_handler():
sr = ds.GetSpatialRef()
assert sr.GetName() == "WGS 84 / Pseudo-Mercator"
assert gdal.GetLastErrorMsg() != ''
assert gdal.GetLastErrorType() == gdal.CE_Warning
66 changes: 45 additions & 21 deletions gdal/frmts/gtiff/geotiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12844,40 +12844,64 @@ void GTiffDataset::LookForProjection()
{
GTIFDefn *psGTIFDefn = GTIFAllocDefn();

if( GTIFGetDefn( hGTIF, psGTIFDefn ) )
// Collect (PROJ) error messages and remit them later as warnings
std::vector<CPLErrorHandlerAccumulatorStruct> aoErrors;
CPLInstallErrorHandlerAccumulator(aoErrors);
const int ret = GTIFGetDefn( hGTIF, psGTIFDefn );
CPLUninstallErrorHandlerAccumulator();

if( ret )
{
CPLInstallErrorHandlerAccumulator(aoErrors);
OGRSpatialReferenceH hSRS = GTIFGetOGISDefnAsOSR( hGTIF, psGTIFDefn );
CPLUninstallErrorHandlerAccumulator();

if( hSRS )
{
m_oSRS = *(OGRSpatialReference::FromHandle(hSRS));
OSRDestroySpatialReference(hSRS);
}
}

if( m_oSRS.IsCompound() )
std::set<std::string> oSetErrorMsg;
for( const auto& oError: aoErrors )
{
// Some error messages might be duplicated in GTIFGetDefn()
// and GTIFGetOGISDefnAsOSR(). Emit them just once.
if( oSetErrorMsg.find(oError.msg) == oSetErrorMsg.end() )
{
const char* pszVertUnit = nullptr;
m_oSRS.GetTargetLinearUnits("COMPD_CS|VERT_CS", &pszVertUnit);
if( pszVertUnit && !EQUAL(pszVertUnit, "unknown") )
{
CPLFree(m_pszVertUnit);
m_pszVertUnit = CPLStrdup(pszVertUnit);
}
oSetErrorMsg.insert(oError.msg);
CPLError( oError.type == CE_Failure ? CE_Warning : oError.type,
oError.no,
"%s",
oError.msg.c_str() );
}
}

int versions[3];
GTIFDirectoryInfo(hGTIF, versions, nullptr);
if( m_oSRS.IsCompound() )
{
const char* pszVertUnit = nullptr;
m_oSRS.GetTargetLinearUnits("COMPD_CS|VERT_CS", &pszVertUnit);
if( pszVertUnit && !EQUAL(pszVertUnit, "unknown") )
{
CPLFree(m_pszVertUnit);
m_pszVertUnit = CPLStrdup(pszVertUnit);
}

// If GeoTIFF 1.0, strip vertical by default
const char* pszDefaultReportCompdCS =
( versions[0] == 1 && versions[1]== 1 && versions[2] == 0 ) ? "NO" : "YES";
int versions[3];
GTIFDirectoryInfo(hGTIF, versions, nullptr);

// Should we simplify away vertical CS stuff?
if( !CPLTestBool( CPLGetConfigOption("GTIFF_REPORT_COMPD_CS",
pszDefaultReportCompdCS) ) )
{
CPLDebug( "GTiff", "Got COMPD_CS, but stripping it." );
// If GeoTIFF 1.0, strip vertical by default
const char* pszDefaultReportCompdCS =
( versions[0] == 1 && versions[1]== 1 && versions[2] == 0 ) ? "NO" : "YES";

m_oSRS.StripVertical();
}
// Should we simplify away vertical CS stuff?
if( !CPLTestBool( CPLGetConfigOption("GTIFF_REPORT_COMPD_CS",
pszDefaultReportCompdCS) ) )
{
CPLDebug( "GTiff", "Got COMPD_CS, but stripping it." );

m_oSRS.StripVertical();
}
}

Expand Down