42
42
#if PROJ_VERSION_MAJOR>=6
43
43
#include " qgsprojutils.h"
44
44
#include < proj.h>
45
+ #include < proj_experimental.h>
45
46
#else
46
47
#include < proj_api.h>
47
48
#endif
@@ -72,6 +73,23 @@ QHash< long, QgsCoordinateReferenceSystem > QgsCoordinateReferenceSystem::sSrsId
72
73
QReadWriteLock QgsCoordinateReferenceSystem::sCrsStringLock ;
73
74
QHash< QString, QgsCoordinateReferenceSystem > QgsCoordinateReferenceSystem::sStringCache ;
74
75
76
+
77
+ #if PROJ_VERSION_MAJOR>=6
78
+ QString getFullProjString ( PJ *obj )
79
+ {
80
+ // see https://lists.osgeo.org/pipermail/proj/2019-May/008565.html, it's not sufficient to just
81
+ // use proj_as_proj_string
82
+ QgsProjUtils::proj_pj_unique_ptr boundCrs ( proj_crs_create_bound_crs_to_WGS84 ( QgsProjContext::get (), obj, nullptr ) );
83
+ if ( const char *proj4src = proj_as_proj_string ( QgsProjContext::get (), boundCrs.get (), PJ_PROJ_4, nullptr ) )
84
+ {
85
+ return QString ( proj4src );
86
+ }
87
+ else
88
+ {
89
+ return QString ( proj_as_proj_string ( QgsProjContext::get (), obj, PJ_PROJ_4, nullptr ) );
90
+ }
91
+ }
92
+ #endif
75
93
// --------------------------
76
94
77
95
QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ()
@@ -91,7 +109,7 @@ QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( const long id, CrsTy
91
109
createFromId ( id, type );
92
110
}
93
111
94
- QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( const QgsCoordinateReferenceSystem &srs ) // NOLINT
112
+ QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( const QgsCoordinateReferenceSystem &srs ) // NOLINT
95
113
: d( srs.d )
96
114
{
97
115
}
@@ -703,12 +721,13 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &wkt )
703
721
// create the proj4 structs needed for transforming
704
722
if ( d->mPj )
705
723
{
706
- if ( const char *proj4src = proj_as_proj_string ( QgsProjContext::get (), d->mPj .get (), PJ_PROJ_4, nullptr ) )
724
+ const QString proj4String = getFullProjString ( d->mPj .get () );
725
+ if ( !proj4String.isEmpty () )
707
726
{
708
727
// now that we have the proj4string, delegate to createFromProj4 so
709
728
// that we can try to fill in the remaining class members...
710
729
// create from Proj will set the isValidFlag
711
- createFromProj4 ( proj4src );
730
+ createFromProj4 ( proj4String );
712
731
}
713
732
}
714
733
#else
@@ -1180,7 +1199,7 @@ QString QgsCoordinateReferenceSystem::toProj4() const
1180
1199
#if PROJ_VERSION_MAJOR>=6
1181
1200
if ( d->mPj )
1182
1201
{
1183
- d->mProj4 = QString ( proj_as_proj_string ( QgsProjContext::get (), d->mPj .get (), PJ_PROJ_4, nullptr ) );
1202
+ d->mProj4 = getFullProjString ( d->mPj .get () );
1184
1203
}
1185
1204
#else
1186
1205
char *proj4src = nullptr ;
@@ -2199,7 +2218,9 @@ int QgsCoordinateReferenceSystem::syncDatabase()
2199
2218
2200
2219
crs = QgsProjUtils::crsToSingleCrs ( crs.get () );
2201
2220
2202
- QString proj4 ( proj_as_proj_string ( pjContext, crs.get (), PJ_PROJ_4, nullptr ) );
2221
+ crs.reset ( proj_crs_create_bound_crs_to_WGS84 ( pjContext, crs.get (), nullptr ) );
2222
+
2223
+ QString proj4 = getFullProjString ( crs.get () );
2203
2224
proj4.replace ( QStringLiteral ( " +type=crs" ), QString () );
2204
2225
proj4 = proj4.trimmed ();
2205
2226
0 commit comments