Skip to content

Commit

Permalink
custom CRS save API change
Browse files Browse the repository at this point in the history
  • Loading branch information
leyan committed Apr 16, 2013
1 parent 0fd52ec commit cc6b010
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 52 deletions.
49 changes: 3 additions & 46 deletions src/core/qgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,46 +641,6 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
{
QgsDebugMsg( "Projection is not found in databases." );
setProj4String( myProj4String );

// Is the SRS is valid now, we know it's a decent +proj string that can be entered into the srs.db
if ( mIsValidFlag )
{
// but the proj.4 parsed string might already be in our database
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) + " order by deprecated" );
if ( myRecord.empty() )
{
// It's not, so try to add it
QgsDebugMsg( "Projection appears to be valid. Save to database!" );
mIsValidFlag = saveAsUserCRS();

if ( mIsValidFlag )
{
// but validate that it's there afterwards
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) + " order by deprecated" );
}
}

if ( !myRecord.empty() )
{
// take the srid from the record
mySrsId = myRecord["srs_id"].toLong();
QgsDebugMsg( "proj4string match search for srsid returned srsid: " + QString::number( mySrsId ) );
if ( mySrsId > 0 )
{
createFromSrsId( mySrsId );
}
else
{
QgsDebugMsg( QString( "invalid srid %1 found" ).arg( mySrsId ) );
mIsValidFlag = false;
}
}
else
{
QgsDebugMsg( "Couldn't find newly added proj string?" );
mIsValidFlag = false;
}
}
}

return mIsValidFlag;
Expand Down Expand Up @@ -1426,7 +1386,7 @@ QString QgsCoordinateReferenceSystem::validationHint()
/// Copied from QgsCustomProjectionDialog ///
/// Please refactor into SQL handler !!! ///

bool QgsCoordinateReferenceSystem::saveAsUserCRS()
bool QgsCoordinateReferenceSystem::saveAsUserCRS(QString name)
{
if ( ! mIsValidFlag )
{
Expand All @@ -1435,9 +1395,6 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS()
}

QString mySql;
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( 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
Expand All @@ -1447,7 +1404,7 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS()
{
mySql = "insert into tbl_srs (srs_id,description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
+ QString::number( USER_CRS_START_ID )
+ "," + quotedValue( myName )
+ "," + quotedValue( name )
+ "," + quotedValue( projectionAcronym() )
+ "," + quotedValue( ellipsoidAcronym() )
+ "," + quotedValue( toProj4() )
Expand All @@ -1456,7 +1413,7 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS()
else
{
mySql = "insert into tbl_srs (description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
+ quotedValue( myName )
+ quotedValue( name )
+ "," + quotedValue( projectionAcronym() )
+ "," + quotedValue( ellipsoidAcronym() )
+ "," + quotedValue( toProj4() )
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgscoordinatereferencesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* check for a match in entities that have the same ellps and proj entries so
* that it doesn't munch yer cpu so much.
*
* @note If the srs was not matched, we will create a new entry on the users tbl_srs
* for this srs.
*
* @param theProjString A proj4 format string
* @return bool TRUE if success else false
*/
Expand Down Expand Up @@ -350,6 +347,12 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* @note added in 1.8
*/
static int syncDb();


/*! Save the proj4-string as a custom CRS
* @returns bool true if success else false
*/
bool saveAsUserCRS( QString name );

// Mutators -----------------------------------
// We don't want to expose these to the public api since they wont create
Expand Down Expand Up @@ -447,9 +450,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
//! Work out the projection units and set the appropriate local variable
void setMapUnits();

//! Save the proj4-string as a custom CRS
bool saveAsUserCRS();

//! Helper for getting number of user CRS already in db
long getRecordCount();

Expand Down

0 comments on commit cc6b010

Please sign in to comment.