Added logic to detect if a srsid is a user defined or system defined one.

git-svn-id: http://svn.osgeo.org/qgis/trunk@3291 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
timlinux 2005-05-02 10:24:10 +00:00
parent d99ecbe283
commit 8abeec8884
3 changed files with 44 additions and 28 deletions

View File

@ -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();
}

View File

@ -7,6 +7,8 @@
#include <qsettings.h>
#include <qapplication.h>
#include <qregexp.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qgslayerprojectionselector.h>
#include <qgsproject.h>
@ -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

View File

@ -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