Skip to content

Commit 1b6b841

Browse files
committed
Merge pull request #142 from etiennesky/fix_crs
Fix crs issues
2 parents 9dcee6b + 396aaf1 commit 1b6b841

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/core/qgscoordinatereferencesystem.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
256256

257257
QString mySql = "select srs_id,description,projection_acronym,"
258258
"ellipsoid_acronym,parameters,srid,auth_name||':'||auth_id,is_geo "
259-
"from tbl_srs where " + expression + "=" + quotedValue( value );
259+
"from tbl_srs where " + expression + "=" + quotedValue( value ) + " order by deprecated";
260260
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(),
261261
mySql.toUtf8().length(),
262262
&myPreparedStatement, &myTail );
@@ -444,7 +444,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
444444
* - if the above does not match perform a whole text search on proj4 string (if not null)
445445
*/
446446
// QgsDebugMsg( "wholetext match on name failed, trying proj4string match" );
447-
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( theProj4String.trimmed() ) );
447+
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( theProj4String.trimmed() ) + " order by deprecated" );
448448
if ( myRecord.empty() )
449449
{
450450
// Ticket #722 - aaronr
@@ -479,7 +479,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
479479
myStart2 = myLat2RegExp.indexIn( theProj4String, myStart2 );
480480
theProj4StringModified.replace( myStart2 + LAT_PREFIX_LEN, myLength2 - LAT_PREFIX_LEN, lat1Str );
481481
QgsDebugMsg( "trying proj4string match with swapped lat_1,lat_2" );
482-
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( theProj4StringModified.trimmed() ) );
482+
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( theProj4StringModified.trimmed() ) + " order by deprecated" );
483483
}
484484
}
485485

@@ -496,9 +496,10 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
496496

497497
// split on spaces followed by a plus sign (+) to deal
498498
// also with parameters containing spaces (e.g. +nadgrids)
499+
// make sure result is trimmed (#5598)
499500
foreach( QString param, theProj4String.split( QRegExp( "\\s+(?=\\+)" ), QString::SkipEmptyParts ) )
500501
{
501-
QString arg = QString( "' '||parameters||' ' LIKE %1" ).arg( quotedValue( QString( "% %1 %" ).arg( param ) ) );
502+
QString arg = QString( "' '||parameters||' ' LIKE %1" ).arg( quotedValue( QString( "% %1 %" ).arg( param.trimmed() ) ) );
502503
if ( param.startsWith( "+datum=" ) )
503504
{
504505
datum = arg;
@@ -512,13 +513,13 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
512513

513514
if ( !datum.isEmpty() )
514515
{
515-
myRecord = getRecord( sql + delim + datum );
516+
myRecord = getRecord( sql + delim + datum + " order by deprecated" );
516517
}
517518

518519
if ( myRecord.empty() )
519520
{
520521
// datum might have disappeared in definition - retry without it
521-
myRecord = getRecord( sql );
522+
myRecord = getRecord( sql + " order by deprecated" );
522523
}
523524
}
524525

@@ -558,7 +559,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
558559
if ( mIsValidFlag )
559560
{
560561
// but the proj.4 parsed string might already be in our database
561-
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) );
562+
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) + " order by deprecated" );
562563
if ( myRecord.empty() )
563564
{
564565
// It's not, so try to add it
@@ -568,7 +569,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
568569
if ( mIsValidFlag )
569570
{
570571
// but validate that it's there afterwards
571-
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) );
572+
myRecord = getRecord( "select * from tbl_srs where parameters=" + quotedValue( toProj4() ) + " order by deprecated" );
572573
}
573574
}
574575

@@ -928,7 +929,7 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
928929
// Set up the query to retrieve the projection information
929930
// needed to populate the list
930931
QString mySql = QString( "select srs_id,parameters from tbl_srs where "
931-
"projection_acronym=%1 and ellipsoid_acronym=%2" )
932+
"projection_acronym=%1 and ellipsoid_acronym=%2 order by deprecated" )
932933
.arg( quotedValue( mProjectionAcronym ) )
933934
.arg( quotedValue( mEllipsoidAcronym ) );
934935
// Get the full path name to the sqlite3 spatial reference database.
@@ -1212,7 +1213,7 @@ QString QgsCoordinateReferenceSystem::proj4FromSrsId( const int theSrsId )
12121213

12131214
QString myDatabaseFileName;
12141215
QString myProjString;
1215-
QString mySql = QString( "select parameters from tbl_srs where srs_id = %1" ).arg( theSrsId );
1216+
QString mySql = QString( "select parameters from tbl_srs where srs_id = %1 order by deprecated" ).arg( theSrsId );
12161217

12171218
QgsDebugMsg( "mySrsId = " + QString::number( theSrsId ) );
12181219
QgsDebugMsg( "USER_CRS_START_ID = " + QString::number( USER_CRS_START_ID ) );
@@ -1451,7 +1452,7 @@ int QgsCoordinateReferenceSystem::syncDb()
14511452

14521453
const char *tail;
14531454
sqlite3_stmt *select;
1454-
QString sql = "select auth_name,auth_id,parameters from tbl_srs WHERE auth_name IS NOT NULL AND auth_id IS NOT NULL";
1455+
QString sql = "select auth_name,auth_id,parameters from tbl_srs WHERE auth_name IS NOT NULL AND auth_id IS NOT NULL order by deprecated";
14551456
if ( sqlite3_prepare( database, sql.toAscii(), sql.size(), &select, &tail ) != SQLITE_OK )
14561457
{
14571458
qCritical( "Could not prepare: %s [%s]\n", sql.toAscii().constData(), sqlite3_errmsg( database ) );

0 commit comments

Comments
 (0)