36 QList<QgsCoordinateReferenceSystemRegistry::UserCrsDetails> res;
42 if ( result != SQLITE_OK )
48 const QString sql = QStringLiteral(
"select srs_id,description,parameters, wkt from tbl_srs" );
49 QgsDebugMsgLevel( QStringLiteral(
"Query to populate existing list:%1" ).arg( sql ), 4 );
51 if ( result == SQLITE_OK )
54 while ( preparedStatement.
step() == SQLITE_ROW )
62 if ( !details.
wkt.isEmpty() )
83 QString proj4String =
crs.d->mProj4;
84 if ( proj4String.isEmpty() )
98 if ( QgsCoordinateReferenceSystem::getRecordCount() == 0 )
100 mySql =
"insert into tbl_srs (srs_id,description,projection_acronym,ellipsoid_acronym,parameters,is_geo,wkt) values ("
104 +
',' + quotedEllipsoidString
112 mySql =
"insert into tbl_srs (description,projection_acronym,ellipsoid_acronym,parameters,is_geo,wkt) values ("
115 +
',' + quotedEllipsoidString
125 if ( myResult != SQLITE_OK )
127 QgsDebugMsg( QStringLiteral(
"Can't open or create database %1: %2" )
132 statement = database.
prepare( mySql, myResult );
134 qint64 returnId = -1;
135 if ( myResult == SQLITE_OK && statement.
step() == SQLITE_DONE )
139 returnId = sqlite3_last_insert_rowid( database.get() );
140 crs.d->mSrsId = returnId;
141 crs.d->mAuthId = QStringLiteral(
"USER:%1" ).arg( returnId );
142 crs.d->mDescription = name;
145 if ( returnId != -1 )
156 if ( returnId != -1 )
173 const QString sql =
"update tbl_srs set description="
186 if ( myResult != SQLITE_OK )
188 QgsDebugMsg( QStringLiteral(
"Can't open or create database %1: %2" )
195 QString errorMessage;
196 if ( database.
exec( sql, errorMessage ) != SQLITE_OK )
203 const int changed = sqlite3_changes( database.get() );
243 if ( result != SQLITE_OK )
245 QgsDebugMsg( QStringLiteral(
"Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg( database.
errorMessage(),
253 if ( result != SQLITE_OK || preparedStatement.
step() != SQLITE_DONE )
255 QgsDebugMsg( QStringLiteral(
"failed to remove custom CRS from database: %1 [%2]" ).arg( sql, database.
errorMessage() ) );
260 const int changed = sqlite3_changes( database.get() );
267 QgsMessageLog::logMessage( QObject::tr(
"Error removing user CRS [%1]: No matching ID found in database" ).arg(
id ), QObject::tr(
"CRS" ) );
285 bool QgsCoordinateReferenceSystemRegistry::insertProjection(
const QString &projectionAcronym )
292 if ( result != SQLITE_OK )
294 QgsDebugMsg( QStringLiteral(
"Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg( database.
errorMessage(),
299 if ( result != SQLITE_OK )
307 QString srsSql =
"select acronym,name,notes,parameters from tbl_projection where acronym=" +
QgsSqliteUtils::quotedString( projectionAcronym );
310 if ( srsResult == SQLITE_OK )
312 if ( srsPreparedStatement.
step() == SQLITE_ROW )
316 sql =
"insert into tbl_projection(acronym,name,notes,parameters) values ("
323 if ( result != SQLITE_OK || preparedStatement.
step() != SQLITE_DONE )
325 QgsDebugMsg( QStringLiteral(
"Could not insert projection into database: %1 [%2]" ).arg( sql, database.
errorMessage() ) );
static QString qgisUserDatabaseFilePath()
Returns the path to the user qgis.db file.
static QString srsDatabaseFilePath()
Returns the path to the srs.db file.
Contains details of a custom (user defined) CRS.
QgsCoordinateReferenceSystem crs
QgsCoordinateReferenceSystem object representing the user-defined CRS.
QString proj
PROJ string definition of CRS.
QString wkt
WKT definition of CRS.
QString name
CRS name (or description)
void userCrsAdded(const QString &id)
Emitted whenever a new user CRS definition is added.
void userCrsChanged(const QString &id)
Emitted whenever an existing user CRS definition is changed.
void userCrsRemoved(long id)
Emitted when the user CRS with matching id is removed from the database.
void crsDefinitionsChanged()
Emitted whenever an operation has caused any of the known CRS definitions (including user-defined CRS...
bool updateUserCrs(long id, const QgsCoordinateReferenceSystem &crs, const QString &name, QgsCoordinateReferenceSystem::Format nativeFormat=QgsCoordinateReferenceSystem::FormatWkt)
Updates the definition of the existing user CRS with matching id.
QgsCoordinateReferenceSystemRegistry(QObject *parent=nullptr)
Constructor for QgsCoordinateReferenceSystemRegistry, with the specified parent object.
bool removeUserCrs(long id)
Removes the existing user CRS with matching id.
QList< QgsCoordinateReferenceSystemRegistry::UserCrsDetails > userCrsList() const
Returns a list containing the details of all registered custom (user-defined) CRSes.
long addUserCrs(const QgsCoordinateReferenceSystem &crs, const QString &name, QgsCoordinateReferenceSystem::Format nativeFormat=QgsCoordinateReferenceSystem::FormatWkt)
Adds a new crs definition as a custom ("USER") CRS.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool createFromWkt(const QString &wkt)
Sets this CRS using a WKT definition.
QString toProj() const
Returns a Proj string representation of this CRS.
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
QString projectionAcronym() const
Returns the projection acronym for the projection used by the CRS.
bool createFromProj(const QString &projString, bool identify=true)
Sets this CRS by passing it a PROJ style formatted string.
Format
Projection definition formats.
@ FormatWkt
WKT format (always recommended over proj string format)
static void invalidateCache(bool disableCache=false)
Clears the internal cache used to initialize QgsCoordinateReferenceSystem objects.
@ WKT_PREFERRED
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
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).
static QString quotedString(const QString &value)
Returns a quoted string value, surround by ' characters and with special characters correctly escaped...
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
int open(const QString &path)
Opens the database at the specified file path.
QString errorMessage() const
Returns the most recent error message encountered by the database.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
int exec(const QString &sql, QString &errorMessage) const
Executes the sql command in the database.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
QString columnAsText(int column) const
Returns the column value from the current statement row as a string.
int step()
Steps to the next record in the statement, returning the sqlite3 result code.
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/....
#define QgsDebugMsgLevel(str, level)
const QgsCoordinateReferenceSystem & crs