Skip to content

Commit

Permalink
TIFF SRS import: better deal when angular unit of the GEOGCS[] of the…
Browse files Browse the repository at this point in the history
… PROJCS[] doesn't match the one from the database

Requires OSGeo/PROJ#3274
  • Loading branch information
rouault committed Aug 1, 2022
1 parent e8c535f commit 1c2ca94
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
16 changes: 15 additions & 1 deletion frmts/gtiff/gt_wkt_srs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ static const char * const papszDatumEquiv[] =
constexpr geokey_t CoordinateEpochGeoKey = static_cast<geokey_t>(5120);
#endif

// Exists since 8.0.1
#ifndef PROJ_AT_LEAST_VERSION
#define PROJ_COMPUTE_VERSION(maj,min,patch) ((maj)*10000+(min)*100+(patch))
#define PROJ_VERSION_NUMBER \
PROJ_COMPUTE_VERSION(PROJ_VERSION_MAJOR, PROJ_VERSION_MINOR, PROJ_VERSION_PATCH)
#define PROJ_AT_LEAST_VERSION(maj,min,patch) \
(PROJ_VERSION_NUMBER >= PROJ_COMPUTE_VERSION(maj,min,patch))
#endif

/************************************************************************/
/* LibgeotiffOneTimeInit() */
/************************************************************************/
Expand Down Expand Up @@ -1675,7 +1684,12 @@ OGRSpatialReferenceH GTIFGetOGISDefnAsOSR( GTIF *hGTIF, GTIFDefn * psDefn )
"FORMAT=WKT1", "ADD_TOWGS84_ON_EXPORT_TO_WKT1=NO", nullptr };
if( oSRS.exportToWkt( &pszWKT, apszOptions ) == OGRERR_NONE )
{
oSRS.importFromWkt(pszWKT);
const char* const apszOptionsImport[] = {
#if PROJ_AT_LEAST_VERSION(9,1,0)
"UNSET_IDENTIFIERS_IF_INCOMPATIBLE_DEF=NO",
#endif
nullptr };
oSRS.importFromWkt(pszWKT, apszOptionsImport);
}
CPLFree(pszWKT);
}
Expand Down
4 changes: 4 additions & 0 deletions ogr/ogr_spatialref.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class CPL_DLL OGRSpatialReference
;

OGRErr importFromWkt( const char ** );
/*! @cond Doxygen_Suppress */
OGRErr importFromWkt( const char * pszInput, CSLConstList papszOptions);
OGRErr importFromWkt( const char ** ppszInput, CSLConstList papszOptions);
/*! @endcond */
OGRErr importFromWkt( const char* );
OGRErr importFromProj4( const char * );
OGRErr importFromEPSG( int );
Expand Down
33 changes: 30 additions & 3 deletions ogr/ogrspatialreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ void OGRSpatialReference::Private::refreshProjObj()
m_coordinateEpoch = dfCoordinateEpochBackup;
m_bHasCenterLong = strstr(pszWKT, "CENTER_LONG") != nullptr;

const char* const options[] = { "STRICT=NO", nullptr };
const char* const options[] = { "STRICT=NO",
#if PROJ_AT_LEAST_VERSION(9,1,0)
"UNSET_IDENTIFIERS_IF_INCOMPATIBLE_DEF=NO",
#endif
nullptr };
PROJ_STRING_LIST warnings = nullptr;
PROJ_STRING_LIST errors = nullptr;
setPjCRS(proj_create_from_wkt(
Expand Down Expand Up @@ -1840,6 +1844,26 @@ OGRErr OSRExportToPROJJSON( OGRSpatialReferenceH hSRS,

OGRErr OGRSpatialReference::importFromWkt( const char ** ppszInput )

{
return importFromWkt(ppszInput, nullptr);
}

/************************************************************************/
/* importFromWkt() */
/************************************************************************/

/*! @cond Doxygen_Suppress */

OGRErr OGRSpatialReference::importFromWkt( const char * pszInput,
CSLConstList papszOptions )

{
return importFromWkt(&pszInput, papszOptions);
}

OGRErr OGRSpatialReference::importFromWkt( const char ** ppszInput,
CSLConstList papszOptions )

{
if( !ppszInput || !*ppszInput )
return OGRERR_FAILURE;
Expand Down Expand Up @@ -1868,11 +1892,13 @@ OGRErr OGRSpatialReference::importFromWkt( const char ** ppszInput )
}
else
{
const char* const options[] = { "STRICT=NO", nullptr };
CPLStringList aosOptions(papszOptions);
if( aosOptions.FetchNameValue("STRICT") == nullptr )
aosOptions.SetNameValue("STRICT", "NO");
PROJ_STRING_LIST warnings = nullptr;
PROJ_STRING_LIST errors = nullptr;
d->setPjCRS(proj_create_from_wkt(
d->getPROJContext(), *ppszInput, options, &warnings, &errors));
d->getPROJContext(), *ppszInput, aosOptions.List(), &warnings, &errors));
for( auto iter = warnings; iter && *iter; ++iter ) {
d->m_wktImportWarnings.push_back(*iter);
}
Expand Down Expand Up @@ -1948,6 +1974,7 @@ OGRErr OGRSpatialReference::importFromWkt( const char ** ppszInput )
}
#endif
}
/*! @endcond */

/**
* \brief Import from WKT string.
Expand Down

0 comments on commit 1c2ca94

Please sign in to comment.