22 QReadWriteLock QgsEllipsoidUtils::sEllipsoidCacheLock;
23 QHash< QString, QgsEllipsoidUtils::EllipsoidParameters > QgsEllipsoidUtils::sEllipsoidCache;
24 QReadWriteLock QgsEllipsoidUtils::sDefinitionCacheLock;
25 QList< QgsEllipsoidUtils::EllipsoidDefinition > QgsEllipsoidUtils::sDefinitionCache;
30 sEllipsoidCacheLock.lockForRead();
31 QHash< QString, EllipsoidParameters >::const_iterator cacheIt = sEllipsoidCache.constFind( ellipsoid );
32 if ( cacheIt != sEllipsoidCache.constEnd() )
36 sEllipsoidCacheLock.unlock();
39 sEllipsoidCacheLock.unlock();
47 if ( ellipsoid.startsWith( QLatin1String(
"PARAMETER" ) ) )
49 QStringList paramList = ellipsoid.split(
':' );
50 bool semiMajorOk, semiMinorOk;
51 double semiMajor = paramList[1].toDouble( & semiMajorOk );
52 double semiMinor = paramList[2].toDouble( & semiMinorOk );
53 if ( semiMajorOk && semiMinorOk )
65 sEllipsoidCacheLock.lockForWrite();
66 sEllipsoidCache.insert( ellipsoid, params );
67 sEllipsoidCacheLock.unlock();
73 QString radius, parameter2;
91 QString sql =
"select radius, parameter2 from tbl_ellipsoid where acronym='" + ellipsoid +
'\'';
92 statement = database.
prepare( sql, result );
94 if ( result == SQLITE_OK )
96 if ( statement.
step() == SQLITE_ROW )
103 if ( radius.isEmpty() || parameter2.isEmpty() )
105 QgsDebugMsg( QString(
"setEllipsoid: no row in tbl_ellipsoid for acronym '%1'" ).arg( ellipsoid ) );
106 params.
valid =
false;
107 sEllipsoidCacheLock.lockForWrite();
108 sEllipsoidCache.insert( ellipsoid, params );
109 sEllipsoidCacheLock.unlock();
114 if ( radius.left( 2 ) == QLatin1String(
"a=" ) )
115 params.
semiMajor = radius.midRef( 2 ).toDouble();
118 QgsDebugMsg( QString(
"setEllipsoid: wrong format of radius field: '%1'" ).arg( radius ) );
119 params.
valid =
false;
120 sEllipsoidCacheLock.lockForWrite();
121 sEllipsoidCache.insert( ellipsoid, params );
122 sEllipsoidCacheLock.unlock();
129 if ( parameter2.left( 2 ) == QLatin1String(
"b=" ) )
131 params.
semiMinor = parameter2.midRef( 2 ).toDouble();
134 else if ( parameter2.left( 3 ) == QLatin1String(
"rf=" ) )
141 QgsDebugMsg( QString(
"setEllipsoid: wrong format of parameter2 field: '%1'" ).arg( parameter2 ) );
142 params.
valid =
false;
143 sEllipsoidCacheLock.lockForWrite();
144 sEllipsoidCache.insert( ellipsoid, params );
145 sEllipsoidCacheLock.unlock();
153 QString proj4 =
"+proj=longlat +ellps=" + ellipsoid +
" +no_defs";
159 if ( destCRS.
srsid() == 0 )
161 QString name = QStringLiteral(
" * %1 (%2)" )
162 .arg( QObject::tr(
"Generated CRS",
"A CRS automatically generated from layer info get this prefix for description" ),
169 params.
crs = destCRS;
171 sEllipsoidCacheLock.lockForWrite();
172 sEllipsoidCache.insert( ellipsoid, params );
173 sEllipsoidCacheLock.unlock();
179 sDefinitionCacheLock.lockForRead();
180 if ( !sDefinitionCache.isEmpty() )
182 QList<QgsEllipsoidUtils::EllipsoidDefinition> defs = sDefinitionCache;
183 sDefinitionCacheLock.unlock();
186 sDefinitionCacheLock.unlock();
188 sDefinitionCacheLock.lockForWrite();
193 QList<QgsEllipsoidUtils::EllipsoidDefinition> defs;
202 Q_ASSERT( result == 0 );
206 QString sql = QStringLiteral(
"select acronym, name from tbl_ellipsoid order by name" );
207 statement = database.
prepare( sql, result );
209 if ( result == SQLITE_OK )
211 while ( statement.
step() == SQLITE_ROW )
224 sDefinitionCache = defs;
225 sDefinitionCacheLock.unlock();
static QgsCoordinateReferenceSystem fromProj4(const QString &proj4)
Creates a CRS from a proj4 style formatted string.
bool useCustomParameters
Whether custom parameters alone should be used (semiMajor/semiMinor only)
Contains definition of an ellipsoid.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
QString toProj4() const
Returns a Proj4 string representation of this CRS.
Contains parameters for an ellipsoid.
static EllipsoidParameters ellipsoidParameters(const QString &ellipsoid)
Returns the parameters for the specified ellipsoid.
long saveAsUserCrs(const QString &name)
Save the proj4-string as a custom CRS.
QgsCoordinateReferenceSystem crs
Associated coordinate reference system.
QString errorMessage() const
Returns the most recent error message encountered by the database.
bool valid
Whether ellipsoid parameters are valid.
#define QgsDebugMsgLevel(str, level)
int step()
Steps to the next record in the statement, returning the sqlite3 result code.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QString columnAsText(int column) const
Returns the column value from the current statement row as a string.
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
QString acronym
Acronym for ellipsoid.
double semiMinor
Semi-minor axis.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
This class represents a coordinate reference system (CRS).
double inverseFlattening
Inverse flattening.
static QString srsDatabaseFilePath()
Returns the path to the srs.db file.
QgsEllipsoidUtils::EllipsoidParameters parameters
Ellipsoid parameters.
static QList< QgsEllipsoidUtils::EllipsoidDefinition > definitions()
Returns a list of the definitions for all known ellipsoids from the internal ellipsoid database...
static QStringList acronyms()
Returns a list of all known ellipsoid acronyms from the internal ellipsoid database.
long srsid() const
Returns the internal CRS ID, if available.
QString description
Description of ellipsoid.
double semiMajor
Semi-major axis.