Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dead code from PROJ <8.1
Browse files Browse the repository at this point in the history
nyalldawson committed Jan 29, 2025
1 parent 3109a20 commit ca9b6e5
Showing 19 changed files with 355 additions and 919 deletions.
Original file line number Diff line number Diff line change
@@ -850,25 +850,13 @@ be returned.

In the case of a compound crs, this method will always return the datum ensemble for the horizontal component.

.. warning::

This method requires PROJ 8.0 or later

:raises QgsNotSupportedException: on QGIS builds based on PROJ 7 or earlier.

.. versionadded:: 3.20
%End

QString celestialBodyName() const;
%Docstring
Attempts to retrieve the name of the celestial body associated with the CRS (e.g. "Earth").

.. warning::

This method requires PROJ 8.1 or later

:raises QgsNotSupportedException: on QGIS builds based on PROJ 8.0 or earlier.

.. versionadded:: 3.20
%End

Original file line number Diff line number Diff line change
@@ -128,12 +128,6 @@ The map keys correspond to PROJ operation IDs.
%Docstring
Returns a list of all known celestial bodies.

.. warning::

This method requires PROJ 8.1 or later

:raises QgsNotSupportedException: on QGIS builds based on PROJ 8.0 or earlier.

.. versionadded:: 3.20
%End

Original file line number Diff line number Diff line change
@@ -839,7 +839,7 @@ plate-fixed.
.. versionadded:: 3.20
%End

QgsDatumEnsemble datumEnsemble() const throw( QgsNotSupportedException );
QgsDatumEnsemble datumEnsemble() const;
%Docstring
Attempts to retrieve datum ensemble details from the CRS.

@@ -850,25 +850,13 @@ be returned.

In the case of a compound crs, this method will always return the datum ensemble for the horizontal component.

.. warning::

This method requires PROJ 8.0 or later

:raises QgsNotSupportedException: on QGIS builds based on PROJ 7 or earlier.

.. versionadded:: 3.20
%End

QString celestialBodyName() const throw( QgsNotSupportedException );
QString celestialBodyName() const;
%Docstring
Attempts to retrieve the name of the celestial body associated with the CRS (e.g. "Earth").

.. warning::

This method requires PROJ 8.1 or later

:raises QgsNotSupportedException: on QGIS builds based on PROJ 8.0 or earlier.

.. versionadded:: 3.20
%End

Original file line number Diff line number Diff line change
@@ -128,12 +128,6 @@ The map keys correspond to PROJ operation IDs.
%Docstring
Returns a list of all known celestial bodies.

.. warning::

This method requires PROJ 8.1 or later

:raises QgsNotSupportedException: on QGIS builds based on PROJ 8.0 or earlier.

.. versionadded:: 3.20
%End

12 changes: 0 additions & 12 deletions src/core/proj/qgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
@@ -1431,13 +1431,9 @@ QString QgsCoordinateReferenceSystem::celestialBodyName() const
if ( !pj )
return QString();

#if PROJ_VERSION_MAJOR>8 || (PROJ_VERSION_MAJOR==8 && PROJ_VERSION_MINOR>=1)
PJ_CONTEXT *context = QgsProjContext::get();

return QString( proj_get_celestial_body_name( context, pj ) );
#else
throw QgsNotSupportedException( QObject::tr( "Retrieving celestial body requires a QGIS build based on PROJ 8.1 or later" ) );
#endif
}

void QgsCoordinateReferenceSystem::setCoordinateEpoch( double epoch )
@@ -1466,7 +1462,6 @@ QgsDatumEnsemble QgsCoordinateReferenceSystem::datumEnsemble() const
if ( !pj )
return res;

#if PROJ_VERSION_MAJOR>=8
PJ_CONTEXT *context = QgsProjContext::get();

QgsProjUtils::proj_pj_unique_ptr ensemble = QgsProjUtils::crsToDatumEnsemble( pj );
@@ -1498,9 +1493,6 @@ QgsDatumEnsemble QgsCoordinateReferenceSystem::datumEnsemble() const
res.mMembers << details;
}
return res;
#else
throw QgsNotSupportedException( QObject::tr( "Calculating datum ensembles requires a QGIS build based on PROJ 8.0 or later" ) );
#endif
}

QgsProjectionFactors QgsCoordinateReferenceSystem::factors( const QgsPoint &point ) const
@@ -1688,11 +1680,7 @@ void QgsCoordinateReferenceSystem::setProjString( const QString &proj4String )
{
#ifdef QGISDEBUG
const int errNo = proj_context_errno( ctx );
#if PROJ_VERSION_MAJOR>=8
QgsDebugError( QStringLiteral( "proj string rejected: %1" ).arg( proj_context_errno_string( ctx, errNo ) ) );
#else
QgsDebugError( QStringLiteral( "proj string rejected: %1" ).arg( proj_errno_string( errNo ) ) );
#endif
#endif
d->mIsValid = false;
}
17 changes: 2 additions & 15 deletions src/core/proj/qgscoordinatereferencesystem.h
Original file line number Diff line number Diff line change
@@ -48,13 +48,8 @@ class QgsProjOperation;
struct PJconsts;
typedef struct PJconsts PJ;

#if PROJ_VERSION_MAJOR>=8
struct pj_ctx;
typedef struct pj_ctx PJ_CONTEXT;
#else
struct projCtx_t;
typedef struct projCtx_t PJ_CONTEXT;
#endif
#endif

// forward declaration for sqlite3
@@ -776,24 +771,16 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*
* \note In the case of a compound crs, this method will always return the datum ensemble for the horizontal component.
*
* \warning This method requires PROJ 8.0 or later
*
* \throws QgsNotSupportedException on QGIS builds based on PROJ 7 or earlier.
*
* \since QGIS 3.20
*/
QgsDatumEnsemble datumEnsemble() const SIP_THROW( QgsNotSupportedException );
QgsDatumEnsemble datumEnsemble() const;

/**
* Attempts to retrieve the name of the celestial body associated with the CRS (e.g. "Earth").
*
* \warning This method requires PROJ 8.1 or later
*
* \throws QgsNotSupportedException on QGIS builds based on PROJ 8.0 or earlier.
*
* \since QGIS 3.20
*/
QString celestialBodyName() const SIP_THROW( QgsNotSupportedException );
QString celestialBodyName() const;

/**
* Sets the coordinate \a epoch, as a decimal year.
4 changes: 0 additions & 4 deletions src/core/proj/qgscoordinatereferencesystemregistry.cpp
Original file line number Diff line number Diff line change
@@ -380,7 +380,6 @@ QMap<QString, QgsProjOperation> QgsCoordinateReferenceSystemRegistry::projOperat

QList< QgsCelestialBody> QgsCoordinateReferenceSystemRegistry::celestialBodies() const
{
#if PROJ_VERSION_MAJOR>8 || (PROJ_VERSION_MAJOR==8 && PROJ_VERSION_MINOR>=1)
static QList< QgsCelestialBody > sCelestialBodies;
static std::once_flag initialized;
std::call_once( initialized, []
@@ -409,9 +408,6 @@ QList< QgsCelestialBody> QgsCoordinateReferenceSystemRegistry::celestialBodies()
} );

return sCelestialBodies;
#else
throw QgsNotSupportedException( QObject::tr( "Retrieving celestial bodies requires a QGIS build based on PROJ 8.1 or later" ) );
#endif
}

QSet<QString> QgsCoordinateReferenceSystemRegistry::authorities() const
4 changes: 0 additions & 4 deletions src/core/proj/qgscoordinatereferencesystemregistry.h
Original file line number Diff line number Diff line change
@@ -162,10 +162,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystemRegistry : public QObject
/**
* Returns a list of all known celestial bodies.
*
* \warning This method requires PROJ 8.1 or later
*
* \throws QgsNotSupportedException on QGIS builds based on PROJ 8.0 or earlier.
*
* \since QGIS 3.20
*/
QList< QgsCelestialBody > celestialBodies() const;
6 changes: 0 additions & 6 deletions src/core/proj/qgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
@@ -193,10 +193,8 @@ bool QgsCoordinateTransform::isTransformationPossible( const QgsCoordinateRefere
if ( !source.isValid() || !destination.isValid() )
return false;

#if PROJ_VERSION_MAJOR>8 || (PROJ_VERSION_MAJOR==8 && PROJ_VERSION_MINOR>=1)
if ( source.celestialBodyName() != destination.celestialBodyName() )
return false;
#endif

return true;
}
@@ -899,12 +897,8 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *

const QString dir = ( direction == Qgis::TransformDirection::Forward ) ? QObject::tr( "Forward transform" ) : QObject::tr( "Inverse transform" );

#if PROJ_VERSION_MAJOR>=8
PJ_CONTEXT *projContext = QgsProjContext::get();
const QString projError = !errorOccurredDuringFallbackOperation ? QString::fromUtf8( proj_context_errno_string( projContext, projResult ) ) : QObject::tr( "Fallback transform failed" );
#else
const QString projError = !errorOccurredDuringFallbackOperation ? QString::fromUtf8( proj_errno_string( projResult ) ) : QObject::tr( "Fallback transform failed" );
#endif

const QString msg = QObject::tr( "%1 (%2 to %3) of%4%5Error: %6" )
.arg( dir,
8 changes: 0 additions & 8 deletions src/core/proj/qgscoordinatetransform_p.cpp
Original file line number Diff line number Diff line change
@@ -334,11 +334,7 @@ ProjData QgsCoordinateTransformPrivate::threadLocalProjData()
const int errNo = proj_context_errno( context );
if ( errNo )
{
#if PROJ_VERSION_MAJOR>=8
nonAvailableError = QString( proj_context_errno_string( context, errNo ) );
#else
nonAvailableError = QString( proj_errno_string( errNo ) );
#endif
}
else
{
@@ -473,11 +469,7 @@ ProjData QgsCoordinateTransformPrivate::threadLocalProjData()
const QStringList projErrors = errorLogger.errors();
if ( errNo )
{
#if PROJ_VERSION_MAJOR>=8
nonAvailableError = QString( proj_context_errno_string( context, errNo ) );
#else
nonAvailableError = QString( proj_errno_string( errNo ) );
#endif
}
else if ( !projErrors.empty() )
{
2 changes: 0 additions & 2 deletions src/core/proj/qgsellipsoidutils.cpp
Original file line number Diff line number Diff line change
@@ -271,9 +271,7 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
name.replace( '_', ' ' );
def.description = QStringLiteral( "%1 (%2:%3)" ).arg( name, authority, code );

#if PROJ_VERSION_MAJOR>8 || (PROJ_VERSION_MAJOR==8 && PROJ_VERSION_MINOR>=1)
def.celestialBodyName = proj_get_celestial_body_name( context, ellipsoid.get() );
#endif

double semiMajor, semiMinor, invFlattening;
int semiMinorComputed = 0;
4 changes: 0 additions & 4 deletions src/core/proj/qgsprojutils.cpp
Original file line number Diff line number Diff line change
@@ -340,7 +340,6 @@ QgsProjUtils::proj_pj_unique_ptr QgsProjUtils::crsToDatumEnsemble( const PJ *crs
if ( !crs )
return nullptr;

#if PROJ_VERSION_MAJOR>=8
PJ_CONTEXT *context = QgsProjContext::get();
QgsProjUtils::proj_pj_unique_ptr candidate = crsToHorizontalCrs( crs );
if ( !candidate ) // purely vertical CRS
@@ -350,9 +349,6 @@ QgsProjUtils::proj_pj_unique_ptr QgsProjUtils::crsToDatumEnsemble( const PJ *crs
return nullptr;

return QgsProjUtils::proj_pj_unique_ptr( proj_crs_get_datum_ensemble( context, candidate.get() ) );
#else
throw QgsNotSupportedException( QObject::tr( "Calculating datum ensembles requires a QGIS build based on PROJ 8.0 or later" ) );
#endif
}

void QgsProjUtils::proj_collecting_logger( void *user_data, int /*level*/, const char *message )
9 changes: 0 additions & 9 deletions src/core/proj/qgsprojutils.h
Original file line number Diff line number Diff line change
@@ -206,10 +206,6 @@ class CORE_EXPORT QgsProjUtils
*
* \note In the case of a compound \a crs, this method will always return the datum ensemble for the horizontal component.
*
* \warning This method requires PROJ 8.0 or later
*
* \throws QgsNotSupportedException on QGIS builds based on PROJ 7 or earlier.
*
* \since QGIS 3.20
*/
static proj_pj_unique_ptr crsToDatumEnsemble( const PJ *crs );
@@ -270,13 +266,8 @@ class CORE_EXPORT QgsProjUtils

#ifndef SIP_RUN

#if PROJ_VERSION_MAJOR>=8
struct pj_ctx;
typedef struct pj_ctx PJ_CONTEXT;
#else
struct projCtx_t;
typedef struct projCtx_t PJ_CONTEXT;
#endif

/**
* \class QgsProjContext
2 changes: 0 additions & 2 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
@@ -1672,7 +1672,6 @@ void TestQgsCoordinateReferenceSystem::isDynamic()

void TestQgsCoordinateReferenceSystem::celestialBody()
{
#if ( PROJ_VERSION_MAJOR > 8 || ( PROJ_VERSION_MAJOR == 8 && PROJ_VERSION_MINOR >= 1 ) )
QgsCoordinateReferenceSystem crs;
QCOMPARE( crs.celestialBodyName(), QString() );

@@ -1681,7 +1680,6 @@ void TestQgsCoordinateReferenceSystem::celestialBody()

crs = QgsCoordinateReferenceSystem( QStringLiteral( "ESRI:104903" ) );
QCOMPARE( crs.celestialBodyName(), QStringLiteral( "Moon" ) );
#endif
}

void TestQgsCoordinateReferenceSystem::operation()
4 changes: 0 additions & 4 deletions tests/src/core/testqgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
@@ -312,13 +312,11 @@ void TestQgsCoordinateTransform::constructorFlags()
QVERIFY( !tr4.isShortCircuited() );
QVERIFY( tr4.mIgnoreImpossible );

#if ( PROJ_VERSION_MAJOR > 8 || ( PROJ_VERSION_MAJOR == 8 && PROJ_VERSION_MINOR >= 1 ) )
QgsCoordinateTransform tr5( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ), QgsCoordinateReferenceSystem( QStringLiteral( "ESRI:104903" ) ), QgsProject::instance(), Qgis::CoordinateTransformationFlag::IgnoreImpossibleTransformations );
QVERIFY( !tr5.mBallparkTransformsAreAppropriate );
// crses are from two different celestial bodies, the transform is impossible and should be short-circuited
QVERIFY( tr5.isShortCircuited() );
QVERIFY( tr5.mIgnoreImpossible );
#endif
}

void TestQgsCoordinateTransform::scaleFactor_data()
@@ -848,10 +846,8 @@ void TestQgsCoordinateTransform::testTransformationIsPossible()
QVERIFY( !QgsCoordinateTransform::isTransformationPossible( QgsCoordinateReferenceSystem(), QgsCoordinateReferenceSystem() ) );

QVERIFY( QgsCoordinateTransform::isTransformationPossible( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) ) );
#if ( PROJ_VERSION_MAJOR > 8 || ( PROJ_VERSION_MAJOR == 8 && PROJ_VERSION_MINOR >= 1 ) )
// crses from two different celestial bodies => transformation is not possible
QVERIFY( !QgsCoordinateTransform::isTransformationPossible( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ), QgsCoordinateReferenceSystem( QStringLiteral( "ESRI:104903" ) ) ) );
#endif
}


24 changes: 3 additions & 21 deletions tests/src/python/test_provider_oracle.py
Original file line number Diff line number Diff line change
@@ -214,15 +214,6 @@ def testAddFeatureWrongGeomType(self):
"""
pass

def testCrs(self):
"""
We override this test for Oracle provider, because without PROJ >= 7
Oracle is not able to understand correctly some EPSG code (4326 for instance)
"""
# TODO remove this when PROJ will be >= 7
if QgsProjUtils.projVersionMajor() >= 7:
super().testCrs()

# HERE GO THE PROVIDER SPECIFIC TESTS
def testDateTimeTypes(self):
vl = QgsVectorLayer(
@@ -1710,10 +1701,7 @@ def testCreateEmptyLayer(self):
)
self.assertTrue(query.next())
self.assertEqual(query.value(0), "GEOM")
# Cannot work with proj version < 7 because it cannot identify properly EPSG:4326
# TODO remove this when PROJ will be >= 7
if QgsProjUtils.projVersionMajor() >= 7:
self.assertEqual(query.value(1), 4326)
self.assertEqual(query.value(1), 4326)
query.finish()

# no feature, so we cannot guess the geometry type, so the layer is not valid
@@ -1746,10 +1734,7 @@ def testCreateEmptyLayer(self):
query.exec('SELECT "l"."GEOM"."SDO_SRID" from "QGIS"."EMPTY_LAYER" "l"')
)
self.assertTrue(query.next())
# Cannot work with proj version < 7 because it cannot identify properly EPSG:4326
# TODO remove this when PROJ will be >= 7
if QgsProjUtils.projVersionMajor() >= 7:
self.assertEqual(query.value(0), 4326)
self.assertEqual(query.value(0), 4326)
query.finish()

# now we can autodetect geom type and srid
@@ -1759,10 +1744,7 @@ def testCreateEmptyLayer(self):
"oracle",
)
self.assertTrue(vl.isValid())
# Cannot work with proj version < 7 because it cannot identify properly EPSG:4326
# TODO remove this when PROJ will be >= 7
if QgsProjUtils.projVersionMajor() >= 7:
self.assertEqual(vl.sourceCrs().authid(), "EPSG:4326")
self.assertEqual(vl.sourceCrs().authid(), "EPSG:4326")

def testCreateAspatialLayer(self):
"""
295 changes: 82 additions & 213 deletions tests/src/python/test_qgsdatumtransforms.py

Large diffs are not rendered by default.

15 changes: 2 additions & 13 deletions tests/src/python/test_qgsellipsoidutils.py
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
__copyright__ = "Copyright 2017, The QGIS Project"


from qgis.core import QgsEllipsoidUtils, QgsProjUtils
from qgis.core import QgsEllipsoidUtils
import unittest
from qgis.testing import start_app, QgisTestCase

@@ -105,11 +105,7 @@ def testDefinitions(self):
self.assertEqual(gany_defs.acronym, gany_id)
self.assertEqual(gany_defs.description, "Ganymede 2000 IAU IAG (ESRI:107916)")

if QgsProjUtils.projVersionMajor() > 8 or (
QgsProjUtils.projVersionMajor() == 8
and QgsProjUtils.projVersionMinor() >= 1
):
self.assertEqual(gany_defs.celestialBodyName, "Ganymede")
self.assertEqual(gany_defs.celestialBodyName, "Ganymede")

self.assertTrue(gany_defs.parameters.valid)
self.assertEqual(gany_defs.parameters.semiMajor, 2632345.0)
@@ -118,13 +114,6 @@ def testDefinitions(self):
self.assertFalse(gany_defs.parameters.useCustomParameters)
self.assertEqual(gany_defs.parameters.crs.authid(), "")

@unittest.skipIf(
QgsProjUtils.projVersionMajor() < 8
or (
QgsProjUtils.projVersionMajor() == 8 and QgsProjUtils.projVersionMinor() < 1
),
"Not a proj >= 8.1 build",
)
def testCelestialBodies(self):
bodies = QgsEllipsoidUtils.celestialBodies()

828 changes: 264 additions & 564 deletions tests/src/python/test_qgsvectorlayerprofilegenerator.py

Large diffs are not rendered by default.

0 comments on commit ca9b6e5

Please sign in to comment.