@@ -525,9 +525,14 @@ bool QgsCoordinateReferenceSystem::loadFromDatabase( const QString &db, const QS
525
525
}
526
526
else if ( d->mAuthId .startsWith ( QLatin1String ( " EPSG:" ), Qt::CaseInsensitive ) )
527
527
{
528
+ #if PROJ_VERSION_MAJOR>=6
529
+ d->mPj .reset ( proj_create_from_database ( QgsProjContext::get (), " EPSG" , d->mAuthId .mid ( 5 ).toLatin1 (), PJ_CATEGORY_CRS, false , nullptr ) );
530
+ d->mIsValid = static_cast < bool >( d->mPj );
531
+ #else
528
532
OSRDestroySpatialReference ( d->mCRS );
529
533
d->mCRS = OSRNewSpatialReference ( nullptr );
530
534
d->mIsValid = OSRSetFromUserInput ( d->mCRS , d->mAuthId .toLower ().toLatin1 () ) == OGRERR_NONE;
535
+ #endif
531
536
setMapUnits ();
532
537
}
533
538
@@ -547,6 +552,9 @@ bool QgsCoordinateReferenceSystem::hasAxisInverted() const
547
552
{
548
553
if ( d->mAxisInvertedDirty )
549
554
{
555
+ #if PROJ_VERSION_MAJOR>=6
556
+ d->mAxisInverted = QgsProjUtils::axisOrderIsSwapped ( d->mPj .get () );
557
+ #else
550
558
OGRAxisOrientation orientation;
551
559
OSRGetAxis ( d->mCRS , OSRIsGeographic ( d->mCRS ) ? " GEOGCS" : " PROJCS" , 0 , &orientation );
552
560
@@ -564,6 +572,7 @@ bool QgsCoordinateReferenceSystem::hasAxisInverted() const
564
572
}
565
573
566
574
d->mAxisInverted = orientation == OAO_North;
575
+ #endif
567
576
d->mAxisInvertedDirty = false ;
568
577
}
569
578
@@ -588,25 +597,48 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &wkt )
588
597
d->mIsValid = false ;
589
598
d->mWkt .clear ();
590
599
d->mProj4 .clear ();
591
-
592
600
if ( wkt.isEmpty () )
593
601
{
594
602
QgsDebugMsgLevel ( QStringLiteral ( " theWkt is uninitialized, operation failed" ), 4 );
595
603
return d->mIsValid ;
596
604
}
605
+
606
+ bool res = false ;
607
+ #if PROJ_VERSION_MAJOR>=6
608
+ PROJ_STRING_LIST warnings = nullptr ;
609
+ PROJ_STRING_LIST grammerErrors = nullptr ;
610
+ d->mPj .reset ( proj_create_from_wkt ( QgsProjContext::get (), wkt.toLatin1 ().constData (), nullptr , &warnings, &grammerErrors ) );
611
+ res = static_cast < bool >( d->mPj );
612
+ if ( !res )
613
+ {
614
+ QgsDebugMsg ( QStringLiteral ( " \n ---------------------------------------------------------------" ) );
615
+ QgsDebugMsg ( QStringLiteral ( " This CRS could *** NOT *** be set from the supplied Wkt " ) );
616
+ QgsDebugMsg ( " INPUT: " + wkt );
617
+ for ( auto iter = warnings; iter && *iter; ++iter )
618
+ QgsDebugMsg ( *iter );
619
+ for ( auto iter = grammerErrors; iter && *iter; ++iter )
620
+ QgsDebugMsg ( *iter );
621
+ QgsDebugMsg ( QStringLiteral ( " ---------------------------------------------------------------\n " ) );
622
+ }
623
+ proj_string_list_destroy ( warnings );
624
+ proj_string_list_destroy ( grammerErrors );
625
+ #else
597
626
QByteArray ba = wkt.toLatin1 ();
598
627
const char *pWkt = ba.data ();
599
628
600
629
OGRErr myInputResult = OSRImportFromWkt ( d->mCRS , const_cast < char ** >( & pWkt ) );
601
-
602
- if ( myInputResult != OGRERR_NONE )
630
+ res = myInputResult != OGRERR_NONE;
631
+ if ( !res )
603
632
{
604
633
QgsDebugMsg ( QStringLiteral ( " \n ---------------------------------------------------------------" ) );
605
634
QgsDebugMsg ( QStringLiteral ( " This CRS could *** NOT *** be set from the supplied Wkt " ) );
606
635
QgsDebugMsg ( " INPUT: " + wkt );
607
636
QgsDebugMsg ( QStringLiteral ( " UNUSED WKT: %1" ).arg ( pWkt ) );
608
637
QgsDebugMsg ( QStringLiteral ( " ---------------------------------------------------------------\n " ) );
609
-
638
+ }
639
+ #endif
640
+ if ( !res )
641
+ {
610
642
sCRSWktLock .lockForWrite ();
611
643
sWktCache .insert ( wkt, *this );
612
644
sCRSWktLock .unlock ();
@@ -1129,17 +1161,23 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
1129
1161
1130
1162
OSRDestroySpatialReference ( d->mCRS );
1131
1163
d->mCRS = OSRNewSpatialReference ( nullptr );
1164
+
1132
1165
const QString trimmed = proj4String.trimmed ();
1133
1166
d->mIsValid = OSRImportFromProj4 ( d->mCRS , trimmed.toLatin1 ().constData () ) == OGRERR_NONE;
1167
+
1134
1168
#if PROJ_VERSION_MAJOR>=6
1135
1169
PJ_CONTEXT *ctx = QgsProjContext::get ();
1136
- QgsProjUtils::proj_pj_unique_ptr proj ( proj_create ( ctx, trimmed.toLatin1 ().constData () ) );
1137
- if ( !proj )
1170
+ d-> mPj . reset ( proj_create ( ctx, trimmed.toLatin1 ().constData () ) );
1171
+ if ( !d-> mPj )
1138
1172
{
1139
1173
const int errNo = proj_context_errno ( ctx );
1140
1174
QgsDebugMsg ( QStringLiteral ( " proj string rejected: %1" ).arg ( proj_errno_string ( errNo ) ) );
1141
1175
d->mIsValid = false ;
1142
1176
}
1177
+ else
1178
+ {
1179
+ d->mIsValid = true ;
1180
+ }
1143
1181
#else
1144
1182
// OSRImportFromProj4() may accept strings that are not valid proj.4 strings,
1145
1183
// e.g if they lack a +ellps parameter, it will automatically add +ellps=WGS84, but as
@@ -1870,6 +1908,7 @@ bool QgsCoordinateReferenceSystem::loadIds( QHash<int, QString> &wkts )
1870
1908
1871
1909
int QgsCoordinateReferenceSystem::syncDatabase ()
1872
1910
{
1911
+ #if 1
1873
1912
setlocale ( LC_ALL, " C" );
1874
1913
QString dbFilePath = QgsApplication::srsDatabaseFilePath ();
1875
1914
syncDatumTransform ( dbFilePath );
@@ -2370,6 +2409,7 @@ bool QgsCoordinateReferenceSystem::syncDatumTransform( const QString &dbPath )
2370
2409
return false ;
2371
2410
}
2372
2411
2412
+ #endif
2373
2413
return true ;
2374
2414
}
2375
2415
0 commit comments