@@ -529,7 +529,7 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
529
529
* as its quicker than methods below..
530
530
*/
531
531
long mySrsId = 0 ;
532
- QgsSpatialRefSys::RecordMap myRecord = getRecord (" select * from tbl_srs where where description='" + mDescription + " '" );
532
+ QgsSpatialRefSys::RecordMap myRecord = getRecord (" select * from tbl_srs where where description='" + mDescription . stripWhiteSpace () + " '" );
533
533
if (!myRecord.empty ())
534
534
{
535
535
mySrsId=myRecord[" srs_id" ].toLong ();
@@ -545,7 +545,7 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
545
545
* - if the above does not match perform a whole text search on proj4 string (if not null)
546
546
*/
547
547
std::cout << " QgsSpatialRefSys::createFromProj4 wholetext match on name failed, trying proj4string match" << std::endl;
548
- myRecord = getRecord (" select * from tbl_srs where where parameters='" + mProj4String + " '" );
548
+ myRecord = getRecord (" select * from tbl_srs where where parameters='" + mProj4String . stripWhiteSpace () + " '" );
549
549
if (!myRecord.empty ())
550
550
{
551
551
mySrsId=myRecord[" srs_id" ].toLong ();
@@ -945,7 +945,7 @@ long QgsSpatialRefSys::findMatchingProj()
945
945
QString myProj4String = (char *)sqlite3_column_text (myPreparedStatement, 1 );
946
946
if (this ->equals (myProj4String))
947
947
{
948
- std::cout << " QgsSpatialRefSys::findMatchingProj -------> MATCH FOUND srsid: " << mySrsId << std::endl;
948
+ std::cout << " QgsSpatialRefSys::findMatchingProj -------> MATCH FOUND in srs.db srsid: " << mySrsId << std::endl;
949
949
// close the sqlite3 statement
950
950
sqlite3_finalize (myPreparedStatement);
951
951
sqlite3_close (myDatabase);
@@ -957,12 +957,55 @@ long QgsSpatialRefSys::findMatchingProj()
957
957
}
958
958
}
959
959
}
960
- std::cout << " QgsSpatialRefSys::findMatchingProj -------> no match found!" << std::endl;
960
+ std::cout << " QgsSpatialRefSys::findMatchingProj -------> no match found in srs.db, trying user db now!" << std::endl;
961
+ // close the sqlite3 statement
962
+ sqlite3_finalize (myPreparedStatement);
963
+ sqlite3_close (myDatabase);
964
+ //
965
+ // Try the users db now
966
+ //
967
+
968
+ myDatabaseFileName = QDir::homeDirPath () + " /.qgis/qgis.db" ;
969
+ // check the db is available
970
+ myResult = sqlite3_open (myDatabaseFileName.latin1 (), &myDatabase);
971
+ if (myResult)
972
+ {
973
+ std::cout << " QgsSpatialRefSys::findMatchingProj Can't open database: " << sqlite3_errmsg (myDatabase) << std::endl;
974
+ // XXX This will likely never happen since on open, sqlite creates the
975
+ // database if it does not exist.
976
+ assert (myResult == 0 );
977
+ }
978
+
979
+ myResult = sqlite3_prepare (myDatabase, (const char *)mySql, mySql.length (), &myPreparedStatement, &myTail);
980
+ // XXX Need to free memory from the error msg if one is set
981
+ if (myResult == SQLITE_OK)
982
+ {
983
+
984
+ while (sqlite3_step (myPreparedStatement) == SQLITE_ROW)
985
+ {
986
+ QString mySrsId = (char *)sqlite3_column_text (myPreparedStatement,0 );
987
+ QString myProj4String = (char *)sqlite3_column_text (myPreparedStatement, 1 );
988
+ if (this ->equals (myProj4String))
989
+ {
990
+ std::cout << " QgsSpatialRefSys::findMatchingProj -------> MATCH FOUND in user qgis.db srsid: " << mySrsId << std::endl;
991
+ // close the sqlite3 statement
992
+ sqlite3_finalize (myPreparedStatement);
993
+ sqlite3_close (myDatabase);
994
+ return mySrsId.toLong ();
995
+ }
996
+ else
997
+ {
998
+ std::cout << " Not matched : " << myProj4String << std::endl;
999
+ }
1000
+ }
1001
+ }
1002
+ std::cout << " QgsSpatialRefSys::findMatchingProj -------> no match found in user db" << std::endl;
1003
+
961
1004
// close the sqlite3 statement
962
1005
sqlite3_finalize (myPreparedStatement);
963
1006
sqlite3_close (myDatabase);
964
1007
return 0 ;
965
- // XXX TODO Add on users db search here!
1008
+
966
1009
}
967
1010
968
1011
bool QgsSpatialRefSys::operator ==(const QgsSpatialRefSys &theSrs)
0 commit comments