Skip to content

Commit cc6b010

Browse files
committed
custom CRS save API change
1 parent 0fd52ec commit cc6b010

File tree

2 files changed

+9
-52
lines changed

2 files changed

+9
-52
lines changed

src/core/qgscoordinatereferencesystem.cpp

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -641,46 +641,6 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
641641
{
642642
QgsDebugMsg( "Projection is not found in databases." );
643643
setProj4String( myProj4String );
644-
645-
// Is the SRS is valid now, we know it's a decent +proj string that can be entered into the srs.db
646-
if ( mIsValidFlag )
647-
{
648-
// but the proj.4 parsed string might already be in our database
649-
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) + " order by deprecated" );
650-
if ( myRecord.empty() )
651-
{
652-
// It's not, so try to add it
653-
QgsDebugMsg( "Projection appears to be valid. Save to database!" );
654-
mIsValidFlag = saveAsUserCRS();
655-
656-
if ( mIsValidFlag )
657-
{
658-
// but validate that it's there afterwards
659-
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) + " order by deprecated" );
660-
}
661-
}
662-
663-
if ( !myRecord.empty() )
664-
{
665-
// take the srid from the record
666-
mySrsId = myRecord["srs_id"].toLong();
667-
QgsDebugMsg( "proj4string match search for srsid returned srsid: " + QString::number( mySrsId ) );
668-
if ( mySrsId > 0 )
669-
{
670-
createFromSrsId( mySrsId );
671-
}
672-
else
673-
{
674-
QgsDebugMsg( QString( "invalid srid %1 found" ).arg( mySrsId ) );
675-
mIsValidFlag = false;
676-
}
677-
}
678-
else
679-
{
680-
QgsDebugMsg( "Couldn't find newly added proj string?" );
681-
mIsValidFlag = false;
682-
}
683-
}
684644
}
685645

686646
return mIsValidFlag;
@@ -1426,7 +1386,7 @@ QString QgsCoordinateReferenceSystem::validationHint()
14261386
/// Copied from QgsCustomProjectionDialog ///
14271387
/// Please refactor into SQL handler !!! ///
14281388

1429-
bool QgsCoordinateReferenceSystem::saveAsUserCRS()
1389+
bool QgsCoordinateReferenceSystem::saveAsUserCRS(QString name)
14301390
{
14311391
if ( ! mIsValidFlag )
14321392
{
@@ -1435,9 +1395,6 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS()
14351395
}
14361396

14371397
QString mySql;
1438-
QString myName = QString( " * %1 (%2)" )
1439-
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
1440-
.arg( toProj4() );
14411398

14421399
//if this is the first record we need to ensure that its srs_id is 10000. For
14431400
//any rec after that sqlite3 will take care of the autonumering
@@ -1447,7 +1404,7 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS()
14471404
{
14481405
mySql = "insert into tbl_srs (srs_id,description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
14491406
+ QString::number( USER_CRS_START_ID )
1450-
+ "," + quotedValue( myName )
1407+
+ "," + quotedValue( name )
14511408
+ "," + quotedValue( projectionAcronym() )
14521409
+ "," + quotedValue( ellipsoidAcronym() )
14531410
+ "," + quotedValue( toProj4() )
@@ -1456,7 +1413,7 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS()
14561413
else
14571414
{
14581415
mySql = "insert into tbl_srs (description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
1459-
+ quotedValue( myName )
1416+
+ quotedValue( name )
14601417
+ "," + quotedValue( projectionAcronym() )
14611418
+ "," + quotedValue( ellipsoidAcronym() )
14621419
+ "," + quotedValue( toProj4() )

src/core/qgscoordinatereferencesystem.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
151151
* check for a match in entities that have the same ellps and proj entries so
152152
* that it doesn't munch yer cpu so much.
153153
*
154-
* @note If the srs was not matched, we will create a new entry on the users tbl_srs
155-
* for this srs.
156-
*
157154
* @param theProjString A proj4 format string
158155
* @return bool TRUE if success else false
159156
*/
@@ -350,6 +347,12 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
350347
* @note added in 1.8
351348
*/
352349
static int syncDb();
350+
351+
352+
/*! Save the proj4-string as a custom CRS
353+
* @returns bool true if success else false
354+
*/
355+
bool saveAsUserCRS( QString name );
353356

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

450-
//! Save the proj4-string as a custom CRS
451-
bool saveAsUserCRS();
452-
453453
//! Helper for getting number of user CRS already in db
454454
long getRecordCount();
455455

0 commit comments

Comments
 (0)