diff --git a/src/qgscoordinatetransform.cpp b/src/qgscoordinatetransform.cpp index 3f4929d4a1d..a3f9a702590 100644 --- a/src/qgscoordinatetransform.cpp +++ b/src/qgscoordinatetransform.cpp @@ -107,7 +107,7 @@ void QgsCoordinateTransform::setDestSRSID (long theSRSID) #ifdef QGISDEBUG std::cout << "QgsCoordinateTransform::setDestSRSID slot called" << std::endl; #endif - mDestSRS->createFromSystemSrsId(theSRSID); + mDestSRS->createFromSrsId(theSRSID); initialise(); } diff --git a/src/qgsspatialrefsys.cpp b/src/qgsspatialrefsys.cpp index 159066f5cf9..6b6ac344388 100644 --- a/src/qgsspatialrefsys.cpp +++ b/src/qgsspatialrefsys.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -36,6 +38,9 @@ const long EPSGID = 4326; const int PROJ_PREFIX_LEN = 6; /** The length of teh string "+ellps=" */ const int ELLPS_PREFIX_LEN = 7; +/** Magick number that determins whether a projection srsid is a system (srs.db) + * or user (~/.qgis.qgis.db) defined projection. */ +const int USER_PROJECTION_START_ID=100000; //-------------------------- QgsSpatialRefSys::QgsSpatialRefSys(){} @@ -61,7 +66,7 @@ QgsSpatialRefSys::QgsSpatialRefSys(const long theId, SRS_TYPE theType) switch (theType) { case QGIS_SRSID: - createFromSystemSrsId(theId); + createFromSrsId(theId); break; case POSTGIS_SRID: createFromSrid(theId); @@ -128,14 +133,12 @@ void QgsSpatialRefSys::validate() //it in the ctor of the layer projection selector QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector(); - // XXX TODO: Change project to store selected CS as 'projectSRS' not 'selectedWKT' long myDefaultSRS = QgsProject::instance()->readNumEntry("SpatialRefSys","/selectedSRS",GEOSRS_ID); mySelector->setSelectedSRSID(myDefaultSRS); if(mySelector->exec()) { - //XXX TODO handle user defined projections too - createFromSystemSrsId(mySelector->getCurrentSRSID()); + createFromSrsId(mySelector->getCurrentSRSID()); } else { @@ -183,13 +186,35 @@ void QgsSpatialRefSys::createFromSrid(long theSrid) #ifdef QGISDEBUG std::cout << " QgsSpatialRefSys::createFromSrid" << std::endl; #endif - // Get the package data path and set the full path name to the sqlite3 spatial reference - // database. + + QString myDatabaseFileName; + + // + // Determine if this is a user projection or a system on + // user projection defs all have srs_id >= 100000 + // + if (theSrid >= USER_PROJECTION_START_ID) + { + myDatabaseFileName = QDir::homeDirPath () + "/.qgis/qgis.db"; + QFileInfo myFileInfo; + myFileInfo.setFile(myDatabaseFileName); + if ( !myFileInfo.exists( ) ) + { + isValidFlag==false; + std::cout << " QgsSpatialRefSys::createFromSrid failed : users qgis.db not found" << std::endl; + return; + } + } + else //must be a system projection then + { + // Get the package data path and set the full path name to the sqlite3 spatial reference + // database. #if defined(Q_OS_MACX) || defined(WIN32) - QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis"; + QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis"; #endif - QString myDatabaseFileName = PKGDATAPATH; - myDatabaseFileName += "/resources/srs.db"; + myDatabaseFileName = PKGDATAPATH; + myDatabaseFileName += "/resources/srs.db"; + } sqlite3 *myDatabase; @@ -364,10 +389,10 @@ void QgsSpatialRefSys::createFromEpsg(long theEpsg) } -void QgsSpatialRefSys::createFromSystemSrsId (long theSrsId) +void QgsSpatialRefSys::createFromSrsId (long theSrsId) { #ifdef QGISDEBUG - std::cout << " QgsSpatialRefSys::createFromSystemSrsId" << std::endl; + std::cout << " QgsSpatialRefSys::createFromSrsId" << std::endl; #endif // Get the package data path and set the full path name to the sqlite3 spatial reference // database. @@ -424,7 +449,7 @@ void QgsSpatialRefSys::createFromSystemSrsId (long theSrsId) else { #ifdef QGISDEBUG - std::cout << " QgsSpatialRefSys::createFromSystemSrsId failed : " << mySql << std::endl; + std::cout << " QgsSpatialRefSys::createFromSrsId failed : " << mySql << std::endl; #endif isValidFlag==false; } @@ -433,9 +458,7 @@ void QgsSpatialRefSys::createFromSystemSrsId (long theSrsId) } -void QgsSpatialRefSys::createFromUserSrsId (long theSrsId) -{ -} + bool QgsSpatialRefSys::isValid() const diff --git a/src/qgsspatialrefsys.h b/src/qgsspatialrefsys.h index 94d528fdd82..7bb20f3bd61 100644 --- a/src/qgsspatialrefsys.h +++ b/src/qgsspatialrefsys.h @@ -92,21 +92,14 @@ class QgsSpatialRefSys */ void createFromEpsg(const long theEpsg); /*! Set up this srs by fetching the appropriate information from the - * sqlite backend. Only the system level read only srs.db will be checked + * sqlite backend. If the srsid is < 100000, only the system srs.db + * will be checked. If the srsid > 100000 the srs will be retrieved from + * the ~/.qgis/qgis.db * @note Any members will be overwritten during this process. - * @note only system db is checked because the users srs.db could - * have srsids that overlap with the system db. * @param theSrsId The QGIS SrsId for the desired spatial reference system. */ - void createFromSystemSrsId (const long theSrsId); - /*! Set up this srs by fetching the appropriate information from the - * sqlite backend. Only the users srs.db will be checked - * @note Any members will be overwritten during this process. - * @note only users db is checked because the users srs.db could - * have srsids that overlap with the system db. - * @param theSrsId The QGIS SrsId for the desired spatial reference system. - */ - void createFromUserSrsId (const long theSrsId); + void createFromSrsId (const long theSrsId); + /*! Set up this srs by passing it a proj4 style formatted string. * The string will be parsed and the projection and ellipsoid * members set and the remainder of the proj4 string will be stored