@@ -277,6 +277,7 @@ QgsCoordinateReferenceSystem& QgsCoordinateReferenceSystem::operator=( const Qgs
277277 mIsValidFlag = srs.mIsValidFlag ;
278278 mValidationHint = srs.mValidationHint ;
279279 mWkt = srs.mWkt ;
280+ mProj4 = srs.mProj4 ;
280281 if ( mIsValidFlag )
281282 {
282283 OSRDestroySpatialReference ( mCRS );
@@ -368,7 +369,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
368369 myPreparedStatement, 1 ) );
369370 mProjectionAcronym = QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement, 2 ) );
370371 mEllipsoidAcronym = QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement, 3 ) );
371- QString toProj4 = QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement, 4 ) );
372+ mProj4 = QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement, 4 ) );
372373 mSRID = QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement, 5 ) ).toLong ();
373374 mAuthId = QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement, 6 ) );
374375 mGeoFlag = QString::fromUtf8 (( char * )sqlite3_column_text ( myPreparedStatement, 7 ) ).toInt () != 0 ;
@@ -388,7 +389,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
388389
389390 if ( !mIsValidFlag )
390391 {
391- setProj4String ( toProj4 );
392+ setProj4String ( mProj4 );
392393 }
393394 }
394395 else
@@ -430,6 +431,7 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &theWkt )
430431{
431432 mIsValidFlag = false ;
432433 mWkt .clear ();
434+ mProj4 .clear ();
433435
434436 if ( theWkt.isEmpty () )
435437 {
@@ -874,14 +876,16 @@ QString QgsCoordinateReferenceSystem::toProj4() const
874876 if ( !mIsValidFlag )
875877 return " " ;
876878
877- QString toProj4;
878- char *proj4src = NULL ;
879- OSRExportToProj4 ( mCRS , &proj4src );
880- toProj4 = proj4src;
881- CPLFree ( proj4src );
882-
879+ if ( mProj4 .isEmpty () )
880+ {
881+ QString toProj4;
882+ char *proj4src = NULL ;
883+ OSRExportToProj4 ( mCRS , &proj4src );
884+ mProj4 = proj4src;
885+ CPLFree ( proj4src );
886+ }
883887 // Stray spaces at the end?
884- return toProj4 .trimmed ();
888+ return mProj4 .trimmed ();
885889}
886890
887891bool QgsCoordinateReferenceSystem::geographicFlag () const
@@ -916,6 +920,7 @@ void QgsCoordinateReferenceSystem::setDescription( QString theDescription )
916920}
917921void QgsCoordinateReferenceSystem::setProj4String ( QString theProj4String )
918922{
923+ mProj4 = theProj4String;
919924 char *oldlocale = setlocale ( LC_NUMERIC, NULL );
920925 /* the next setlocale() invalides the return of previous setlocale() */
921926 if ( oldlocale )
@@ -1462,6 +1467,12 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS( QString name )
14621467
14631468 QString mySql;
14641469
1470+ QString proj4String=mProj4 ;
1471+ if ( proj4String.isEmpty () )
1472+ {
1473+ proj4String = toProj4 ();
1474+ }
1475+
14651476 // if this is the first record we need to ensure that its srs_id is 10000. For
14661477 // any rec after that sqlite3 will take care of the autonumering
14671478 // this was done to support sqlite 3.0 as it does not yet support
0 commit comments