80 changes: 1 addition & 79 deletions src/app/qgsdatumtransformtablewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,49 +60,23 @@ void QgsDatumTransformTableModel::removeTransform( const QModelIndexList &indexe
int QgsDatumTransformTableModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent )
#if PROJ_VERSION_MAJOR>=6
return mTransformContext.coordinateOperations().count();
#else
Q_NOWARN_DEPRECATED_PUSH
return mTransformContext.sourceDestinationDatumTransforms().count();
Q_NOWARN_DEPRECATED_POP
#endif
}

int QgsDatumTransformTableModel::columnCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent )
#if PROJ_VERSION_MAJOR>=6
return 4;
#else
return 4;
#endif
}

QVariant QgsDatumTransformTableModel::data( const QModelIndex &index, int role ) const
{
QString sourceCrs;
QString destinationCrs;
#if PROJ_VERSION_MAJOR>=6
QPair< QString, QString> crses = mTransformContext.coordinateOperations().keys().at( index.row() );
#else
int sourceTransform = -1;
int destinationTransform = -1;
Q_NOWARN_DEPRECATED_PUSH
QPair< QString, QString> crses = mTransformContext.sourceDestinationDatumTransforms().keys().at( index.row() );
Q_NOWARN_DEPRECATED_POP
#endif
sourceCrs = crses.first;
destinationCrs = crses.second;
#if PROJ_VERSION_MAJOR>=6
const QString proj = mTransformContext.coordinateOperations().value( crses );
#else
Q_NOWARN_DEPRECATED_PUSH
const QgsDatumTransform::TransformPair transforms = mTransformContext.sourceDestinationDatumTransforms().value( crses );
Q_NOWARN_DEPRECATED_POP
sourceTransform = transforms.sourceTransformId;
destinationTransform = transforms.destinationTransformId;
#endif

switch ( role )
{
Expand All @@ -121,36 +95,15 @@ QVariant QgsDatumTransformTableModel::data( const QModelIndex &index, int role )
case DestinationCrsColumn:
return destinationCrs;

#if PROJ_VERSION_MAJOR>=6
case ProjDefinitionColumn:
return proj;
#else
case SourceTransformColumn:
if ( sourceTransform != -1 )
{
Q_NOWARN_DEPRECATED_PUSH
return QgsDatumTransform::datumTransformToProj( sourceTransform );
Q_NOWARN_DEPRECATED_POP
}
break;

case DestinationTransformColumn:
if ( destinationTransform != -1 )
{
Q_NOWARN_DEPRECATED_PUSH
return QgsDatumTransform::datumTransformToProj( destinationTransform );
Q_NOWARN_DEPRECATED_POP
}
break;
#endif

default:
break;
}
break;

case Qt::CheckStateRole:
#if PROJ_VERSION_MAJOR>=6
switch ( index.column() )
{
case AllowFallbackColumn:
Expand All @@ -159,23 +112,10 @@ QVariant QgsDatumTransformTableModel::data( const QModelIndex &index, int role )
break;
}
break;
#endif

case Qt::UserRole:
#if PROJ_VERSION_MAJOR>=6
return proj;
#else
switch ( index.column() )
{
case SourceTransformColumn:
return sourceTransform;
case DestinationTransformColumn:
return destinationTransform;
default:
break;
}
break;
#endif

default:
break;
}
Expand All @@ -198,18 +138,10 @@ QVariant QgsDatumTransformTableModel::headerData( int section, Qt::Orientation o
return tr( "Source CRS" );
case DestinationCrsColumn:
return tr( "Destination CRS" );

#if PROJ_VERSION_MAJOR>=6
case ProjDefinitionColumn:
return tr( "Operation" );
case AllowFallbackColumn:
return tr( "Allow Fallback Transforms" );
#else
case SourceTransformColumn:
return tr( "Source Datum Transform" );
case DestinationTransformColumn:
return tr( "Destination Datum Transform" );
#endif
default:
break;
}
Expand Down Expand Up @@ -302,20 +234,10 @@ void QgsDatumTransformTableWidget::editDatumTransform( const QModelIndex &index
QgsCoordinateReferenceSystem destinationCrs = QgsCoordinateReferenceSystem( mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::DestinationCrsColumn ), Qt::DisplayRole ).toString() );

bool allowFallback = true;
#if PROJ_VERSION_MAJOR>=6
proj = mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::ProjDefinitionColumn ), Qt::UserRole ).toString();
allowFallback = mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::AllowFallbackColumn ), Qt::CheckStateRole ) == Qt::Checked;
#else
sourceTransform = mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::SourceTransformColumn ), Qt::UserRole ).toInt();
destinationTransform = mModel->data( mModel->index( index.row(), QgsDatumTransformTableModel::DestinationTransformColumn ), Qt::UserRole ).toInt();
#endif

#if PROJ_VERSION_MAJOR>=6
if ( sourceCrs.isValid() && destinationCrs.isValid() )
#else
if ( sourceCrs.isValid() && destinationCrs.isValid() &&
( sourceTransform != -1 || destinationTransform != -1 ) )
#endif
{
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, true, false, false, qMakePair( sourceTransform, destinationTransform ), nullptr, Qt::WindowFlags(), proj, QgisApp::instance()->mapCanvas(), allowFallback );
if ( dlg.exec() )
Expand Down
7 changes: 0 additions & 7 deletions src/app/qgsdatumtransformtablewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,10 @@ class APP_EXPORT QgsDatumTransformTableModel : public QAbstractTableModel

enum TableColumns
{
#if PROJ_VERSION_MAJOR>=6
SourceCrsColumn = 0,
DestinationCrsColumn,
ProjDefinitionColumn,
AllowFallbackColumn,
#else
SourceCrsColumn = 0,
SourceTransformColumn,
DestinationCrsColumn,
DestinationTransformColumn,
#endif
};

QgsDatumTransformTableModel( QObject *parent = nullptr );
Expand Down
8 changes: 0 additions & 8 deletions src/core/processing/qgsprocessingfeedback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
#include "qgsprocessingprovider.h"
#include <ogr_api.h>
#include <gdal_version.h>
#if PROJ_VERSION_MAJOR > 4
#include <proj.h>
#else
#include <proj_api.h>
#endif

#ifdef HAVE_PDAL
#include <pdal/pdal.hpp>
Expand Down Expand Up @@ -105,12 +101,8 @@ void QgsProcessingFeedback::pushVersionInfo( const QgsProcessingProvider *provid
pushDebugInfo( tr( "GDAL version: %1" ).arg( GDALVersionInfo( "RELEASE_NAME" ) ) );
pushDebugInfo( tr( "GEOS version: %1" ).arg( GEOSversion() ) );

#if PROJ_VERSION_MAJOR > 4
PJ_INFO info = proj_info();
pushDebugInfo( tr( "PROJ version: %1" ).arg( info.release ) );
#else
pushDebugInfo( tr( "PROJ version: %1" ).arg( PJ_VERSION ) );
#endif

#ifdef HAVE_PDAL
#if PDAL_VERSION_MAJOR_INT > 1 || (PDAL_VERSION_MAJOR_INT == 1 && PDAL_VERSION_MINOR_INT >= 7)
Expand Down
2 changes: 0 additions & 2 deletions src/core/processing/qgsprocessingregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ QgsProcessingRegistry::QgsProcessingRegistry( QObject *parent SIP_TRANSFERTHIS )
addParameterType( new QgsProcessingParameterTypeLayout() );
addParameterType( new QgsProcessingParameterTypeLayoutItem() );
addParameterType( new QgsProcessingParameterTypeColor() );
#if PROJ_VERSION_MAJOR>=6
addParameterType( new QgsProcessingParameterTypeCoordinateOperation() );
#endif
addParameterType( new QgsProcessingParameterTypeMapTheme() );
addParameterType( new QgsProcessingParameterTypeDateTime() );
addParameterType( new QgsProcessingParameterTypeProviderConnection() );
Expand Down
40 changes: 0 additions & 40 deletions src/core/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3969,21 +3969,8 @@ bool QgsOgrProviderUtils::createEmptyDataSource( const QString &uri,
{
QString layerName = uri.left( index );
QFile prjFile( layerName + ".qpj" );
#if PROJ_VERSION_MAJOR<6
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream prjStream( &prjFile );
prjStream << myWkt.toLocal8Bit().data() << endl;
prjFile.close();
}
else
{
QgsMessageLog::logMessage( QObject::tr( "Couldn't create file %1.qpj" ).arg( layerName ), QObject::tr( "OGR" ) );
}
#else
if ( prjFile.exists() )
prjFile.remove();
#endif
}
}

Expand All @@ -4009,33 +3996,6 @@ QgsCoordinateReferenceSystem QgsOgrProvider::crs() const
if ( !mValid || ( mOGRGeomType == wkbNone ) )
return srs;

#if PROJ_VERSION_MAJOR<6
if ( mGDALDriverName == QLatin1String( "ESRI Shapefile" ) )
{
int index = mFilePath.indexOf( QLatin1String( ".shp" ), Qt::CaseInsensitive );
if ( index > 0 )
{
QString layerName = mFilePath.left( index );
QFile prjFile( layerName + ".qpj" );
if ( prjFile.open( QIODevice::ReadOnly ) )
{
QTextStream prjStream( &prjFile );
QString myWktString = prjStream.readLine();
prjFile.close();

srs = QgsCoordinateReferenceSystem::fromWkt( myWktString.toUtf8().constData() );
if ( srs.isValid() )
return srs;
}
}
}

// add towgs84 parameter
Q_NOWARN_DEPRECATED_PUSH
QgsCoordinateReferenceSystem::setupESRIWktFix();
Q_NOWARN_DEPRECATED_POP
#endif

if ( OGRSpatialReferenceH spatialRefSys = mOgrLayer->GetSpatialRef() )
{
srs = QgsOgrUtils::OGRSpatialReferenceToCrs( spatialRefSys );
Expand Down
16 changes: 0 additions & 16 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,25 +679,9 @@ void CORE_EXPORT qgsFree( void *ptr ) SIP_SKIP;
*/
CONSTLATIN1STRING geoWkt()
{
#if PROJ_VERSION_MAJOR>=6
return QLatin1String(
R"""(GEOGCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["unknown"],AREA["World"],BBOX[-90,-180,90,180]],ID["EPSG",4326]] )"""
);
#else
return QLatin1String(
"GEOGCS[\"WGS 84\", "
" DATUM[\"WGS_1984\", "
" SPHEROID[\"WGS 84\",6378137,298.257223563, "
" AUTHORITY[\"EPSG\",\"7030\"]], "
" TOWGS84[0,0,0,0,0,0,0], "
" AUTHORITY[\"EPSG\",\"6326\"]], "
" PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]], "
" UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]], "
" AXIS[\"Lat\",NORTH], "
" AXIS[\"Long\",EAST], "
" AUTHORITY[\"EPSG\",\"4326\"]]"
);
#endif
}

//! PROJ4 string that represents a geographic coord sys
Expand Down
12 changes: 0 additions & 12 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@
#include <sqlite3.h>
#include <mutex>

#if PROJ_VERSION_MAJOR>=6
#include <proj.h>
#endif


#define CONN_POOL_MAX_CONCURRENT_CONNS 4
Expand Down Expand Up @@ -354,7 +352,6 @@ void QgsApplication::init( QString profileFolder )
}
#endif

#if PROJ_VERSION_MAJOR>=6
// append local user-writable folder as a proj search path
QStringList currentProjSearchPaths = QgsProjUtils::searchPaths();
currentProjSearchPaths.append( qgisSettingsDirPath() + QStringLiteral( "proj" ) );
Expand All @@ -378,7 +375,6 @@ void QgsApplication::init( QString profileFolder )
CPLFree( newPaths[i] );
}
delete [] newPaths;
#endif // PROJ_VERSION_MAJOR>=6

// allow Qt to search for Qt plugins (e.g. sqldrivers) in our plugin directory
QCoreApplication::addLibraryPath( pluginPath() );
Expand Down Expand Up @@ -1039,19 +1035,11 @@ QString QgsApplication::srsDatabaseFilePath()
{
if ( ABISYM( mRunningFromBuildDir ) )
{
#if PROJ_VERSION_MAJOR>=6
QString tempCopy = QDir::tempPath() + "/srs6.db";
#else
QString tempCopy = QDir::tempPath() + "/srs.db";
#endif

if ( !QFile( tempCopy ).exists() )
{
#if PROJ_VERSION_MAJOR>=6
QFile f( buildSourcePath() + "/resources/srs6.db" );
#else
QFile f( buildSourcePath() + "/resources/srs.db" );
#endif
if ( !f.copy( tempCopy ) )
{
qFatal( "Could not create temporary copy" );
Expand Down
1,083 changes: 3 additions & 1,080 deletions src/core/qgscoordinatereferencesystem.cpp

Large diffs are not rendered by default.

18 changes: 1 addition & 17 deletions src/core/qgscoordinatereferencesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class QDomNode;
class QDomDocument;
class QgsCoordinateReferenceSystemPrivate;

#if PROJ_VERSION_MAJOR>=6
#ifndef SIP_RUN
struct PJconsts;
typedef struct PJconsts PJ;
Expand All @@ -53,7 +52,6 @@ struct projCtx_t;
typedef struct projCtx_t PJ_CONTEXT;
#endif
#endif
#endif

// forward declaration for sqlite3
typedef struct sqlite3 sqlite3 SIP_SKIP;
Expand Down Expand Up @@ -819,7 +817,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
#endif

#ifndef SIP_RUN
#if PROJ_VERSION_MAJOR>=6

/**
* Returns the underlying PROJ PJ object corresponding to the CRS, or NULLPTR
Expand All @@ -831,7 +828,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* \since QGIS 3.8
*/
PJ *projObject() const;
#endif
#endif

/**
Expand Down Expand Up @@ -900,7 +896,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
/**
* Set the WKT string
*/
bool setWktString( const QString &wkt, bool allowProjFallback = true );
bool setWktString( const QString &wkt );

/**
* Print the description if debugging
Expand Down Expand Up @@ -931,7 +927,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
//! Helper for getting number of user CRS already in db
static long getRecordCount();

#if PROJ_VERSION_MAJOR>=6
bool loadFromAuthCode( const QString &auth, const QString &code );

/**
Expand All @@ -947,7 +942,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* criteria).
*/
long matchToUserCrs() const;
#endif

/**
* Initialize the CRS object by looking up CRS database in path given in db argument,
Expand All @@ -957,24 +951,14 @@ class CORE_EXPORT QgsCoordinateReferenceSystem

bool createFromWktInternal( const QString &wkt, const QString &description );

#if PROJ_VERSION_MAJOR<6 // not used for proj >= 6.0
static bool loadIds( QHash<int, QString> &wkts );
static bool loadWkts( QHash<int, QString> &wkts, const char *filename );

//! Update datum shift definitions from GDAL data. Used by syncDb()
static bool syncDatumTransform( const QString &dbPath );
#endif

QExplicitlySharedDataPointer<QgsCoordinateReferenceSystemPrivate> d;

QString mValidationHint;

#if PROJ_VERSION_MAJOR>=6
friend class QgsProjContext;

// Only meant to be called by QgsProjContext::~QgsProjContext()
static void removeFromCacheObjectsBelongingToCurrentThread( PJ_CONTEXT *pj_context );
#endif

//! Function for CRS validation. May be NULLPTR.
static CUSTOM_CRS_VALIDATION sCustomSrsValidation;
Expand Down
2 changes: 0 additions & 2 deletions src/core/qgscoordinatereferencesystem_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <QMap>
#include <QString>

#if PROJ_VERSION_MAJOR>=6
// maps QGIS custom db srs ids to proj auth/codes
const QMap< QString, QString > sAuthIdToQgisSrsIdMap
{
Expand Down Expand Up @@ -10104,4 +10103,3 @@ const QMap< QString, QString > sAuthIdToQgisSrsIdMap
{"IGNF:RGWF96GDD", "63319,520003319"},
{"IGNF:RGWF96GEODD", "63320,520003320"},
};
#endif // PROJ_VERSION_MAJOR>=6
35 changes: 0 additions & 35 deletions src/core/qgscoordinatereferencesystem_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@

#include "qgscoordinatereferencesystem.h"

#if PROJ_VERSION_MAJOR>=6
#include <proj.h>
#include "qgsprojutils.h"
#include "qgsreadwritelocker.h"
#else
#include <ogr_srs_api.h>
#endif

#ifdef DEBUG
typedef struct OGRSpatialReferenceHS *OGRSpatialReferenceH;
Expand All @@ -50,9 +46,6 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
public:

explicit QgsCoordinateReferenceSystemPrivate()
#if PROJ_VERSION_MAJOR<6
: mCRS( OSRNewSpatialReference( nullptr ) )
#endif
{
}

Expand All @@ -67,43 +60,23 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
, mSRID( other.mSRID )
, mAuthId( other.mAuthId )
, mIsValid( other.mIsValid )
#if PROJ_VERSION_MAJOR >= 6
, mPj()
#else
, mCRS( nullptr )
#endif
, mProj4( other.mProj4 )
, mWktPreferred( other.mWktPreferred )
, mAxisInvertedDirty( other.mAxisInvertedDirty )
, mAxisInverted( other.mAxisInverted )
#if PROJ_VERSION_MAJOR >= 6
, mProjObjects()
#endif
{
#if PROJ_VERSION_MAJOR<6
if ( mIsValid )
{
mCRS = OSRClone( other.mCRS );
}
else
{
mCRS = OSRNewSpatialReference( nullptr );
}
#endif
}

~QgsCoordinateReferenceSystemPrivate()
{
#if PROJ_VERSION_MAJOR>=6
QgsReadWriteLocker locker( mProjLock, QgsReadWriteLocker::Read );
if ( !mProjObjects.empty() || mPj )
{
locker.changeMode( QgsReadWriteLocker::Write );
cleanPjObjects();
}
#else
OSRDestroySpatialReference( mCRS );
#endif
}

//! The internal sqlite3 srs.db primary key for this CRS
Expand Down Expand Up @@ -133,8 +106,6 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
//! Whether this CRS is properly defined and valid
bool mIsValid = false;

#if PROJ_VERSION_MAJOR>=6

// this is the "master" proj object, to be used as a template for new proj objects created on different threads ONLY.
// Always use threadLocalProjObject() instead of this.

Expand Down Expand Up @@ -182,10 +153,6 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
return static_cast< bool >( mPj );
}

#else
OGRSpatialReferenceH mCRS = nullptr;
#endif

mutable QString mProj4;

mutable QString mWktPreferred;
Expand All @@ -196,7 +163,6 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData
//! Whether this is a coordinate system has inverted axis
mutable bool mAxisInverted = false;

#if PROJ_VERSION_MAJOR>=6
private:
mutable QReadWriteLock mProjLock{};
mutable QMap < PJ_CONTEXT *, PJ * > mProjObjects{};
Expand Down Expand Up @@ -245,7 +211,6 @@ class QgsCoordinateReferenceSystemPrivate : public QSharedData

return mProjObjects.isEmpty();
}
#endif

private:
QgsCoordinateReferenceSystemPrivate &operator= ( const QgsCoordinateReferenceSystemPrivate & ) = delete;
Expand Down
152 changes: 1 addition & 151 deletions src/core/qgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@
#include <QStringList>
#include <QVector>

#if PROJ_VERSION_MAJOR>=6
#include <proj.h>
#include "qgsprojutils.h"
#else
#include <proj_api.h>
#endif

#include <sqlite3.h>
#include <qlogging.h>
Expand Down Expand Up @@ -74,11 +70,7 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
return;

Q_NOWARN_DEPRECATED_PUSH
#if PROJ_VERSION_MAJOR>=6
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mProjCoordinateOperation, d->mAllowFallbackTransforms ) )
#else
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
#endif
{
d->initialize();
addToCache();
Expand All @@ -99,11 +91,7 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
return;

Q_NOWARN_DEPRECATED_PUSH
#if PROJ_VERSION_MAJOR>=6
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mProjCoordinateOperation, d->mAllowFallbackTransforms ) )
#else
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
#endif
{
d->initialize();
addToCache();
Expand All @@ -122,11 +110,7 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
return;

Q_NOWARN_DEPRECATED_PUSH
#if PROJ_VERSION_MAJOR>=6
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mProjCoordinateOperation, d->mAllowFallbackTransforms ) )
#else
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
#endif
{
d->initialize();
addToCache();
Expand Down Expand Up @@ -166,11 +150,7 @@ void QgsCoordinateTransform::setSourceCrs( const QgsCoordinateReferenceSystem &c

d->calculateTransforms( mContext );
Q_NOWARN_DEPRECATED_PUSH
#if PROJ_VERSION_MAJOR>=6
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mProjCoordinateOperation, d->mAllowFallbackTransforms ) )
#else
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
#endif
{
d->initialize();
addToCache();
Expand All @@ -186,11 +166,7 @@ void QgsCoordinateTransform::setDestinationCrs( const QgsCoordinateReferenceSyst

d->calculateTransforms( mContext );
Q_NOWARN_DEPRECATED_PUSH
#if PROJ_VERSION_MAJOR>=6
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mProjCoordinateOperation, d->mAllowFallbackTransforms ) )
#else
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
#endif
{
d->initialize();
addToCache();
Expand All @@ -210,11 +186,7 @@ void QgsCoordinateTransform::setContext( const QgsCoordinateTransformContext &co

d->calculateTransforms( mContext );
Q_NOWARN_DEPRECATED_PUSH
#if PROJ_VERSION_MAJOR>=6
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mProjCoordinateOperation, d->mAllowFallbackTransforms ) )
#else
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
#endif
{
d->initialize();
addToCache();
Expand Down Expand Up @@ -675,14 +647,12 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
}
}

#if PROJ_VERSION_MAJOR>=6
std::vector< double > xprev( numPoints );
memcpy( xprev.data(), x, sizeof( double ) * numPoints );
std::vector< double > yprev( numPoints );
memcpy( yprev.data(), y, sizeof( double ) * numPoints );
std::vector< double > zprev( numPoints );
memcpy( zprev.data(), z, sizeof( double ) * numPoints );
#endif

#ifdef COORDINATE_TRANSFORM_VERBOSE
double xorg = *x;
Expand All @@ -702,7 +672,7 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
ProjData projData = d->threadLocalProjData();

int projResult = 0;
#if PROJ_VERSION_MAJOR>=6

proj_errno_reset( projData );
proj_trans_generic( projData, ( direction == ForwardTransform && !d->mIsReversed ) || ( direction == ReverseTransform && d->mIsReversed ) ? PJ_FWD : PJ_INV,
x, sizeof( double ), numPoints,
Expand Down Expand Up @@ -738,40 +708,6 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
actualRes = 1;
}
}
#else
bool sourceIsLatLong = false;
bool destIsLatLong = false;

projPJ sourceProj = projData.first;
projPJ destProj = projData.second;
sourceIsLatLong = pj_is_latlong( sourceProj );
destIsLatLong = pj_is_latlong( destProj );

if ( ( destIsLatLong && ( direction == ReverseTransform ) )
|| ( sourceIsLatLong && ( direction == ForwardTransform ) ) )
{
for ( int i = 0; i < numPoints; ++i )
{
x[i] *= DEG_TO_RAD;
y[i] *= DEG_TO_RAD;
}
}
#endif

#if PROJ_VERSION_MAJOR<6
if ( direction == ReverseTransform )
{
projResult = pj_transform( destProj, sourceProj, numPoints, 0, x, y, z );
}
else
{
Q_ASSERT( sourceProj );
Q_ASSERT( destProj );
projResult = pj_transform( sourceProj, destProj, numPoints, 0, x, y, z );
}
#endif

#if PROJ_VERSION_MAJOR>=6

mFallbackOperationOccurred = false;
if ( actualRes != 0
Expand Down Expand Up @@ -823,7 +759,6 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
}
}
}
#endif

for ( const int &pos : zNanPositions )
{
Expand All @@ -843,39 +778,19 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
}
else
{
#if PROJ_VERSION_MAJOR>=6
points += QStringLiteral( "(%1, %2)\n" ).arg( x[i], 0, 'f' ).arg( y[i], 0, 'f' );
#else
points += QStringLiteral( "(%1, %2)\n" ).arg( x[i] * RAD_TO_DEG, 0, 'f' ).arg( y[i] * RAD_TO_DEG, 0, 'f' );
#endif
}
}

QString dir = ( direction == ForwardTransform ) ? QObject::tr( "forward transform" ) : QObject::tr( "inverse transform" );

#if PROJ_VERSION_MAJOR>=6
QString msg = QObject::tr( "%1 of\n"
"%2"
"Error: %3" )
.arg( dir,
points,
projResult < 0 ? QString::fromUtf8( proj_errno_string( projResult ) ) : QObject::tr( "Fallback transform failed" ) );
#else
char *srcdef = pj_get_def( sourceProj, 0 );
char *dstdef = pj_get_def( destProj, 0 );

QString msg = QObject::tr( "%1 of\n"
"%2"
"PROJ: %3 +to %4\n"
"Error: %5" )
.arg( dir,
points,
srcdef, dstdef,
QString::fromUtf8( pj_strerrno( projResult ) ) );

pj_dalloc( srcdef );
pj_dalloc( dstdef );
#endif

// don't flood console with thousands of duplicate transform error messages
if ( msg != mLastError )
Expand All @@ -888,19 +803,6 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
throw QgsCsException( msg );
}

#if PROJ_VERSION_MAJOR<6
// if the result is lat/long, convert the results from radians back
// to degrees
if ( ( destIsLatLong && ( direction == ForwardTransform ) )
|| ( sourceIsLatLong && ( direction == ReverseTransform ) ) )
{
for ( int i = 0; i < numPoints; ++i )
{
x[i] *= RAD_TO_DEG;
y[i] *= RAD_TO_DEG;
}
}
#endif
#ifdef COORDINATE_TRANSFORM_VERBOSE
QgsDebugMsg( QStringLiteral( "[[[[[[ Projected %1, %2 to %3, %4 ]]]]]]" )
.arg( xorg, 0, 'g', 15 ).arg( yorg, 0, 'g', 15 )
Expand All @@ -925,12 +827,8 @@ QString QgsCoordinateTransform::coordinateOperation() const

QgsDatumTransform::TransformDetails QgsCoordinateTransform::instantiatedCoordinateOperationDetails() const
{
#if PROJ_VERSION_MAJOR>=6
ProjData projData = d->threadLocalProjData();
return QgsDatumTransform::transformDetailsFromPj( projData );
#else
return QgsDatumTransform::TransformDetails();
#endif
}

void QgsCoordinateTransform::setCoordinateOperation( const QString &operation ) const
Expand Down Expand Up @@ -978,7 +876,6 @@ const char *finder( const char *name )
return proj.toUtf8();
}

#if PROJ_VERSION_MAJOR>=6
bool QgsCoordinateTransform::setFromCache( const QgsCoordinateReferenceSystem &src, const QgsCoordinateReferenceSystem &dest, const QString &coordinateOperationProj, bool allowFallback )
{
if ( !src.isValid() || !dest.isValid() )
Expand Down Expand Up @@ -1019,51 +916,6 @@ bool QgsCoordinateTransform::setFromCache( const QgsCoordinateReferenceSystem &s
}
return false;
}
#else
bool QgsCoordinateTransform::setFromCache( const QgsCoordinateReferenceSystem &src, const QgsCoordinateReferenceSystem &dest, int srcDatumTransform, int destDatumTransform )
{
if ( !src.isValid() || !dest.isValid() )
return false;

const QString sourceKey = src.authid().isEmpty() ?
src.toWkt() : src.authid();
const QString destKey = dest.authid().isEmpty() ?
dest.toWkt() : dest.authid();

if ( sourceKey.isEmpty() || destKey.isEmpty() )
return false;

QgsReadWriteLocker locker( sCacheLock, QgsReadWriteLocker::Read );
if ( sDisableCache )
return false;

const QList< QgsCoordinateTransform > values = sTransforms.values( qMakePair( src.authid(), dest.authid() ) );
for ( auto valIt = values.constBegin(); valIt != values.constEnd(); ++valIt )
{
Q_NOWARN_DEPRECATED_PUSH
if ( ( *valIt ).sourceDatumTransformId() == srcDatumTransform &&
( *valIt ).destinationDatumTransformId() == destDatumTransform )
{
// need to save, and then restore the context... we don't want this to be cached or to use the values from the cache
QgsCoordinateTransformContext context = mContext;
#ifdef QGISDEBUG
bool hasContext = mHasContext;
#endif
*this = *valIt;
locker.unlock();

mContext = context;
#ifdef QGISDEBUG
mHasContext = hasContext;
#endif

return true;
}
Q_NOWARN_DEPRECATED_POP
}
return false;
}
#endif

void QgsCoordinateTransform::addToCache()
{
Expand Down Expand Up @@ -1129,7 +981,6 @@ void QgsCoordinateTransform::invalidateCache( bool disableCache )
sTransforms.clear();
}

#if PROJ_VERSION_MAJOR>=6
void QgsCoordinateTransform::removeFromCacheObjectsBelongingToCurrentThread( void *pj_context )
{
// Not completely sure about object order destruction after main() has
Expand All @@ -1153,7 +1004,6 @@ void QgsCoordinateTransform::removeFromCacheObjectsBelongingToCurrentThread( voi
++it;
}
}
#endif

double QgsCoordinateTransform::scaleFactor( const QgsRectangle &ReferenceExtent ) const
{
Expand Down
10 changes: 1 addition & 9 deletions src/core/qgscoordinatetransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,11 @@ class CORE_EXPORT QgsCoordinateTransform
#endif

#ifndef SIP_RUN
#if PROJ_VERSION_MAJOR>=6
protected:
friend class QgsProjContext;

// Only meant to be called by QgsProjContext::~QgsProjContext()
static void removeFromCacheObjectsBelongingToCurrentThread( void *pj_context );
#endif
#endif
private:

Expand All @@ -694,16 +692,10 @@ class CORE_EXPORT QgsCoordinateTransform
bool mDisableFallbackHandler = false;
mutable bool mFallbackOperationOccurred = false;

#if PROJ_VERSION_MAJOR>=6
bool setFromCache( const QgsCoordinateReferenceSystem &src,
const QgsCoordinateReferenceSystem &dest,
const QString &coordinateOperationProj, bool allowFallback );
#else
bool setFromCache( const QgsCoordinateReferenceSystem &src,
const QgsCoordinateReferenceSystem &dest,
int srcDatumTransform,
int destDatumTransform );
#endif

void addToCache();

// cache
Expand Down
179 changes: 1 addition & 178 deletions src/core/qgscoordinatetransform_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
#include "qgsreadwritelocker.h"
#include "qgsmessagelog.h"

#if PROJ_VERSION_MAJOR>=6
#include "qgsprojutils.h"
#include <proj.h>
#include <proj_experimental.h>
#else
#include <proj_api.h>
#endif

#include <sqlite3.h>

Expand All @@ -52,25 +48,6 @@ std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
const QgsCoordinateReferenceSystem &destinationCrs,
const QgsDatumTransform::TransformDetails &desiredOperation )> QgsCoordinateTransformPrivate::sMissingGridUsedByContextHandler = nullptr;

#if PROJ_VERSION_MAJOR<6
#ifdef USE_THREAD_LOCAL
thread_local QgsProjContextStore QgsCoordinateTransformPrivate::mProjContext;
#else
QThreadStorage< QgsProjContextStore * > QgsCoordinateTransformPrivate::mProjContext;
#endif

QgsProjContextStore::QgsProjContextStore()
{
context = pj_ctx_alloc();
}

QgsProjContextStore::~QgsProjContextStore()
{
pj_ctx_free( context );
}

#endif

Q_NOWARN_DEPRECATED_PUSH // because of deprecated members
QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate()
{
Expand Down Expand Up @@ -100,9 +77,7 @@ QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinat

QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinateTransformPrivate &other )
: QSharedData( other )
#if PROJ_VERSION_MAJOR >= 6
, mAvailableOpCount( other.mAvailableOpCount )
#endif
, mIsValid( other.mIsValid )
, mShortCircuit( other.mShortCircuit )
, mSourceCRS( other.mSourceCRS )
Expand All @@ -117,10 +92,6 @@ QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinat
, mProjProjections()
, mProjFallbackProjections()
{
#if PROJ_VERSION_MAJOR < 6
//must reinitialize to setup mSourceProjection and mDestinationProjection
initialize();
#endif
}
Q_NOWARN_DEPRECATED_POP

Expand All @@ -146,9 +117,7 @@ void QgsCoordinateTransformPrivate::invalidate()
{
mShortCircuit = true;
mIsValid = false;
#if PROJ_VERSION_MAJOR >= 6
mAvailableOpCount = -1;
#endif
}

bool QgsCoordinateTransformPrivate::initialize()
Expand Down Expand Up @@ -184,39 +153,6 @@ bool QgsCoordinateTransformPrivate::initialize()
// init the projections (destination and source)
freeProj();

#if PROJ_VERSION_MAJOR < 6
Q_NOWARN_DEPRECATED_PUSH
int sourceDatumTransform = mSourceDatumTransform;
int destDatumTransform = mDestinationDatumTransform;
bool useDefaultDatumTransform = ( sourceDatumTransform == - 1 && destDatumTransform == -1 );

mSourceProjString = mSourceCRS.toProj();
if ( !useDefaultDatumTransform )
{
mSourceProjString = stripDatumTransform( mSourceProjString );
}
if ( sourceDatumTransform != -1 )
{
mSourceProjString += ( ' ' + QgsDatumTransform::datumTransformToProj( sourceDatumTransform ) );
}

mDestProjString = mDestCRS.toProj();
if ( !useDefaultDatumTransform )
{
mDestProjString = stripDatumTransform( mDestProjString );
}
if ( destDatumTransform != -1 )
{
mDestProjString += ( ' ' + QgsDatumTransform::datumTransformToProj( destDatumTransform ) );
}

if ( !useDefaultDatumTransform )
{
addNullGridShifts( mSourceProjString, mDestProjString, sourceDatumTransform, destDatumTransform );
}
Q_NOWARN_DEPRECATED_POP
#endif

// create proj projections for current thread
ProjData res = threadLocalProjData();

Expand All @@ -225,15 +161,8 @@ bool QgsCoordinateTransformPrivate::initialize()
QgsDebugMsg( "To proj : " + mDestCRS.toProj() );
#endif

#if PROJ_VERSION_MAJOR>=6
if ( !res )
mIsValid = false;
#else
if ( !res.first || !res.second )
{
mIsValid = false;
}
#endif

#ifdef COORDINATE_TRANSFORM_VERBOSE
if ( mIsValid )
Expand Down Expand Up @@ -266,7 +195,6 @@ bool QgsCoordinateTransformPrivate::initialize()
void QgsCoordinateTransformPrivate::calculateTransforms( const QgsCoordinateTransformContext &context )
{
// recalculate datum transforms from context
#if PROJ_VERSION_MAJOR >= 6
if ( mSourceCRS.isValid() && mDestCRS.isValid() )
{
mProjCoordinateOperation = context.calculateCoordinateOperation( mSourceCRS, mDestCRS );
Expand All @@ -279,16 +207,8 @@ void QgsCoordinateTransformPrivate::calculateTransforms( const QgsCoordinateTran
mShouldReverseCoordinateOperation = false;
mAllowFallbackTransforms = false;
}
#else
Q_NOWARN_DEPRECATED_PUSH
QgsDatumTransform::TransformPair transforms = context.calculateDatumTransforms( mSourceCRS, mDestCRS );
mSourceDatumTransform = transforms.sourceTransformId;
mDestinationDatumTransform = transforms.destinationTransformId;
Q_NOWARN_DEPRECATED_POP
#endif
}

#if PROJ_VERSION_MAJOR>=6
static void proj_collecting_logger( void *user_data, int /*level*/, const char *message )
{
QStringList *dest = reinterpret_cast< QStringList * >( user_data );
Expand All @@ -309,32 +229,13 @@ static void proj_logger( void *, int level, const char *message )
QgsDebugMsgLevel( QString( message ), 3 );
}
}
#endif

ProjData QgsCoordinateTransformPrivate::threadLocalProjData()
{
QgsReadWriteLocker locker( mProjLock, QgsReadWriteLocker::Read );

#if PROJ_VERSION_MAJOR>=6
PJ_CONTEXT *context = QgsProjContext::get();
QMap < uintptr_t, ProjData >::const_iterator it = mProjProjections.constFind( reinterpret_cast< uintptr_t>( context ) );
#else
#ifdef USE_THREAD_LOCAL
QMap < uintptr_t, QPair< projPJ, projPJ > >::const_iterator it = mProjProjections.constFind( reinterpret_cast< uintptr_t>( mProjContext.get() ) );
#else
projCtx pContext = nullptr;
if ( mProjContext.hasLocalData() )
{
pContext = mProjContext.localData()->get();
}
else
{
mProjContext.setLocalData( new QgsProjContextStore() );
pContext = mProjContext.localData()->get();
}
QMap < uintptr_t, QPair< projPJ, projPJ > >::const_iterator it = mProjProjections.constFind( reinterpret_cast< uintptr_t>( pContext ) );
#endif
#endif

if ( it != mProjProjections.constEnd() )
{
Expand All @@ -345,7 +246,6 @@ ProjData QgsCoordinateTransformPrivate::threadLocalProjData()
// proj projections don't exist yet, so we need to create
locker.changeMode( QgsReadWriteLocker::Write );

#if PROJ_VERSION_MAJOR>=6
// use a temporary proj error collector
QStringList projErrors;
proj_log_func( context, &projErrors, proj_collecting_logger );
Expand Down Expand Up @@ -585,23 +485,9 @@ ProjData QgsCoordinateTransformPrivate::threadLocalProjData()

ProjData res = transform.release();
mProjProjections.insert( reinterpret_cast< uintptr_t>( context ), res );
#else
#ifdef USE_THREAD_LOCAL
Q_NOWARN_DEPRECATED_PUSH
QPair<projPJ, projPJ> res = qMakePair( pj_init_plus_ctx( mProjContext.get(), mSourceProjString.toUtf8() ),
pj_init_plus_ctx( mProjContext.get(), mDestProjString.toUtf8() ) );
Q_NOWARN_DEPRECATED_POP
mProjProjections.insert( reinterpret_cast< uintptr_t>( mProjContext.get() ), res );
#else
QPair<projPJ, projPJ> res = qMakePair( pj_init_plus_ctx( pContext, mSourceProjString.toUtf8() ),
pj_init_plus_ctx( pContext, mDestProjString.toUtf8() ) );
mProjProjections.insert( reinterpret_cast< uintptr_t>( pContext ), res );
#endif
#endif
return res;
}

#if PROJ_VERSION_MAJOR>=6
ProjData QgsCoordinateTransformPrivate::threadLocalFallbackProjData()
{
QgsReadWriteLocker locker( mProjLock, QgsReadWriteLocker::Read );
Expand All @@ -626,7 +512,6 @@ ProjData QgsCoordinateTransformPrivate::threadLocalFallbackProjData()
mProjFallbackProjections.insert( reinterpret_cast< uintptr_t>( context ), res );
return res;
}
#endif

void QgsCoordinateTransformPrivate::setCustomMissingRequiredGridHandler( const std::function<void ( const QgsCoordinateReferenceSystem &, const QgsCoordinateReferenceSystem &, const QgsDatumTransform::GridDetails & )> &handler )
{
Expand All @@ -648,62 +533,13 @@ void QgsCoordinateTransformPrivate::setCustomMissingGridUsedByContextHandler( co
sMissingGridUsedByContextHandler = handler;
}

#if PROJ_VERSION_MAJOR<6
QString QgsCoordinateTransformPrivate::stripDatumTransform( const QString &proj4 ) const
{
QStringList parameterSplit = proj4.split( '+', QString::SkipEmptyParts );
QString currentParameter;
QString newProjString;

for ( int i = 0; i < parameterSplit.size(); ++i )
{
currentParameter = parameterSplit.at( i );
if ( !currentParameter.startsWith( QLatin1String( "towgs84" ), Qt::CaseInsensitive )
&& !currentParameter.startsWith( QLatin1String( "nadgrids" ), Qt::CaseInsensitive ) )
{
newProjString.append( '+' );
newProjString.append( currentParameter );
newProjString.append( ' ' );
}
}
return newProjString;
}

void QgsCoordinateTransformPrivate::addNullGridShifts( QString &srcProjString, QString &destProjString,
int sourceDatumTransform, int destinationDatumTransform ) const
{
//if one transformation uses ntv2, the other one needs to be null grid shift
if ( destinationDatumTransform == -1 && srcProjString.contains( QLatin1String( "+nadgrids" ) ) ) //add null grid if source transformation is ntv2
{
destProjString += QLatin1String( " +nadgrids=@null" );
return;
}
if ( sourceDatumTransform == -1 && destProjString.contains( QLatin1String( "+nadgrids" ) ) )
{
srcProjString += QLatin1String( " +nadgrids=@null" );
return;
}

//add null shift grid for google mercator
//(see e.g. http://trac.osgeo.org/proj/wiki/FAQ#ChangingEllipsoidWhycantIconvertfromWGS84toGoogleEarthVirtualGlobeMercator)
if ( mSourceCRS.authid().compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) == 0 && sourceDatumTransform == -1 )
{
srcProjString += QLatin1String( " +nadgrids=@null" );
}
if ( mDestCRS.authid().compare( QLatin1String( "EPSG:3857" ), Qt::CaseInsensitive ) == 0 && destinationDatumTransform == -1 )
{
destProjString += QLatin1String( " +nadgrids=@null" );
}
}
#endif

void QgsCoordinateTransformPrivate::freeProj()
{
QgsReadWriteLocker locker( mProjLock, QgsReadWriteLocker::Write );
if ( mProjProjections.isEmpty() && mProjFallbackProjections.isEmpty() )
return;
QMap < uintptr_t, ProjData >::const_iterator it = mProjProjections.constBegin();
#if PROJ_VERSION_MAJOR>=6

// During destruction of PJ* objects, the errno is set in the underlying
// context. Consequently the context attached to the PJ* must still exist !
// Which is not necessarily the case currently unfortunately. So
Expand All @@ -724,22 +560,10 @@ void QgsCoordinateTransformPrivate::freeProj()
}

proj_context_destroy( tmpContext );
#else
projCtx tmpContext = pj_ctx_alloc();
for ( ; it != mProjProjections.constEnd(); ++it )
{
pj_set_ctx( it.value().first, tmpContext );
pj_free( it.value().first );
pj_set_ctx( it.value().second, tmpContext );
pj_free( it.value().second );
}
pj_ctx_free( tmpContext );
#endif
mProjProjections.clear();
mProjFallbackProjections.clear();
}

#if PROJ_VERSION_MAJOR>=6
bool QgsCoordinateTransformPrivate::removeObjectsBelongingToCurrentThread( void *pj_context )
{
QgsReadWriteLocker locker( mProjLock, QgsReadWriteLocker::Write );
Expand All @@ -760,6 +584,5 @@ bool QgsCoordinateTransformPrivate::removeObjectsBelongingToCurrentThread( void

return mProjProjections.isEmpty();
}
#endif

///@endcond
56 changes: 0 additions & 56 deletions src/core/qgscoordinatetransform_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,13 @@

#include <QSharedData>

#if PROJ_VERSION_MAJOR<6
typedef void *projPJ;
#ifndef USE_THREAD_LOCAL
#include <QThreadStorage>
#endif
typedef QPair< projPJ, projPJ > ProjData;
#else
struct PJconsts;
typedef struct PJconsts PJ;
typedef PJ *ProjData;
#endif

#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransformcontext.h"

#if PROJ_VERSION_MAJOR<6

typedef void *projCtx;

/**
* \class QgsProjContextStore
* \ingroup core
* \brief Used to create and store a proj projCtx object, correctly freeing the context upon destruction.
*/
class QgsProjContextStore
{
public:

QgsProjContextStore();
~QgsProjContextStore();

projCtx get() { return context; }

private:
projCtx context;
};

#endif

class QgsCoordinateTransformPrivate : public QSharedData
{

Expand Down Expand Up @@ -102,13 +70,11 @@ class QgsCoordinateTransformPrivate : public QSharedData

ProjData threadLocalProjData();

#if PROJ_VERSION_MAJOR>=6
int mAvailableOpCount = -1;
ProjData threadLocalFallbackProjData();

// Only meant to be called by QgsCoordinateTransform::removeFromCacheObjectsBelongingToCurrentThread()
bool removeObjectsBelongingToCurrentThread( void *pj_context );
#endif

/**
* Flag to indicate whether the transform is valid (ie has a valid
Expand Down Expand Up @@ -140,20 +106,6 @@ class QgsCoordinateTransformPrivate : public QSharedData
//! True if the proj transform corresponds to the reverse direction, and must be flipped when transforming...
bool mIsReversed = false;

#if PROJ_VERSION_MAJOR<6

/**
* Thread local proj context storage. A new proj context will be created
* for every thread.
*/
#ifdef USE_THREAD_LOCAL
static thread_local QgsProjContextStore mProjContext;
#else
static QThreadStorage< QgsProjContextStore * > mProjContext;
#endif
#endif


QReadWriteLock mProjLock;
QMap < uintptr_t, ProjData > mProjProjections;
QMap < uintptr_t, ProjData > mProjFallbackProjections;
Expand Down Expand Up @@ -209,14 +161,6 @@ class QgsCoordinateTransformPrivate : public QSharedData

private:

#if PROJ_VERSION_MAJOR<6
//! Removes +nadgrids and +towgs84 from proj4 string
Q_DECL_DEPRECATED QString stripDatumTransform( const QString &proj4 ) const;

//! In certain situations, null grid shifts have to be added to src / dst proj string
Q_DECL_DEPRECATED void addNullGridShifts( QString &srcProjString, QString &destProjString, int sourceDatumTransform, int destinationDatumTransform ) const;
#endif

void freeProj();

static std::function< void( const QgsCoordinateReferenceSystem &sourceCrs,
Expand Down
175 changes: 0 additions & 175 deletions src/core/qgscoordinatetransformcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,11 @@ void QgsCoordinateTransformContext::clear()

QMap<QPair<QString, QString>, QgsDatumTransform::TransformPair> QgsCoordinateTransformContext::sourceDestinationDatumTransforms() const
{
#if PROJ_VERSION_MAJOR>=6
return QMap<QPair<QString, QString>, QgsDatumTransform::TransformPair>();
#else
d->mLock.lockForRead();
auto res = d->mSourceDestDatumTransforms;
res.detach();
d->mLock.unlock();
return res;
#endif
}

QMap<QPair<QString, QString>, QString> QgsCoordinateTransformContext::coordinateOperations() const
{
#if PROJ_VERSION_MAJOR>=6
d->mLock.lockForRead();
auto res = d->mSourceDestDatumTransforms;
res.detach();
Expand All @@ -98,33 +89,21 @@ QMap<QPair<QString, QString>, QString> QgsCoordinateTransformContext::coordinate
results.insert( qMakePair( it.key().first.authid(), it.key().second.authid() ), it.value().operation );

return results;
#else
return QMap<QPair<QString, QString>, QString>();
#endif
}

bool QgsCoordinateTransformContext::addSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, int sourceTransform, int destinationTransform )
{
if ( !sourceCrs.isValid() || !destinationCrs.isValid() )
return false;
#if PROJ_VERSION_MAJOR>=6
Q_UNUSED( sourceTransform )
Q_UNUSED( destinationTransform )
return false;
#else
d.detach();
d->mLock.lockForWrite();
d->mSourceDestDatumTransforms.insert( qMakePair( sourceCrs.authid(), destinationCrs.authid() ), QgsDatumTransform::TransformPair( sourceTransform, destinationTransform ) );
d->mLock.unlock();
return true;
#endif
}

bool QgsCoordinateTransformContext::addCoordinateOperation( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, const QString &coordinateOperationProjString, bool allowFallback )
{
if ( !sourceCrs.isValid() || !destinationCrs.isValid() )
return false;
#if PROJ_VERSION_MAJOR>=6
d.detach();
d->mLock.lockForWrite();
QgsCoordinateTransformContextPrivate::OperationDetails details;
Expand All @@ -133,11 +112,6 @@ bool QgsCoordinateTransformContext::addCoordinateOperation( const QgsCoordinateR
d->mSourceDestDatumTransforms.insert( qMakePair( sourceCrs, destinationCrs ), details );
d->mLock.unlock();
return true;
#else
Q_UNUSED( coordinateOperationProjString )
Q_UNUSED( allowFallback )
return false;
#endif
}

void QgsCoordinateTransformContext::removeSourceDestinationDatumTransform( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs )
Expand All @@ -147,54 +121,24 @@ void QgsCoordinateTransformContext::removeSourceDestinationDatumTransform( const

void QgsCoordinateTransformContext::removeCoordinateOperation( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs )
{
#if PROJ_VERSION_MAJOR>=6
d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs, destinationCrs ) );
#else
d->mSourceDestDatumTransforms.remove( qMakePair( sourceCrs.authid(), destinationCrs.authid() ) );
#endif
}

bool QgsCoordinateTransformContext::hasTransform( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
{
#if PROJ_VERSION_MAJOR>=6
const QString t = calculateCoordinateOperation( source, destination );
return !t.isEmpty();
#else
Q_NOWARN_DEPRECATED_PUSH
QgsDatumTransform::TransformPair t = calculateDatumTransforms( source, destination );
Q_NOWARN_DEPRECATED_POP
// calculateDatumTransforms already takes care of switching source and destination
return t.sourceTransformId != -1 || t.destinationTransformId != -1;
#endif
}

QgsDatumTransform::TransformPair QgsCoordinateTransformContext::calculateDatumTransforms( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
{
#if PROJ_VERSION_MAJOR>=6
Q_UNUSED( source )
Q_UNUSED( destination )
return QgsDatumTransform::TransformPair( -1, -1 );
#else
QString srcKey = source.authid();
QString destKey = destination.authid();

d->mLock.lockForRead();
// highest priority is exact match for source/dest pair
QgsDatumTransform::TransformPair res = d->mSourceDestDatumTransforms.value( qMakePair( srcKey, destKey ), QgsDatumTransform::TransformPair( -1, -1 ) );
if ( res.sourceTransformId == -1 && res.destinationTransformId == -1 )
{
// try to reverse
QgsDatumTransform::TransformPair res2 = d->mSourceDestDatumTransforms.value( qMakePair( destKey, srcKey ), QgsDatumTransform::TransformPair( -1, -1 ) );
res = QgsDatumTransform::TransformPair( res2.destinationTransformId, res2.sourceTransformId );
}
d->mLock.unlock();
return res;
#endif
}

QString QgsCoordinateTransformContext::calculateCoordinateOperation( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
{
#if PROJ_VERSION_MAJOR>=6
if ( !source.isValid() || !destination.isValid() )
return QString();

Expand All @@ -207,16 +151,10 @@ QString QgsCoordinateTransformContext::calculateCoordinateOperation( const QgsCo
}
d->mLock.unlock();
return res.operation;
#else
Q_UNUSED( source )
Q_UNUSED( destination )
return QString();
#endif
}

bool QgsCoordinateTransformContext::allowFallbackTransform( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
{
#if PROJ_VERSION_MAJOR>=6
if ( !source.isValid() || !destination.isValid() )
return false;

Expand All @@ -229,16 +167,10 @@ bool QgsCoordinateTransformContext::allowFallbackTransform( const QgsCoordinateR
}
d->mLock.unlock();
return res.allowFallback;
#else
Q_UNUSED( source )
Q_UNUSED( destination )
return false;
#endif
}

bool QgsCoordinateTransformContext::mustReverseCoordinateOperation( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination ) const
{
#if PROJ_VERSION_MAJOR>=6
if ( !source.isValid() || !destination.isValid() )
return false;

Expand All @@ -259,11 +191,6 @@ bool QgsCoordinateTransformContext::mustReverseCoordinateOperation( const QgsCoo

d->mLock.unlock();
return false;
#else
Q_UNUSED( source )
Q_UNUSED( destination )
return false;
#endif
}

bool QgsCoordinateTransformContext::readXml( const QDomElement &element, const QgsReadWriteContext &, QStringList &missingTransforms )
Expand Down Expand Up @@ -291,7 +218,6 @@ bool QgsCoordinateTransformContext::readXml( const QDomElement &element, const Q
{
const QDomElement transformElem = srcDestNodes.at( i ).toElement();

#if PROJ_VERSION_MAJOR>=6
const QDomElement srcElem = transformElem.firstChildElement( QStringLiteral( "src" ) );
const QDomElement destElem = transformElem.firstChildElement( QStringLiteral( "dest" ) );

Expand Down Expand Up @@ -329,39 +255,6 @@ bool QgsCoordinateTransformContext::readXml( const QDomElement &element, const Q
deets.operation = coordinateOp;
deets.allowFallback = allowFallback;
d->mSourceDestDatumTransforms.insert( qMakePair( srcCrs, destCrs ), deets );
#else
const QString key1 = transformElem.attribute( QStringLiteral( "source" ) );
const QString key2 = transformElem.attribute( QStringLiteral( "dest" ) );

QString value1 = transformElem.attribute( QStringLiteral( "sourceTransform" ) );
QString value2 = transformElem.attribute( QStringLiteral( "destTransform" ) );

Q_NOWARN_DEPRECATED_PUSH
int datumId1 = -1;
int datumId2 = -1;
//warn if value1 or value2 is non-empty, yet no matching transform was found
if ( !value1.isEmpty() )
{
datumId1 = QgsDatumTransform::projStringToDatumTransformId( value1 );
if ( datumId1 < 0 )
{
result = false;
missingTransforms << value1;
}
}
if ( !value2.isEmpty() )
{
datumId2 = QgsDatumTransform::projStringToDatumTransformId( value2 );
if ( datumId2 < 0 )
{
result = false;
missingTransforms << value2;
}
}
Q_NOWARN_DEPRECATED_POP

d->mSourceDestDatumTransforms.insert( qMakePair( key1, key2 ), QgsDatumTransform::TransformPair( datumId1, datumId2 ) );
#endif
}

d->mLock.unlock();
Expand All @@ -380,7 +273,6 @@ void QgsCoordinateTransformContext::writeXml( QDomElement &element, const QgsRea
for ( auto it = d->mSourceDestDatumTransforms.constBegin(); it != d->mSourceDestDatumTransforms.constEnd(); ++ it )
{
QDomElement transformElem = doc.createElement( QStringLiteral( "srcDest" ) );
#if PROJ_VERSION_MAJOR>=6
QDomElement srcElem = doc.createElement( QStringLiteral( "src" ) );
QDomElement destElem = doc.createElement( QStringLiteral( "dest" ) );

Expand All @@ -392,15 +284,6 @@ void QgsCoordinateTransformContext::writeXml( QDomElement &element, const QgsRea

transformElem.setAttribute( QStringLiteral( "coordinateOp" ), it.value().operation );
transformElem.setAttribute( QStringLiteral( "allowFallback" ), it.value().allowFallback ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
#else
transformElem.setAttribute( QStringLiteral( "source" ), it.key().first );
transformElem.setAttribute( QStringLiteral( "dest" ), it.key().second );

Q_NOWARN_DEPRECATED_PUSH
transformElem.setAttribute( QStringLiteral( "sourceTransform" ), it.value().sourceTransformId < 0 ? QString() : QgsDatumTransform::datumTransformToProj( it.value().sourceTransformId ) );
transformElem.setAttribute( QStringLiteral( "destTransform" ), it.value().destinationTransformId < 0 ? QString() : QgsDatumTransform::datumTransformToProj( it.value().destinationTransformId ) );
Q_NOWARN_DEPRECATED_POP
#endif
contextElem.appendChild( transformElem );
}

Expand All @@ -420,15 +303,10 @@ void QgsCoordinateTransformContext::readSettings()
QStringList projectionKeys = settings.allKeys();

//collect src and dest entries that belong together
#if PROJ_VERSION_MAJOR>=6
QMap< QPair< QgsCoordinateReferenceSystem, QgsCoordinateReferenceSystem >, QgsCoordinateTransformContextPrivate::OperationDetails > transforms;
#else
QMap< QPair< QString, QString >, QPair< int, int > > transforms;
#endif
QStringList::const_iterator pkeyIt = projectionKeys.constBegin();
for ( ; pkeyIt != projectionKeys.constEnd(); ++pkeyIt )
{
#if PROJ_VERSION_MAJOR>=6
if ( pkeyIt->contains( QLatin1String( "coordinateOp" ) ) )
{
QStringList split = pkeyIt->split( '/' );
Expand All @@ -452,45 +330,13 @@ void QgsCoordinateTransformContext::readSettings()
deets.allowFallback = allowFallback;
transforms[ qMakePair( QgsCoordinateReferenceSystem( srcAuthId ), QgsCoordinateReferenceSystem( destAuthId ) )] = deets;
}
#else
if ( pkeyIt->contains( QLatin1String( "srcTransform" ) ) || pkeyIt->contains( QLatin1String( "destTransform" ) ) )
{
QStringList split = pkeyIt->split( '/' );
QString srcAuthId, destAuthId;
if ( ! split.isEmpty() )
{
srcAuthId = split.at( 0 );
}
if ( split.size() > 1 )
{
destAuthId = split.at( 1 ).split( '_' ).at( 0 );
}

QString proj = settings.value( *pkeyIt ).toString();
Q_NOWARN_DEPRECATED_PUSH
int datumId = QgsDatumTransform::projStringToDatumTransformId( proj );
Q_NOWARN_DEPRECATED_POP
if ( pkeyIt->contains( QLatin1String( "srcTransform" ) ) )
{
transforms[ qMakePair( srcAuthId, destAuthId )].first = datumId;
}
else if ( pkeyIt->contains( QLatin1String( "destTransform" ) ) )
{
transforms[ qMakePair( srcAuthId, destAuthId )].second = datumId;
}
}
#endif
}

// add transforms to context
auto transformIt = transforms.constBegin();
for ( ; transformIt != transforms.constEnd(); ++transformIt )
{
#if PROJ_VERSION_MAJOR>=6
d->mSourceDestDatumTransforms.insert( transformIt.key(), transformIt.value() );
#else
d->mSourceDestDatumTransforms.insert( transformIt.key(), QgsDatumTransform::TransformPair( transformIt.value().first, transformIt.value().second ) );
#endif
}

d->mLock.unlock();
Expand All @@ -513,37 +359,16 @@ void QgsCoordinateTransformContext::writeSettings()

for ( auto transformIt = d->mSourceDestDatumTransforms.constBegin(); transformIt != d->mSourceDestDatumTransforms.constEnd(); ++transformIt )
{
#if PROJ_VERSION_MAJOR>=6
const QString srcAuthId = transformIt.key().first.authid();
const QString destAuthId = transformIt.key().second.authid();
#else
const QString srcAuthId = transformIt.key().first;
const QString destAuthId = transformIt.key().second;
#endif

if ( srcAuthId.isEmpty() || destAuthId.isEmpty() )
continue; // not so nice, but alternative would be to shove whole CRS wkt into the settings values...

#if PROJ_VERSION_MAJOR>=6
const QString proj = transformIt.value().operation;
const bool allowFallback = transformIt.value().allowFallback;
settings.setValue( srcAuthId + "//" + destAuthId + "_coordinateOp", proj );
settings.setValue( srcAuthId + "//" + destAuthId + "_allowFallback", allowFallback );
#else
int sourceDatumTransform = transformIt.value().sourceTransformId;
QString sourceDatumProj;
Q_NOWARN_DEPRECATED_PUSH
if ( sourceDatumTransform >= 0 )
sourceDatumProj = QgsDatumTransform::datumTransformToProj( sourceDatumTransform );
int destinationDatumTransform = transformIt.value().destinationTransformId;
QString destinationDatumProj;
if ( destinationDatumTransform >= 0 )
destinationDatumProj = QgsDatumTransform::datumTransformToProj( destinationDatumTransform );
Q_NOWARN_DEPRECATED_POP

settings.setValue( srcAuthId + "//" + destAuthId + "_srcTransform", sourceDatumProj );
settings.setValue( srcAuthId + "//" + destAuthId + "_destTransform", destinationDatumProj );
#endif
}

settings.endGroup();
Expand Down
4 changes: 0 additions & 4 deletions src/core/qgscoordinatetransformcontext_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class QgsCoordinateTransformContextPrivate : public QSharedData
/**
* Mapping for coordinate operation Proj string to use for source/destination CRS pairs.
*/
#if PROJ_VERSION_MAJOR>=6
class OperationDetails
{
public:
Expand All @@ -71,9 +70,6 @@ class QgsCoordinateTransformContextPrivate : public QSharedData
}
};
QMap< QPair< QgsCoordinateReferenceSystem, QgsCoordinateReferenceSystem >, OperationDetails > mSourceDestDatumTransforms;
#else
QMap< QPair< QString, QString >, QgsDatumTransform::TransformPair > mSourceDestDatumTransforms;
#endif

//! Mutex for making QgsCoordinateTransformContextPrivate thread safe
mutable QReadWriteLock mLock{};
Expand Down
10 changes: 0 additions & 10 deletions src/core/qgsdatumtransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@
#include "qgssqliteutils.h"
#include <sqlite3.h>

#if PROJ_VERSION_MAJOR>=6
#include "qgsprojutils.h"
#include <proj.h>
#endif

QList<QgsDatumTransform::TransformDetails> QgsDatumTransform::operations( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination, bool includeSuperseded )
{
QList< QgsDatumTransform::TransformDetails > res;
#if PROJ_VERSION_MAJOR<6
Q_UNUSED( source )
Q_UNUSED( destination )
Q_UNUSED( includeSuperseded )
#else
if ( !source.projObject() || !destination.projObject() )
return res;

Expand Down Expand Up @@ -66,7 +59,6 @@ QList<QgsDatumTransform::TransformDetails> QgsDatumTransform::operations( const
proj_list_destroy( ops );
}
proj_operation_factory_context_destroy( operationContext );
#endif
return res;
}

Expand Down Expand Up @@ -312,7 +304,6 @@ QgsDatumTransform::TransformInfo QgsDatumTransform::datumTransformInfo( int datu
return info;
}

#if PROJ_VERSION_MAJOR>=6
QgsDatumTransform::TransformDetails QgsDatumTransform::transformDetailsFromPj( PJ *op )
{
PJ_CONTEXT *pjContext = QgsProjContext::get();
Expand Down Expand Up @@ -417,4 +408,3 @@ QgsDatumTransform::TransformDetails QgsDatumTransform::transformDetailsFromPj( P

return details;
}
#endif
4 changes: 0 additions & 4 deletions src/core/qgsdatumtransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@

class QgsCoordinateReferenceSystem;

#if PROJ_VERSION_MAJOR>=6
#ifndef SIP_RUN
struct PJconsts;
typedef struct PJconsts PJ;
#endif
#endif

/**
* \brief Contains methods and classes relating the datum transformations.
Expand Down Expand Up @@ -318,7 +316,6 @@ class CORE_EXPORT QgsDatumTransform
Q_DECL_DEPRECATED static QgsDatumTransform::TransformInfo datumTransformInfo( int datumTransformId ) SIP_DEPRECATED;

#ifndef SIP_RUN
#if PROJ_VERSION_MAJOR >= 6

/**
* Returns the transform details for a Proj coordinate operation \a op.
Expand All @@ -327,7 +324,6 @@ class CORE_EXPORT QgsDatumTransform
* \since QGIS 3.8
*/
static QgsDatumTransform::TransformDetails transformDetailsFromPj( PJ *op );
#endif
#endif

private:
Expand Down
164 changes: 0 additions & 164 deletions src/core/qgsellipsoidutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
#include "qgsreadwritelocker.h"
#include "qgsruntimeprofiler.h"

#if PROJ_VERSION_MAJOR>=6
#include <proj.h>
#include <mutex>
#endif

Q_GLOBAL_STATIC( QReadWriteLock, sEllipsoidCacheLock )
typedef QHash< QString, QgsEllipsoidUtils::EllipsoidParameters > EllipsoidParamCache;
Expand Down Expand Up @@ -171,7 +169,6 @@ QgsEllipsoidUtils::EllipsoidParameters QgsEllipsoidUtils::ellipsoidParameters( c
};

QString ellipsoid = e;
#if PROJ_VERSION_MAJOR >= 6
// ensure ellipsoid database is populated when first called
static std::once_flag initialized;
std::call_once( initialized, [ = ]
Expand All @@ -181,9 +178,6 @@ QgsEllipsoidUtils::EllipsoidParameters QgsEllipsoidUtils::ellipsoidParameters( c
} );

ellipsoid = sProj6EllipsoidAcronymMap.value( ellipsoid, ellipsoid ); // silently upgrade older QGIS acronyms to proj acronyms
#else
( void )sProj6EllipsoidAcronymMap;
#endif

// check cache
{
Expand Down Expand Up @@ -231,126 +225,6 @@ QgsEllipsoidUtils::EllipsoidParameters QgsEllipsoidUtils::ellipsoidParameters( c
}
return params;
}

#if PROJ_VERSION_MAJOR< 6
// cache miss - get from database
// NOT REQUIRED FOR PROJ >= 6 -- we populate known types once by calling definitions() above

QString radius, parameter2;
//
// SQLITE3 stuff - get parameters for selected ellipsoid
//
sqlite3_database_unique_ptr database;
sqlite3_statement_unique_ptr statement;
// Continue with PROJ list of ellipsoids.

//check the db is available
int result = database.open_v2( QgsApplication::srsDatabaseFilePath(), SQLITE_OPEN_READONLY, nullptr );
if ( result )
{
QgsMessageLog::logMessage( QObject::tr( "Can not open srs database (%1): %2" ).arg( QgsApplication::srsDatabaseFilePath(), database.errorMessage() ) );
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
return params;
}
// Set up the query to retrieve the projection information needed to populate the ELLIPSOID list
QString sql = "select radius, parameter2 from tbl_ellipsoid where acronym='" + ellipsoid + '\'';
statement = database.prepare( sql, result );
// XXX Need to free memory from the error msg if one is set
if ( result == SQLITE_OK )
{
if ( statement.step() == SQLITE_ROW )
{
radius = statement.columnAsText( 0 );
parameter2 = statement.columnAsText( 1 );
}
}
// row for this ellipsoid wasn't found?
if ( radius.isEmpty() || parameter2.isEmpty() )
{
QgsDebugMsg( QStringLiteral( "setEllipsoid: no row in tbl_ellipsoid for acronym '%1'" ).arg( ellipsoid ) );
params.valid = false;
sEllipsoidCacheLock()->lockForWrite();
if ( !sDisableCache )
{
sEllipsoidCache()->insert( ellipsoid, params );
}
sEllipsoidCacheLock()->unlock();
return params;
}

// get major semiaxis
if ( radius.left( 2 ) == QLatin1String( "a=" ) )
params.semiMajor = radius.midRef( 2 ).toDouble();
else
{
QgsDebugMsg( QStringLiteral( "setEllipsoid: wrong format of radius field: '%1'" ).arg( radius ) );
params.valid = false;
sEllipsoidCacheLock()->lockForWrite();
if ( !sDisableCache )
{
sEllipsoidCache()->insert( ellipsoid, params );
}
sEllipsoidCacheLock()->unlock();
return params;
}

// get second parameter
// one of values 'b' or 'f' is in field parameter2
// second one must be computed using formula: invf = a/(a-b)
if ( parameter2.left( 2 ) == QLatin1String( "b=" ) )
{
params.semiMinor = parameter2.midRef( 2 ).toDouble();
params.inverseFlattening = params.semiMajor / ( params.semiMajor - params.semiMinor );
}
else if ( parameter2.left( 3 ) == QLatin1String( "rf=" ) )
{
params.inverseFlattening = parameter2.midRef( 3 ).toDouble();
params.semiMinor = params.semiMajor - ( params.semiMajor / params.inverseFlattening );
}
else
{
QgsDebugMsg( QStringLiteral( "setEllipsoid: wrong format of parameter2 field: '%1'" ).arg( parameter2 ) );
params.valid = false;
sEllipsoidCacheLock()->lockForWrite();
if ( !sDisableCache )
{
sEllipsoidCache()->insert( ellipsoid, params );
}
sEllipsoidCacheLock()->unlock();
return params;
}

QgsDebugMsgLevel( QStringLiteral( "setEllipsoid: a=%1, b=%2, 1/f=%3" ).arg( params.semiMajor ).arg( params.semiMinor ).arg( params.inverseFlattening ), 4 );


// get spatial ref system for ellipsoid
QString proj4 = "+proj=longlat +ellps=" + ellipsoid + " +no_defs";
QgsCoordinateReferenceSystem destCRS = QgsCoordinateReferenceSystem::fromProj( proj4 );
//TODO: createFromProj used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if ( destCRS.srsid() == 0 )
{
QString name = QStringLiteral( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ),
destCRS.toProj() );
destCRS.saveAsUserCrs( name );
}
//

// set transformation from project CRS to ellipsoid coordinates
params.crs = destCRS;

sEllipsoidCacheLock()->lockForWrite();
if ( !sDisableCache )
{
sEllipsoidCache()->insert( ellipsoid, params );
}
sEllipsoidCacheLock()->unlock();
return params;
#else
params.valid = false;

QgsReadWriteLocker l( *sEllipsoidCacheLock(), QgsReadWriteLocker::Write );
Expand All @@ -360,7 +234,6 @@ QgsEllipsoidUtils::EllipsoidParameters QgsEllipsoidUtils::ellipsoidParameters( c
}

return params;
#endif
}

QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
Expand All @@ -374,7 +247,6 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()

QList<QgsEllipsoidUtils::EllipsoidDefinition> defs;

#if PROJ_VERSION_MAJOR>=6
QgsReadWriteLocker locker( *sEllipsoidCacheLock(), QgsReadWriteLocker::Write );

PJ_CONTEXT *context = QgsProjContext::get();
Expand Down Expand Up @@ -434,42 +306,6 @@ QList<QgsEllipsoidUtils::EllipsoidDefinition> QgsEllipsoidUtils::definitions()
}
locker.unlock();

#else
sqlite3_database_unique_ptr database;
sqlite3_statement_unique_ptr statement;
int result;

//check the db is available
result = database.open_v2( QgsApplication::srsDatabaseFilePath(), SQLITE_OPEN_READONLY, nullptr );
if ( result )
{
QgsDebugMsg( QStringLiteral( "Can't open database: %1" ).arg( database.errorMessage() ) );
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
Q_ASSERT( result == 0 );
}

// Set up the query to retrieve the projection information needed to populate the ELLIPSOID list
QString sql = QStringLiteral( "select acronym, name from tbl_ellipsoid order by name" );
statement = database.prepare( sql, result );

if ( result == SQLITE_OK )
{
while ( statement.step() == SQLITE_ROW )
{
EllipsoidDefinition def;
def.acronym = statement.columnAsText( 0 );
def.description = statement.columnAsText( 1 );

// use ellipsoidParameters so that result is cached
def.parameters = ellipsoidParameters( def.acronym );

defs << def;
}
}

#endif

QCollator collator;
collator.setCaseSensitivity( Qt::CaseInsensitive );
std::sort( defs.begin(), defs.end(), [&collator]( const EllipsoidDefinition & a, const EllipsoidDefinition & b )
Expand Down
20 changes: 0 additions & 20 deletions src/core/qgsprojutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
#include <QSet>
#include <QRegularExpression>

#if PROJ_VERSION_MAJOR>=6
#include <proj.h>
#else
#include <proj_api.h>
#endif


#if defined(USE_THREAD_LOCAL) && !defined(Q_OS_WIN)
thread_local QgsProjContext QgsProjContext::sProjContext;
Expand All @@ -37,24 +32,16 @@ QThreadStorage< QgsProjContext * > QgsProjContext::sProjContext;

QgsProjContext::QgsProjContext()
{
#if PROJ_VERSION_MAJOR>=6
mContext = proj_context_create();
#else
mContext = pj_ctx_alloc();
#endif
}

QgsProjContext::~QgsProjContext()
{
#if PROJ_VERSION_MAJOR>=6
// Call removeFromCacheObjectsBelongingToCurrentThread() before
// destroying the context
QgsCoordinateTransform::removeFromCacheObjectsBelongingToCurrentThread( mContext );
QgsCoordinateReferenceSystem::removeFromCacheObjectsBelongingToCurrentThread( mContext );
proj_context_destroy( mContext );
#else
pj_ctx_free( mContext );
#endif
}

PJ_CONTEXT *QgsProjContext::get()
Expand All @@ -76,7 +63,6 @@ PJ_CONTEXT *QgsProjContext::get()
#endif
}

#if PROJ_VERSION_MAJOR>=6
void QgsProjUtils::ProjPJDeleter::operator()( PJ *object )
{
proj_destroy( object );
Expand Down Expand Up @@ -308,11 +294,8 @@ QStringList QgsProjUtils::nonAvailableGrids( const QString &projDef )
}
#endif

#endif

QStringList QgsProjUtils::searchPaths()
{
#if PROJ_VERSION_MAJOR>=6
const QString path( proj_info().searchpath );
QStringList paths;
#ifdef Q_OS_WIN
Expand All @@ -334,7 +317,4 @@ QStringList QgsProjUtils::searchPaths()
res << p;
}
return res;
#else
return QStringList();
#endif
}
9 changes: 1 addition & 8 deletions src/core/qgsprojutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
#include <QThreadStorage>
#endif

#if PROJ_VERSION_MAJOR>=6
#ifndef SIP_RUN
struct PJconsts;
typedef struct PJconsts PJ;
#endif
#endif

/**
* \class QgsProjUtils
Expand Down Expand Up @@ -71,8 +69,6 @@ class CORE_EXPORT QgsProjUtils
};
Q_DECLARE_FLAGS( IdentifyFlags, IdentifyFlag )

#if PROJ_VERSION_MAJOR >= 6

/**
* Destroys Proj PJ objects.
*/
Expand Down Expand Up @@ -139,19 +135,16 @@ class CORE_EXPORT QgsProjUtils
static QStringList nonAvailableGrids( const QString &projDef );
#endif
#endif
#endif
};

#ifndef SIP_RUN

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

/**
Expand Down
13 changes: 0 additions & 13 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,21 +548,8 @@ void QgsVectorFileWriter::init( QString vectorFileName,
{
QString layerName = vectorFileName.left( vectorFileName.indexOf( QLatin1String( ".shp" ), Qt::CaseInsensitive ) );
QFile prjFile( layerName + ".qpj" );
#if PROJ_VERSION_MAJOR<6
if ( prjFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QTextStream prjStream( &prjFile );
prjStream << srs.toWkt().toLocal8Bit().constData() << endl;
prjFile.close();
}
else
{
QgsDebugMsg( "Couldn't open file " + layerName + ".qpj" );
}
#else
if ( prjFile.exists() )
prjFile.remove();
#endif
}
}

Expand Down
257 changes: 1 addition & 256 deletions src/gui/qgscoordinateoperationwidget.cpp

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/gui/qgscoordinateoperationwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,8 @@ class GUI_EXPORT QgsCoordinateOperationWidget : public QWidget, private Ui::QgsC
*/
QString formatScope( const QString &scope );

#if PROJ_VERSION_MAJOR>=6
QList< QgsDatumTransform::TransformDetails > mDatumTransforms;
#else
QList< QgsDatumTransform::TransformPair > mDatumTransforms;
#endif

QgsCoordinateReferenceSystem mSourceCrs;
QgsCoordinateReferenceSystem mDestinationCrs;
OperationDetails mPreviousOp;
Expand Down
18 changes: 0 additions & 18 deletions src/gui/qgsdatumtransformdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
#include <QDir>
#include <QPushButton>

#if PROJ_VERSION_MAJOR>=6
#include "qgsprojutils.h"
#include <proj.h>
#endif

bool QgsDatumTransformDialog::run( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, QWidget *parent, QgsMapCanvas *mapCanvas, const QString &windowTitle )
{
Expand Down Expand Up @@ -98,7 +96,6 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( const QgsCoordinateReferenceSy
setWindowFlags( windowFlags() & ~Qt::WindowCloseButtonHint );
}

#if PROJ_VERSION_MAJOR>=6
if ( !sourceCrs.isValid() )
sourceCrs = QgsProject::instance()->crs();
if ( !sourceCrs.isValid() )
Expand All @@ -110,7 +107,6 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( const QgsCoordinateReferenceSy

mSourceProjectionSelectionWidget->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, false );
mDestinationProjectionSelectionWidget->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, false );
#endif

mSourceProjectionSelectionWidget->setCrs( sourceCrs );
mDestinationProjectionSelectionWidget->setCrs( destinationCrs );
Expand Down Expand Up @@ -146,26 +142,16 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( const QgsCoordinateReferenceSy

connect( mCoordinateOperationsWidget, &QgsCoordinateOperationWidget::operationDoubleClicked, this, [ = ]
{

#if PROJ_VERSION_MAJOR>=6
if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
&& mCoordinateOperationsWidget->selectedOperation().isAvailable )
accept();
#else
if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid() && mCoordinateOperationsWidget->hasSelection() )
accept();
#endif
} );
}

void QgsDatumTransformDialog::setOKButtonEnabled()
{
#if PROJ_VERSION_MAJOR>=6
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
&& mCoordinateOperationsWidget->selectedOperation().isAvailable );
#else
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid() && mCoordinateOperationsWidget->hasSelection() );
#endif
}

void QgsDatumTransformDialog::accept()
Expand Down Expand Up @@ -237,12 +223,8 @@ void QgsDatumTransformDialog::applyDefaultTransform()
context.addSourceDestinationDatumTransform( dt.sourceCrs, dt.destinationCrs, dt.sourceTransformId, dt.destinationTransformId );
Q_NOWARN_DEPRECATED_POP

#if PROJ_VERSION_MAJOR>=6
// on proj 6 builds, removing a coordinate operation falls back to default
context.removeCoordinateOperation( dt.sourceCrs, dt.destinationCrs );
#else
context.addCoordinateOperation( dt.sourceCrs, dt.destinationCrs, dt.proj );
#endif
QgsProject::instance()->setTransformContext( context );
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/grass/qgsgrassnewmapset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ extern "C"
#if defined(_MSC_VER) && defined(M_PI_4)
#undef M_PI_4 //avoid redefinition warning
#endif
#if defined(PROJ_VERSION_MAJOR) && PROJ_VERSION_MAJOR>=6
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <grass/gprojects.h>
}

Expand Down
8 changes: 0 additions & 8 deletions src/process/qgsprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@

#include <ogr_api.h>
#include <gdal_version.h>
#if PROJ_VERSION_MAJOR > 4
#include <proj.h>
#else
#include <proj_api.h>
#endif
#include <json.hpp>

ConsoleFeedback::ConsoleFeedback( bool useJson )
Expand Down Expand Up @@ -1082,12 +1078,8 @@ void QgsProcessingExec::addVersionInformation( QVariantMap &json )
json.insert( QStringLiteral( "gdal_version" ), GDALVersionInfo( "RELEASE_NAME" ) );
json.insert( QStringLiteral( "geos_version" ), GEOSversion() );

#if PROJ_VERSION_MAJOR > 4
PJ_INFO info = proj_info();
json.insert( QStringLiteral( "proj_version" ), info.release );
#else
json.insert( QStringLiteral( "proj_version" ), PJ_VERSION );
#endif
}

void QgsProcessingExec::addAlgorithmInformation( QVariantMap &algorithmJson, const QgsProcessingAlgorithm *algorithm )
Expand Down
3 changes: 0 additions & 3 deletions src/providers/grass/qgis.g.info.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#if defined(_MSC_VER) && defined(M_PI_4)
#undef M_PI_4 //avoid redefinition warning
#endif
#if defined(PROJ_VERSION_MAJOR) && PROJ_VERSION_MAJOR>=6
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <grass/gprojects.h>

int main( int argc, char **argv )
Expand Down
3 changes: 0 additions & 3 deletions src/providers/grass/qgsgrass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ extern "C"
#if defined(_MSC_VER) && defined(M_PI_4)
#undef M_PI_4 //avoid redefinition warning
#endif
#if defined(PROJ_VERSION_MAJOR) && PROJ_VERSION_MAJOR>=6
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <grass/gprojects.h>
#include <grass/vector.h>
#include <grass/raster.h>
Expand Down
3 changes: 0 additions & 3 deletions src/providers/grass/qgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ extern "C"
#if defined(_MSC_VER) && defined(M_PI_4)
#undef M_PI_4 //avoid redefinition warning
#endif
#if defined(PROJ_VERSION_MAJOR) && PROJ_VERSION_MAJOR>=6
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <grass/gprojects.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
Expand Down
3 changes: 0 additions & 3 deletions src/providers/grass/qgsgrassvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ extern "C"
#if defined(_MSC_VER) && defined(M_PI_4)
#undef M_PI_4 //avoid redefinition warning
#endif
#if defined(PROJ_VERSION_MAJOR) && PROJ_VERSION_MAJOR>=6
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <grass/gprojects.h>
#include <grass/vector.h>
#include <grass/raster.h>
Expand Down
3 changes: 0 additions & 3 deletions src/providers/grass/qgsgrassvectormap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ extern "C"
#if defined(_MSC_VER) && defined(M_PI_4)
#undef M_PI_4 //avoid redefinition warning
#endif
#if defined(PROJ_VERSION_MAJOR) && PROJ_VERSION_MAJOR>=6
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <grass/gprojects.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
Expand Down
3 changes: 0 additions & 3 deletions src/providers/grass/qgsgrassvectormaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ extern "C"
#if defined(_MSC_VER) && defined(M_PI_4)
#undef M_PI_4 //avoid redefinition warning
#endif
#if defined(PROJ_VERSION_MAJOR) && PROJ_VERSION_MAJOR>=6
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <grass/gprojects.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
Expand Down
3 changes: 0 additions & 3 deletions src/providers/grass/qgsgrassvectormaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ extern "C"
#if defined(_MSC_VER) && defined(M_PI_4)
#undef M_PI_4 //avoid redefinition warning
#endif
#if defined(PROJ_VERSION_MAJOR) && PROJ_VERSION_MAJOR>=6
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
#endif
#include <grass/gprojects.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
Expand Down
20 changes: 0 additions & 20 deletions src/providers/hana/qgshanacrsutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
#include "qgshanacrsutils.h"
#include "qgshanaexception.h"

#if PROJ_VERSION_MAJOR>=6
#include <proj.h>
#include "qgsprojutils.h"
#else
#include <ogr_srs_api.h>
#endif

double QgsHanaCrsUtils::getAngularUnits( const QgsCoordinateReferenceSystem &crs )
{
Expand All @@ -31,7 +27,6 @@ double QgsHanaCrsUtils::getAngularUnits( const QgsCoordinateReferenceSystem &crs
throw QgsHanaException( "Unable to retrieve angular units from a spatial reference system" );
};

#if PROJ_VERSION_MAJOR>=6
PJ *pjCrs = crs.projObject();
if ( !pjCrs )
throwUnableToGetAngularUnits();
Expand All @@ -56,21 +51,6 @@ double QgsHanaCrsUtils::getAngularUnits( const QgsCoordinateReferenceSystem &crs
if ( !ret )
throwUnableToGetAngularUnits();
return factor;
#else
OGRSpatialReferenceH hCRS = OSRNewSpatialReference( nullptr );
int errcode = OSRImportFromProj4( hCRS, crs.toProj().toUtf8() );
if ( errcode != OGRERR_NONE )
{
if ( hCRS )
OSRRelease( hCRS );
throwUnableToGetAngularUnits();
}

char *angularUnits = nullptr;
double factor = OSRGetAngularUnits( hCRS, &angularUnits );
OSRRelease( hCRS );
return factor;
#endif
}

bool QgsHanaCrsUtils::identifyCrs( const QgsCoordinateReferenceSystem &crs, QString &name, long &srid )
Expand Down
19 changes: 0 additions & 19 deletions tests/src/analysis/testqgsalignraster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,25 +235,6 @@ class TestAlignRaster : public QObject
QCOMPARE( out.identify( 1308405, -746611 ), 10. );
}

void testInvalidReprojection()
{
#if PROJ_VERSION_MAJOR<6 // the projection works on proj 6 builds
QString tmpFile( _tempFile( QStringLiteral( "reproject-invalid" ) ) );

// reprojection to British National Grid with raster in Jakarta area clearly cannot work
QgsCoordinateReferenceSystem destCRS( QStringLiteral( "EPSG:27700" ) );
QVERIFY( destCRS.isValid() );

QgsAlignRaster align;
QgsAlignRaster::List rasters;
rasters << QgsAlignRaster::Item( SRC_FILE, tmpFile );
align.setRasters( rasters );
align.setParametersFromRaster( SRC_FILE, destCRS.toWkt( QgsCoordinateReferenceSystem::WKT2_2018 ) );
bool res = align.run();
QVERIFY( !res );
#endif
}

void testSuggestedReferenceLayer()
{
QgsAlignRaster align;
Expand Down
2 changes: 0 additions & 2 deletions tests/src/app/testqgsdecorationscalebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ void TestQgsDecorationScalebar::mapWidth()
scalebar.mSettings.setUnits( QgsUnitTypes::DistanceMiles );
QGSCOMPARENEAR( scalebar.mapWidth( settings ), 4.97097, 0.0001 );

#if PROJ_VERSION_MAJOR>=6
// ellipsoidal measure
QgsProject::instance()->setEllipsoid( QStringLiteral( "EPSG:7030" ) );
QGSCOMPARENEAR( scalebar.mapWidth( settings ), 4.060337, 0.0001 );
QgsProject::instance()->setEllipsoid( QString() );
#endif

// with non-uniform output size vs extent aspect ratio
settings.setExtent( QgsRectangle( 16700000, -4212000, 16708000, -4204000 ) );
Expand Down
44 changes: 0 additions & 44 deletions tests/src/app/testqgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void TestQgsProjectProperties::testEllipsoidChange()
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "NONE" ) );

#if PROJ_VERSION_MAJOR>=6
QgsProject::instance()->setEllipsoid( QStringLiteral( "ESRI:107900" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
Expand All @@ -122,27 +121,6 @@ void TestQgsProjectProperties::testEllipsoidChange()
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7005" ) );

#else
QgsProject::instance()->setEllipsoid( QStringLiteral( "bessel" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "bessel" ) );

QgsProject::instance()->setEllipsoid( QStringLiteral( "IGNF:ELG052" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "IGNF:ELG052" ) );

QgsProject::instance()->setEllipsoid( QStringLiteral( "IGNF:ELG037" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "IGNF:ELG037" ) );

#endif

QgsProject::instance()->setEllipsoid( QStringLiteral( "NONE" ) );
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->apply();
Expand Down Expand Up @@ -185,37 +163,20 @@ void TestQgsProjectProperties::testEllipsoidCrsSync()
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "NONE" ) );

// but if ellipsoid is initially set, then changing the project CRS should update the ellipsoid to match
#if PROJ_VERSION_MAJOR>=6
QgsProject::instance()->setEllipsoid( QStringLiteral( "EPSG:7021" ) );
#else
QgsProject::instance()->setEllipsoid( QStringLiteral( "evrst69" ) );
#endif
pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
pp->setSelectedCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ) );
pp->apply();
pp.reset();
// ellipsoid should be updated to match CRS ellipsoid
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7019" ) );
#else
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "GRS80" ) );
#endif

pp = qgis::make_unique< QgsProjectProperties >( mQgisApp->mapCanvas() );
#if PROJ_VERSION_MAJOR>=6
pp->setSelectedCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4240" ) ) );
#else
pp->setSelectedCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3907" ) ) );
#endif
pp->apply();
pp.reset();
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7015" ) );
#else
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "bessel" ) );
#endif

#if PROJ_VERSION_MAJOR>=6
// try creating a crs from a non-standard WKT string (in this case, the invalid WKT definition of EPSG:31370 used by
// some ArcGIS versions: see https://github.com/OSGeo/PROJ/issues/1781
const QString wkt = QStringLiteral( R"""(PROJCS["Belge 1972 / Belgian Lambert 72",GEOGCS["Belge 1972",DATUM["Reseau_National_Belge_1972",SPHEROID["International 1924",6378388,297],AUTHORITY["EPSG","6313"]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",90],PARAMETER["central_meridian",4.36748666666667],PARAMETER["standard_parallel_1",49.8333339],PARAMETER["standard_parallel_2",51.1666672333333],PARAMETER["false_easting",150000.01256],PARAMETER["false_northing",5400088.4378],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" );
Expand All @@ -225,7 +186,6 @@ void TestQgsProjectProperties::testEllipsoidCrsSync()
pp->apply();
pp.reset();
QCOMPARE( QgsProject::instance()->ellipsoid().left( 30 ), QStringLiteral( "PARAMETER:6378388:6356911.9461" ) );
#endif

// ok. Next bit of logic -- if the project is initially set to NO projection and NO ellipsoid, then first setting the project CRS should set an ellipsoid to match
QgsProject::instance()->setCrs( QgsCoordinateReferenceSystem() );
Expand All @@ -236,11 +196,7 @@ void TestQgsProjectProperties::testEllipsoidCrsSync()
pp->apply();
pp.reset();
// ellipsoid should be updated to match CRS ellipsoid
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "EPSG:7019" ) );
#else
QCOMPARE( QgsProject::instance()->ellipsoid(), QStringLiteral( "GRS80" ) );
#endif
}

void TestQgsProjectProperties::testBearingFormat()
Expand Down
4 changes: 0 additions & 4 deletions tests/src/core/testqgsarcgisrestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,8 @@ void TestQgsArcGisRestUtils::testParseSpatialReference()
QgsCoordinateReferenceSystem crs = QgsArcGisRestUtils::convertSpatialReference( map );
QVERIFY( crs.isValid() );

#if PROJ_VERSION_MAJOR>=6
QgsDebugMsg( crs.toWkt() );
QCOMPARE( crs.toWkt(), QStringLiteral( R"""(PROJCS["NewJTM",GEOGCS["ETRF89",DATUM["European_Terrestrial_Reference_Frame_1989",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","1178"]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49.225],PARAMETER["central_meridian",-2.135],PARAMETER["scale_factor",0.9999999],PARAMETER["false_easting",40000],PARAMETER["false_northing",70000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" ) );
#else
QCOMPARE( crs.toWkt(), QStringLiteral( "PROJCS[\"unnamed\",GEOGCS[\"WGS 84\",DATUM[\"unknown\",SPHEROID[\"WGS84\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",49.225],PARAMETER[\"central_meridian\",-2.135],PARAMETER[\"scale_factor\",0.9999999],PARAMETER[\"false_easting\",40000],PARAMETER[\"false_northing\",70000],UNIT[\"Meter\",1]]" ) );
#endif
}

void TestQgsArcGisRestUtils::testMapEsriGeometryType()
Expand Down
247 changes: 3 additions & 244 deletions tests/src/core/testqgscoordinatereferencesystem.cpp

Large diffs are not rendered by default.

40 changes: 0 additions & 40 deletions tests/src/core/testqgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ void TestQgsCoordinateTransform::isShortCircuited()
void TestQgsCoordinateTransform::contextShared()
{
//test implicit sharing of QgsCoordinateTransformContext
#if PROJ_VERSION_MAJOR >= 6
QgsCoordinateTransformContext original;
original.addCoordinateOperation( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3113" ) ), QStringLiteral( "proj" ) );

Expand Down Expand Up @@ -211,38 +210,6 @@ void TestQgsCoordinateTransform::contextShared()
QCOMPARE( original.coordinateOperations(), expected );
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), QStringLiteral( "proj2" ) );
QCOMPARE( copy2.coordinateOperations(), expected );
#else
QgsCoordinateTransformContext original;
Q_NOWARN_DEPRECATED_PUSH
original.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3113" ) ), 1, 2 );

QgsCoordinateTransformContext copy( original );
QMap< QPair< QString, QString >, QgsDatumTransform::TransformPair > expected;
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), QgsDatumTransform::TransformPair( 1, 2 ) );
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
QCOMPARE( copy.sourceDestinationDatumTransforms(), expected );

// trigger detach
copy.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3113" ) ), 3, 4 );
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );

expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), QgsDatumTransform::TransformPair( 3, 4 ) );
QCOMPARE( copy.sourceDestinationDatumTransforms(), expected );

// copy via assignment
QgsCoordinateTransformContext copy2;
copy2 = original;
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), QgsDatumTransform::TransformPair( 1, 2 ) );
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
QCOMPARE( copy2.sourceDestinationDatumTransforms(), expected );

copy2.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3111" ) ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3113" ) ), 3, 4 );
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), QgsDatumTransform::TransformPair( 3, 4 ) );
QCOMPARE( copy2.sourceDestinationDatumTransforms(), expected );

Q_NOWARN_DEPRECATED_POP
#endif
}

void TestQgsCoordinateTransform::scaleFactor()
Expand Down Expand Up @@ -456,7 +423,6 @@ void TestQgsCoordinateTransform::transformLKS()

void TestQgsCoordinateTransform::transformContextNormalize()
{
#if PROJ_VERSION_MAJOR >= 6
// coordinate operation for WGS84 to 27700
const QString coordOperation = QStringLiteral( "+proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=WGS84 +step +inv +proj=helmert +x=446.448 +y=-125.157 +z=542.06 +rx=0.15 +ry=0.247 +rz=0.842 +s=-20.489 +convention=position_vector +step +inv +proj=cart +ellps=airy +step +proj=pop +v_3 +step +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy" );
QgsCoordinateTransformContext context;
Expand All @@ -483,8 +449,6 @@ void TestQgsCoordinateTransform::transformContextNormalize()
p = ct2.transform( p2, QgsCoordinateTransform::ReverseTransform );
QGSCOMPARENEAR( p.x(), 245424.604645, 0.01 );
QGSCOMPARENEAR( p.y(), 54016.813093, 0.01 );

#endif
}

void TestQgsCoordinateTransform::transform2DPoint()
Expand Down Expand Up @@ -542,7 +506,6 @@ void TestQgsCoordinateTransform::transformErrorOnePoint()

void TestQgsCoordinateTransform::testDeprecated4240to4326()
{
#if PROJ_VERSION_MAJOR >= 6
// test creating a coordinate transform between EPSG 4240 and EPSG 4326 using a deprecated coordinate operation
// see https://github.com/qgis/QGIS/issues/33121

Expand Down Expand Up @@ -610,12 +573,10 @@ void TestQgsCoordinateTransform::testDeprecated4240to4326()
p3 = deprecatedTransformRev.transform( p2, QgsCoordinateTransform::ReverseTransform );
QGSCOMPARENEAR( p3.x(), 102.496547, 0.000001 );
QGSCOMPARENEAR( p3.y(), 7.502139, 0.000001 );
#endif
}

void TestQgsCoordinateTransform::testCustomProjTransform()
{
#if PROJ_VERSION_MAJOR >= 6
// test custom proj string
// refs https://github.com/qgis/QGIS/issues/32928
QgsCoordinateReferenceSystem ss( QgsCoordinateReferenceSystem::fromProj( QStringLiteral( "+proj=longlat +ellps=GRS80 +towgs84=1,2,3,4,5,6,7 +no_defs" ) ) );
Expand All @@ -632,7 +593,6 @@ void TestQgsCoordinateTransform::testCustomProjTransform()
"+step +inv +proj=cart +ellps=WGS84 "
"+step +proj=pop +v_3 "
"+step +proj=unitconvert +xy_in=rad +xy_out=deg" ) );
#endif
}


Expand Down
17 changes: 0 additions & 17 deletions tests/src/core/testqgsdistancearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,16 @@ void TestQgsDistanceArea::cache()
// warm cache
QVERIFY( da.setEllipsoid( QStringLiteral( "Ganymede2000" ) ) );
QVERIFY( da.willUseEllipsoid() );
// different definition under proj 6, neither is incorrect!
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( da.ellipsoidSemiMajor(), 2632345.0 );
QCOMPARE( da.ellipsoidSemiMinor(), 2632345.0 );
#else
QCOMPARE( da.ellipsoidSemiMajor(), 2632400.0 );
QCOMPARE( da.ellipsoidSemiMinor(), 2632350.0 );
QCOMPARE( da.ellipsoidInverseFlattening(), 52648.0 );
#endif
QCOMPARE( da.ellipsoid(), QStringLiteral( "Ganymede2000" ) );

// a second time, so ellipsoid is fetched from cache
QgsDistanceArea da2;
QVERIFY( da2.setEllipsoid( QStringLiteral( "Ganymede2000" ) ) );
QVERIFY( da2.willUseEllipsoid() );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( da2.ellipsoidSemiMajor(), 2632345.0 );
QCOMPARE( da2.ellipsoidSemiMinor(), 2632345.0 );
#else
QCOMPARE( da2.ellipsoidSemiMajor(), 2632400.0 );
QCOMPARE( da2.ellipsoidSemiMinor(), 2632350.0 );
QCOMPARE( da2.ellipsoidInverseFlattening(), 52648.0 );
#endif
QCOMPARE( da2.ellipsoid(), QStringLiteral( "Ganymede2000" ) );

// using parameters
Expand Down Expand Up @@ -341,11 +328,7 @@ void TestQgsDistanceArea::measureAreaAndUnits()
poly << ring;
polygon = QgsGeometry::fromPolygonXY( poly );

#if PROJ_VERSION_MAJOR>=6
da.setSourceCrs( QgsCoordinateReferenceSystem( QStringLiteral( "ESRI:102635" ) ), QgsProject::instance()->transformContext() );
#else
da.setSourceCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:102635" ) ), QgsProject::instance()->transformContext() );
#endif
da.setEllipsoid( QStringLiteral( "NONE" ) );
// measurement should be in square feet
area = da.measureArea( polygon );
Expand Down
19 changes: 0 additions & 19 deletions tests/src/core/testqgsgdalutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,10 @@ void TestQgsGdalUtils::supportsRasterCreate()
QVERIFY( !QgsGdalUtils::supportsRasterCreate( GDALGetDriverByName( "ESRI Shapefile" ) ) );
}

#if PROJ_VERSION_MAJOR>=6
#define EPSG_4326_WKT \
"GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]]," \
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433," \
"AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]"
#else
#define EPSG_4326_WKT \
"GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]]," \
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433," \
"AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]"
#endif

void TestQgsGdalUtils::testCreateSingleBandMemoryDataset()
{
Expand All @@ -105,11 +98,7 @@ void TestQgsGdalUtils::testCreateSingleBandMemoryDataset()
QCOMPARE( GDALGetRasterXSize( ds1.get() ), 40 );
QCOMPARE( GDALGetRasterYSize( ds1.get() ), 20 );

#if PROJ_VERSION_MAJOR>=6
QCOMPARE( GDALGetProjectionRef( ds1.get() ), R"""(GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]])""" );
#else
QCOMPARE( GDALGetProjectionRef( ds1.get() ), EPSG_4326_WKT );
#endif
double geoTransform[6];
double geoTransformExpected[] = { 1, 0.5, 0, 11, 0, -0.5 };
QCOMPARE( GDALGetGeoTransform( ds1.get(), geoTransform ), CE_None );
Expand All @@ -127,11 +116,7 @@ void TestQgsGdalUtils::testCreateMultiBandMemoryDataset()
QCOMPARE( GDALGetRasterXSize( ds1.get() ), 40 );
QCOMPARE( GDALGetRasterYSize( ds1.get() ), 20 );

#if PROJ_VERSION_MAJOR>=6
QCOMPARE( GDALGetProjectionRef( ds1.get() ), R"""(GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]])""" );
#else
QCOMPARE( GDALGetProjectionRef( ds1.get() ), EPSG_4326_WKT );
#endif
double geoTransform[6];
double geoTransformExpected[] = { 1, 0.5, 0, 11, 0, -0.5 };
QCOMPARE( GDALGetGeoTransform( ds1.get(), geoTransform ), CE_None );
Expand All @@ -156,11 +141,7 @@ void TestQgsGdalUtils::testCreateSingleBandTiffDataset()
QCOMPARE( GDALGetRasterXSize( ds1.get() ), 40 );
QCOMPARE( GDALGetRasterYSize( ds1.get() ), 20 );

#if PROJ_VERSION_MAJOR>=6
QCOMPARE( GDALGetProjectionRef( ds1.get() ), R"""(GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]])""" );
#else
QCOMPARE( GDALGetProjectionRef( ds1.get() ), EPSG_4326_WKT );
#endif

double geoTransform[6];
double geoTransformExpected[] = { 1, 0.5, 0, 11, 0, -0.5 };
Expand Down
8 changes: 0 additions & 8 deletions tests/src/core/testqgslayoutmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,7 @@ void TestQgsLayoutMap::dataDefinedCrs()
//test proj string variable
map->dataDefinedProperties().setProperty( QgsLayoutObject::MapCrs, QgsProperty::fromValue( QStringLiteral( "PROJ4: +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" ) ) );
map->refreshDataDefinedProperty( QgsLayoutObject::MapCrs );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( map->crs().toProj(), QStringLiteral( "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs" ) );
#else
QCOMPARE( map->crs().toProj(), QStringLiteral( "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" ) );
#endif
}

void TestQgsLayoutMap::dataDefinedTemporalRange()
Expand Down Expand Up @@ -718,11 +714,7 @@ void TestQgsLayoutMap::expressionContext()

QgsExpression e9( QStringLiteral( "@map_crs_ellipsoid" ) );
r = e9.evaluate( &c );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( r.toString(), QString( "EPSG:7030" ) );
#else
QCOMPARE( r.toString(), QString( "WGS84" ) );
#endif

QgsVectorLayer *layer = new QgsVectorLayer( QStringLiteral( "Point?field=id_a:integer" ), QStringLiteral( "A" ), QStringLiteral( "memory" ) );
QgsVectorLayer *layer2 = new QgsVectorLayer( QStringLiteral( "Point?field=id_a:integer" ), QStringLiteral( "B" ), QStringLiteral( "memory" ) );
Expand Down
4 changes: 0 additions & 4 deletions tests/src/core/testqgsmapsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,7 @@ void TestQgsMapSettings::testExpressionContext()
e = QgsExpression( QStringLiteral( "@map_crs_ellipsoid" ) );
r = e.evaluate( &c );

#if PROJ_VERSION_MAJOR>=6
QCOMPARE( r.toString(), QStringLiteral( "EPSG:7030" ) );
#else
QCOMPARE( r.toString(), QStringLiteral( "WGS84" ) );
#endif

e = QgsExpression( QStringLiteral( "@map_start_time" ) );
r = e.evaluate( &c );
Expand Down
12 changes: 0 additions & 12 deletions tests/src/core/testqgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,7 @@ void TestQgsProject::testSetGetCrs()
QCOMPARE( ellipsoidChangedSpy.count(), 1 );

QCOMPARE( p.crs(), QgsCoordinateReferenceSystem::fromEpsgId( 21781 ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( p.ellipsoid(), QStringLiteral( "EPSG:7004" ) );
#else
QCOMPARE( p.ellipsoid(), QStringLiteral( "bessel" ) );
#endif

crsChangedSpy.clear();
ellipsoidChangedSpy.clear();
Expand All @@ -614,11 +610,7 @@ void TestQgsProject::testSetGetCrs()
QCOMPARE( ellipsoidChangedSpy.count(), 0 );

QCOMPARE( p.crs(), QgsCoordinateReferenceSystem::fromEpsgId( 2056 ) );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( p.ellipsoid(), QStringLiteral( "EPSG:7004" ) );
#else
QCOMPARE( p.ellipsoid(), QStringLiteral( "bessel" ) );
#endif
}

void TestQgsProject::testCrsValidAfterReadingProjectFile()
Expand Down Expand Up @@ -692,11 +684,7 @@ void TestQgsProject::testCrsExpressions()

QgsExpression e9( QStringLiteral( "@project_crs_ellipsoid" ) );
r = e9.evaluate( &c );
#if PROJ_VERSION_MAJOR>=6
QCOMPARE( r.toString(), QString( "EPSG:7030" ) );
#else
QCOMPARE( r.toString(), QString( "WGS84" ) );
#endif
}

QGSTEST_MAIN( TestQgsProject )
Expand Down
10 changes: 0 additions & 10 deletions tests/src/core/testqgsprojutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
#include "qgsapplication.h"
#include "qgslogger.h"

#if PROJ_VERSION_MAJOR>=6
#include <proj.h>
#endif

//header for class being tested
#include "qgsprojutils.h"
Expand Down Expand Up @@ -77,40 +75,33 @@ void TestQgsProjUtils::threadSafeContext()

void TestQgsProjUtils::usesAngularUnits()
{
#if PROJ_VERSION_MAJOR>=6
QVERIFY( !QgsProjUtils::usesAngularUnit( QString() ) );
QVERIFY( !QgsProjUtils::usesAngularUnit( QString( "" ) ) );
QVERIFY( !QgsProjUtils::usesAngularUnit( QStringLiteral( "x" ) ) );
QVERIFY( QgsProjUtils::usesAngularUnit( QStringLiteral( "+proj=longlat +ellps=WGS60 +no_defs" ) ) );
QVERIFY( !QgsProjUtils::usesAngularUnit( QStringLiteral( "+proj=tmerc +lat_0=0 +lon_0=147 +k_0=0.9996 +x_0=500000 +y_0=10000000 +ellps=GRS80 +units=m +no_defs" ) ) );
#endif
}

void TestQgsProjUtils::axisOrderIsSwapped()
{
#if PROJ_VERSION_MAJOR>=6
PJ_CONTEXT *context = QgsProjContext::get();
QVERIFY( !QgsProjUtils::axisOrderIsSwapped( nullptr ) );

QgsProjUtils::proj_pj_unique_ptr crs( proj_create( context, "urn:ogc:def:crs:EPSG::3111" ) );
QVERIFY( !QgsProjUtils::axisOrderIsSwapped( crs.get() ) );
crs.reset( proj_create( context, "urn:ogc:def:crs:EPSG::4326" ) );
QVERIFY( QgsProjUtils::axisOrderIsSwapped( crs.get() ) );
#endif
}

void TestQgsProjUtils::searchPath()
{
#if PROJ_VERSION_MAJOR>=6
// ensure local user-writable path is present in Proj search paths
const QStringList paths = QgsProjUtils::searchPaths();
QVERIFY( paths.contains( QgsApplication::qgisSettingsDirPath() + QStringLiteral( "proj" ) ) );
#endif
}

void TestQgsProjUtils::gridsUsed()
{
#if PROJ_VERSION_MAJOR>=6
// ensure local user-writable path is present in Proj search paths
QList< QgsDatumTransform::GridDetails > grids = QgsProjUtils::gridsUsed( QStringLiteral( "+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +inv +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1" ) );
QCOMPARE( grids.count(), 1 );
Expand All @@ -129,7 +120,6 @@ void TestQgsProjUtils::gridsUsed()
QCOMPARE( grids.at( 0 ).packageName, QStringLiteral( "proj-datumgrid-oceania" ) );
QVERIFY( grids.at( 0 ).directDownload );
#endif
#endif
}

QGSTEST_MAIN( TestQgsProjUtils )
Expand Down
2 changes: 0 additions & 2 deletions tests/src/gui/testprocessinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5406,7 +5406,6 @@ void TestProcessingGui::testColorWrapper()

void TestProcessingGui::testCoordinateOperationWrapper()
{
#if PROJ_VERSION_MAJOR>=6
auto testWrapper = []( QgsProcessingGui::WidgetType type )
{
QgsProcessingParameterCoordinateOperation param( QStringLiteral( "op" ), QStringLiteral( "op" ) );
Expand Down Expand Up @@ -5513,7 +5512,6 @@ void TestProcessingGui::testCoordinateOperationWrapper()
QCOMPARE( def->description(), QStringLiteral( "test desc" ) );
QVERIFY( def->flags() & QgsProcessingParameterDefinition::FlagOptional );
QVERIFY( def->flags() & QgsProcessingParameterDefinition::FlagAdvanced );
#endif
}

void TestProcessingGui::mapLayerComboBox()
Expand Down
Loading