@@ -533,15 +533,9 @@ bool QgsCoordinateReferenceSystem::loadFromDatabase( const QString &db, const QS
533
533
QString auth = parts.at ( 0 );
534
534
QString code = parts.at ( 1 );
535
535
536
- QgsProjUtils::proj_pj_unique_ptr crs ( proj_create_from_database ( QgsProjContext::get (), auth.toLatin1 (), code.toLatin1 (), PJ_CATEGORY_CRS, false , nullptr ) );
537
- if ( crs && proj_get_type ( crs.get () ) == PJ_TYPE_COMPOUND_CRS )
538
536
{
539
- // freaking take a guess that 0 is horizontal, because we are only mortal
540
- d->mPj .reset ( proj_crs_get_sub_crs ( QgsProjContext::get (), crs.get (), 0 ) );
541
- }
542
- else
543
- {
544
- d->mPj = std::move ( crs );
537
+ QgsProjUtils::proj_pj_unique_ptr crs ( proj_create_from_database ( QgsProjContext::get (), auth.toLatin1 (), code.toLatin1 (), PJ_CATEGORY_CRS, false , nullptr ) );
538
+ d->mPj = QgsProjUtils::crsToSingleCrs ( crs.get () );
545
539
}
546
540
547
541
d->mIsValid = static_cast < bool >( d->mPj );
@@ -625,15 +619,9 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &wkt )
625
619
PROJ_STRING_LIST warnings = nullptr ;
626
620
PROJ_STRING_LIST grammerErrors = nullptr ;
627
621
628
- QgsProjUtils::proj_pj_unique_ptr crs ( proj_create_from_wkt ( QgsProjContext::get (), wkt.toLatin1 ().constData (), nullptr , &warnings, &grammerErrors ) );
629
- if ( crs && proj_get_type ( crs.get () ) == PJ_TYPE_COMPOUND_CRS )
630
- {
631
- // freaking take a guess that 0 is horizontal, because we are only mortal
632
- d->mPj .reset ( proj_crs_get_sub_crs ( QgsProjContext::get (), crs.get (), 0 ) );
633
- }
634
- else
635
622
{
636
- d->mPj = std::move ( crs );
623
+ QgsProjUtils::proj_pj_unique_ptr crs ( proj_create_from_wkt ( QgsProjContext::get (), wkt.toLatin1 ().constData (), nullptr , &warnings, &grammerErrors ) );
624
+ d->mPj = QgsProjUtils::crsToSingleCrs ( crs.get () );
637
625
}
638
626
639
627
res = static_cast < bool >( d->mPj );
@@ -1232,20 +1220,14 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
1232
1220
d->mProj4 = proj4String;
1233
1221
1234
1222
QgsLocaleNumC l;
1235
- const QString trimmed = proj4String.trimmed ();
1223
+ const QString trimmed = proj4String.trimmed () + QStringLiteral ( " +type=crs " ) ;
1236
1224
1237
1225
#if PROJ_VERSION_MAJOR>=6
1238
1226
PJ_CONTEXT *ctx = QgsProjContext::get ();
1239
1227
1240
- QgsProjUtils::proj_pj_unique_ptr crs ( proj_create ( ctx, trimmed.toLatin1 ().constData () ) );
1241
- if ( crs && proj_get_type ( crs.get () ) == PJ_TYPE_COMPOUND_CRS )
1242
1228
{
1243
- // freaking take a guess that 0 is horizontal, because we are only mortal
1244
- d->mPj .reset ( proj_crs_get_sub_crs ( QgsProjContext::get (), crs.get (), 0 ) );
1245
- }
1246
- else
1247
- {
1248
- d->mPj = std::move ( crs );
1229
+ QgsProjUtils::proj_pj_unique_ptr crs ( proj_create ( ctx, trimmed.toLatin1 ().constData () ) );
1230
+ d->mPj = QgsProjUtils::crsToSingleCrs ( crs.get () );
1249
1231
}
1250
1232
1251
1233
if ( !d->mPj )
@@ -2128,6 +2110,17 @@ int QgsCoordinateReferenceSystem::syncDatabase()
2128
2110
continue ;
2129
2111
}
2130
2112
2113
+ switch ( proj_get_type ( crs.get () ) )
2114
+ {
2115
+ case PJ_TYPE_VERTICAL_CRS: // don't need these in the CRS db
2116
+ continue ;
2117
+
2118
+ default :
2119
+ break ;
2120
+ }
2121
+
2122
+ crs = QgsProjUtils::crsToSingleCrs ( crs.get () );
2123
+
2131
2124
QString proj4 ( proj_as_proj_string ( pjContext, crs.get (), PJ_PROJ_4, nullptr ) );
2132
2125
proj4 = proj4.trimmed ();
2133
2126
0 commit comments