37
37
#include " qgssettings.h"
38
38
39
39
#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
43
44
#include < proj_api.h>
45
+ #endif
44
46
45
47
// gdal and ogr includes (needed for == operator)
46
48
#include < ogr_srs_api.h>
@@ -1127,7 +1129,18 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
1127
1129
1128
1130
OSRDestroySpatialReference ( d->mCRS );
1129
1131
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
1131
1144
// OSRImportFromProj4() may accept strings that are not valid proj.4 strings,
1132
1145
// e.g if they lack a +ellps parameter, it will automatically add +ellps=WGS84, but as
1133
1146
// we use the original mProj4 with QgsCoordinateTransform, it will fail to initialize
@@ -1144,6 +1157,8 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
1144
1157
pj_free ( proj );
1145
1158
}
1146
1159
pj_ctx_free ( pContext );
1160
+ #endif
1161
+
1147
1162
d->mWkt .clear ();
1148
1163
setMapUnits ();
1149
1164
}
1 commit comments
PeterPetrik commentedon Apr 25, 2019
this commit broken build with proj6