Skip to content

Commit

Permalink
store original proj4 representation of a CRS and use it to store a cu…
Browse files Browse the repository at this point in the history
…stom CRS
  • Loading branch information
leyan authored and mhugent committed Feb 10, 2014
1 parent 89f08f0 commit 9a79188
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -277,6 +277,7 @@ QgsCoordinateReferenceSystem& QgsCoordinateReferenceSystem::operator=( const Qgs
mIsValidFlag = srs.mIsValidFlag;
mValidationHint = srs.mValidationHint;
mWkt = srs.mWkt;
mProj4 = srs.mProj4;
if ( mIsValidFlag )
{
OSRDestroySpatialReference( mCRS );
Expand Down Expand Up @@ -368,7 +369,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
myPreparedStatement, 1 ) );
mProjectionAcronym = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 2 ) );
mEllipsoidAcronym = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 3 ) );
QString toProj4 = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 4 ) );
mProj4 = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 4 ) );
mSRID = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 5 ) ).toLong();
mAuthId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 6 ) );
mGeoFlag = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt() != 0;
Expand All @@ -388,7 +389,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q

if ( !mIsValidFlag )
{
setProj4String( toProj4 );
setProj4String( mProj4 );
}
}
else
Expand Down Expand Up @@ -430,6 +431,7 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &theWkt )
{
mIsValidFlag = false;
mWkt.clear();
mProj4.clear();

if ( theWkt.isEmpty() )
{
Expand Down Expand Up @@ -874,14 +876,16 @@ QString QgsCoordinateReferenceSystem::toProj4() const
if ( !mIsValidFlag )
return "";

QString toProj4;
char *proj4src = NULL;
OSRExportToProj4( mCRS, &proj4src );
toProj4 = proj4src;
CPLFree( proj4src );

if ( mProj4.isEmpty() )
{
QString toProj4;
char *proj4src = NULL;
OSRExportToProj4( mCRS, &proj4src );
mProj4 = proj4src;
CPLFree( proj4src );
}
// Stray spaces at the end?
return toProj4.trimmed();
return mProj4.trimmed();
}

bool QgsCoordinateReferenceSystem::geographicFlag() const
Expand Down Expand Up @@ -916,6 +920,7 @@ void QgsCoordinateReferenceSystem::setDescription( QString theDescription )
}
void QgsCoordinateReferenceSystem::setProj4String( QString theProj4String )
{
mProj4 = theProj4String;
char *oldlocale = setlocale( LC_NUMERIC, NULL );
/* the next setlocale() invalides the return of previous setlocale() */
if ( oldlocale )
Expand Down Expand Up @@ -1462,6 +1467,12 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS( QString name )

QString mySql;

QString proj4String=mProj4;
if ( proj4String.isEmpty() )
{
proj4String = toProj4();
}

//if this is the first record we need to ensure that its srs_id is 10000. For
//any rec after that sqlite3 will take care of the autonumering
//this was done to support sqlite 3.0 as it does not yet support
Expand Down
1 change: 1 addition & 0 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -465,6 +465,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem

QString mValidationHint;
mutable QString mWkt;
mutable QString mProj4;

static bool loadIDs( QHash<int, QString> &wkts );
static bool loadWkts( QHash<int, QString> &wkts, const char *filename );
Expand Down

0 comments on commit 9a79188

Please sign in to comment.