Skip to content

Commit

Permalink
Expose control over whether custom projections are stored using proj …
Browse files Browse the repository at this point in the history
…or WKT strings
  • Loading branch information
nyalldawson committed Dec 18, 2019
1 parent 67f25fe commit 8bfca7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Expand Up @@ -696,11 +696,14 @@ Update proj.4 parameters in our database from proj.4
This is used internally and should not be necessary to call in client code
%End

long saveAsUserCrs( const QString &name );
long saveAsUserCrs( const QString &name, bool storeWkt = true );
%Docstring
Saves the CRS as a custom ("USER") CRS.

Returns the new CRS srsid(), or -1 if the CRS could not be saved.

If ``storeWkt`` is ``True`` then the WKT representation of the CRS will be stored in the database.
If it is ``False``, then only the lossy PROJ string representation of the CRS will be stored (not recommended).
%End

QString geographicCrsAuthId() const;
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -2117,7 +2117,7 @@ QString QgsCoordinateReferenceSystem::validationHint()
/// Copied from QgsCustomProjectionDialog ///
/// Please refactor into SQL handler !!! ///

long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name )
long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, bool storeWkt )
{
if ( !d->mIsValid )
{
Expand Down Expand Up @@ -2153,9 +2153,9 @@ long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name )
+ ',' + QgsSqliteUtils::quotedString( name )
+ ',' + ( !d->mProjectionAcronym.isEmpty() ? QgsSqliteUtils::quotedString( d->mProjectionAcronym ) : QStringLiteral( "''" ) )
+ ',' + quotedEllipsoidString
+ ',' + QgsSqliteUtils::quotedString( toProj4() )
+ ',' + ( !proj4String.isEmpty() ? QgsSqliteUtils::quotedString( proj4String ) : QStringLiteral( "''" ) )
+ ",0," // <-- is_geo shamelessly hard coded for now
+ QgsSqliteUtils::quotedString( wktString )
+ ( storeWkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ')';
}
else
Expand All @@ -2164,9 +2164,9 @@ long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name )
+ QgsSqliteUtils::quotedString( name )
+ ',' + ( !d->mProjectionAcronym.isEmpty() ? QgsSqliteUtils::quotedString( d->mProjectionAcronym ) : QStringLiteral( "''" ) )
+ ',' + quotedEllipsoidString
+ ',' + QgsSqliteUtils::quotedString( toProj4() )
+ ',' + ( !proj4String.isEmpty() ? QgsSqliteUtils::quotedString( proj4String ) : QStringLiteral( "''" ) )
+ ",0," // <-- is_geo shamelessly hard coded for now
+ QgsSqliteUtils::quotedString( wktString )
+ ( storeWkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ')';
}
sqlite3_database_unique_ptr database;
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgscoordinatereferencesystem.h
Expand Up @@ -658,8 +658,11 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* Saves the CRS as a custom ("USER") CRS.
*
* Returns the new CRS srsid(), or -1 if the CRS could not be saved.
*
* If \a storeWkt is TRUE then the WKT representation of the CRS will be stored in the database.
* If it is FALSE, then only the lossy PROJ string representation of the CRS will be stored (not recommended).
*/
long saveAsUserCrs( const QString &name );
long saveAsUserCrs( const QString &name, bool storeWkt = true );

//! Returns auth id of related geographic CRS
QString geographicCrsAuthId() const;
Expand Down

0 comments on commit 8bfca7f

Please sign in to comment.