Skip to content

Commit 5f28c14

Browse files
author
timlinux
committedMay 21, 2005
Check user db when doing reverse mapping of proj string or wkt. Updated changelog.
git-svn-id: http://svn.osgeo.org/qgis/trunk@3421 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent bc0e258 commit 5f28c14

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed
 

‎ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Version 0.6 'Simon' .... development version
44
QGIS Change Log
55

6+
2005-04-17 [timlinux] 0.6devel24
7+
** Added logic for reverse mapping a wkt or proj4string to an srsid - not
8+
very well tested at this stage but works for me with my test dataset
69
2005-04-17 [timlinux] 0.6devel23
710
** Numerous fixes and clean ups to projection handling
811
2005-05-15 [morb_au] 0.6devel21

‎configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dnl ---------------------------------------------------------------------------
2525
MAJOR_VERSION=0
2626
MINOR_VERSION=6
2727
MICRO_VERSION=0
28-
EXTRA_VERSION=23
28+
EXTRA_VERSION=24
2929
if test $EXTRA_VERSION -eq 0; then
3030
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}
3131
else

‎src/qgsspatialrefsys.cpp

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
529529
* as its quicker than methods below..
530530
*/
531531
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 () + "'");
533533
if (!myRecord.empty())
534534
{
535535
mySrsId=myRecord["srs_id"].toLong();
@@ -545,7 +545,7 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
545545
* - if the above does not match perform a whole text search on proj4 string (if not null)
546546
*/
547547
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 () + "'");
549549
if (!myRecord.empty())
550550
{
551551
mySrsId=myRecord["srs_id"].toLong();
@@ -945,7 +945,7 @@ long QgsSpatialRefSys::findMatchingProj()
945945
QString myProj4String = (char *)sqlite3_column_text(myPreparedStatement, 1);
946946
if (this->equals(myProj4String))
947947
{
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;
949949
// close the sqlite3 statement
950950
sqlite3_finalize(myPreparedStatement);
951951
sqlite3_close(myDatabase);
@@ -957,12 +957,55 @@ long QgsSpatialRefSys::findMatchingProj()
957957
}
958958
}
959959
}
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+
9611004
// close the sqlite3 statement
9621005
sqlite3_finalize(myPreparedStatement);
9631006
sqlite3_close(myDatabase);
9641007
return 0;
965-
//XXX TODO Add on users db search here!
1008+
9661009
}
9671010

9681011
bool QgsSpatialRefSys::operator==(const QgsSpatialRefSys &theSrs)

0 commit comments

Comments
 (0)
Please sign in to comment.