Skip to content

Commit 018f3bc

Browse files
committedApr 15, 2019
Remove more proj4 api usage
1 parent d3f6a5f commit 018f3bc

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed
 

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
#include "qgssettings.h"
3838

3939
#include <sqlite3.h>
40-
#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
41-
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
42-
#endif
40+
#if PROJ_VERSION_MAJOR>=6
41+
#include "qgsprojutils.h"
42+
#include <proj.h>
43+
#else
4344
#include <proj_api.h>
45+
#endif
4446

4547
//gdal and ogr includes (needed for == operator)
4648
#include <ogr_srs_api.h>
@@ -1127,7 +1129,18 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
11271129

11281130
OSRDestroySpatialReference( d->mCRS );
11291131
d->mCRS = OSRNewSpatialReference( nullptr );
1130-
d->mIsValid = OSRImportFromProj4( d->mCRS, proj4String.trimmed().toLatin1().constData() ) == OGRERR_NONE;
1132+
const QString trimmed = proj4String.trimmed();
1133+
d->mIsValid = OSRImportFromProj4( d->mCRS, trimmed.toLatin1().constData() ) == OGRERR_NONE;
1134+
#if PROJ_VERSION_MAJOR>=6
1135+
PJ_CONTEXT *ctx = QgsProjContext::get();
1136+
QgsProjUtils::proj_pj_unique_ptr proj( proj_create( ctx, trimmed.toLatin1().constData() ) );
1137+
if ( !proj )
1138+
{
1139+
const int errNo = proj_context_errno( ctx );
1140+
QgsDebugMsg( QStringLiteral( "proj string rejected: %1" ).arg( proj_errno_string( errNo ) ) );
1141+
d->mIsValid = false;
1142+
}
1143+
#else
11311144
// OSRImportFromProj4() may accept strings that are not valid proj.4 strings,
11321145
// e.g if they lack a +ellps parameter, it will automatically add +ellps=WGS84, but as
11331146
// we use the original mProj4 with QgsCoordinateTransform, it will fail to initialize
@@ -1144,6 +1157,8 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
11441157
pj_free( proj );
11451158
}
11461159
pj_ctx_free( pContext );
1160+
#endif
1161+
11471162
d->mWkt.clear();
11481163
setMapUnits();
11491164
}

1 commit comments

Comments
 (1)

PeterPetrik commented on Apr 25, 2019

@PeterPetrik
Contributor

this commit broken build with proj6

Please sign in to comment.