19#include "moc_qgscoordinatereferencesystemregistry.cpp" 
   48  QList<QgsCoordinateReferenceSystemRegistry::UserCrsDetails> res;
 
   54  if ( result != SQLITE_OK )
 
   60  const QString sql = QStringLiteral( 
"select srs_id,description,parameters, wkt from tbl_srs" );
 
   61  QgsDebugMsgLevel( QStringLiteral( 
"Query to populate existing list:%1" ).arg( sql ), 4 );
 
   63  if ( result == SQLITE_OK )
 
   66    while ( preparedStatement.
step() == SQLITE_ROW )
 
   74      if ( !details.
wkt.isEmpty() )
 
 
   95  QString proj4String = 
crs.d->mProj4;
 
   96  if ( proj4String.isEmpty() )
 
  110  if ( QgsCoordinateReferenceSystem::getRecordCount() == 0 )
 
  112    mySql = 
"insert into tbl_srs (srs_id,description,projection_acronym,ellipsoid_acronym,parameters,is_geo,wkt) values (" 
  116            + 
',' + quotedEllipsoidString
 
  124    mySql = 
"insert into tbl_srs (description,projection_acronym,ellipsoid_acronym,parameters,is_geo,wkt) values (" 
  127            + 
',' + quotedEllipsoidString
 
  137  if ( myResult != SQLITE_OK )
 
  139    QgsDebugError( QStringLiteral( 
"Can't open or create database %1: %2" )
 
  144  statement = database.
prepare( mySql, myResult );
 
  146  qint64 returnId = -1;
 
  147  if ( myResult == SQLITE_OK && statement.
step() == SQLITE_DONE )
 
  151    returnId = sqlite3_last_insert_rowid( database.get() );
 
  152    crs.d->mSrsId = returnId;
 
  153    crs.d->mAuthId = QStringLiteral( 
"USER:%1" ).arg( returnId );
 
  154    crs.d->mDescription = name;
 
  157  if ( returnId != -1 )
 
  168  if ( returnId != -1 )
 
 
  185  const QString sql = 
"update tbl_srs set description=" 
  198  if ( myResult != SQLITE_OK )
 
  200    QgsDebugError( QStringLiteral( 
"Can't open or create database %1: %2" )
 
  207  QString errorMessage;
 
  208  if ( database.
exec( sql, errorMessage ) != SQLITE_OK )
 
  215    const int changed = sqlite3_changes( database.get() );
 
 
  255  if ( result != SQLITE_OK )
 
  257    QgsDebugError( QStringLiteral( 
"Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg( database.
errorMessage(),
 
  265    if ( result != SQLITE_OK || preparedStatement.
step() != SQLITE_DONE )
 
  267      QgsDebugError( QStringLiteral( 
"failed to remove custom CRS from database: %1 [%2]" ).arg( sql, database.
errorMessage() ) );
 
  272      const int changed = sqlite3_changes( database.get() );
 
  279        QgsMessageLog::logMessage( QObject::tr( 
"Error removing user CRS [%1]: No matching ID found in database" ).arg( 
id ), QObject::tr( 
"CRS" ) );
 
 
  298bool QgsCoordinateReferenceSystemRegistry::insertProjection( 
const QString &projectionAcronym )
 
  305  if ( result != SQLITE_OK )
 
  307    QgsDebugError( QStringLiteral( 
"Can't open database: %1 \n please notify  QGIS developers of this error \n %2 (file name) " ).arg( database.
errorMessage(),
 
  312  if ( result != SQLITE_OK )
 
  320  const QString srsSql = 
"select acronym,name,notes,parameters from tbl_projection where acronym=" + 
QgsSqliteUtils::quotedString( projectionAcronym );
 
  323  if ( srsResult == SQLITE_OK )
 
  325    if ( srsPreparedStatement.
step() == SQLITE_ROW )
 
  329      sql = 
"insert into tbl_projection(acronym,name,notes,parameters) values (" 
  336      if ( result != SQLITE_OK || preparedStatement.
step() != SQLITE_DONE )
 
  338        QgsDebugError( QStringLiteral( 
"Could not insert projection into database: %1 [%2]" ).arg( sql, database.
errorMessage() ) );
 
  354  static std::once_flag initialized;
 
  355  static QMap< QString, QgsProjOperation > sProjOperations;
 
  356  std::call_once( initialized, []
 
  360    const PJ_OPERATIONS *operation = proj_list_operations();
 
  361    while ( operation && operation->id )
 
  365      value.mId = QString( operation->id );
 
  367      const QString description( *operation->descr );
 
  368      const QStringList descriptionParts = description.split( QStringLiteral( 
"\n\t" ) );
 
  369      value.mDescription = descriptionParts.value( 0 );
 
  370      value.mDetails = descriptionParts.mid( 1 ).join( 
'\n' );
 
  372      sProjOperations.insert( value.
id(), value );
 
  378  return sProjOperations;
 
 
  383  static QList< QgsCelestialBody > sCelestialBodies;
 
  384  static std::once_flag initialized;
 
  385  std::call_once( initialized, []
 
  392    PROJ_CELESTIAL_BODY_INFO **list = proj_get_celestial_body_list_from_database( context, 
nullptr, &resultCount );
 
  393    sCelestialBodies.reserve( resultCount );
 
  394    for ( 
int i = 0; i < resultCount; i++ )
 
  396      const PROJ_CELESTIAL_BODY_INFO *info = list[ i ];
 
  402      body.mAuthority = QString( info->auth_name );
 
  403      body.mName = QString( info->name );
 
  405      sCelestialBodies << body;
 
  407    proj_celestial_body_list_destroy( list );
 
  410  return sCelestialBodies;
 
 
  415  static QSet< QString > sKnownAuthorities;
 
  416  static std::once_flag initialized;
 
  417  std::call_once( initialized, []
 
  422    PROJ_STRING_LIST 
authorities = proj_get_authorities_from_database( pjContext );
 
  424    for ( 
auto authIter = 
authorities; authIter && *authIter; ++authIter )
 
  426      const QString authority( *authIter );
 
  427      sKnownAuthorities.insert( authority.toLower() );
 
  433  return sKnownAuthorities;
 
 
  439  if ( mCrsDbRecordsPopulated )
 
  440    return mCrsDbRecords;
 
  445  if ( QFileInfo::exists( srsDatabaseFileName ) )
 
  449    int result = database.
open_v2( srsDatabaseFileName, SQLITE_OPEN_READONLY, 
nullptr );
 
  450    if ( result == SQLITE_OK )
 
  452      const QString sql = QStringLiteral( 
"SELECT description, srs_id, auth_name, auth_id, projection_acronym, deprecated, srs_type FROM tbl_srs" );
 
  454      if ( result == SQLITE_OK )
 
  456        while ( preparedStatement.
step() == SQLITE_ROW )
 
  466          mCrsDbRecords.append( record );
 
  472  mCrsDbRecordsPopulated = 
true;
 
  473  return mCrsDbRecords;
 
 
  478  QList<QgsCoordinateReferenceSystem> res;
 
  482  QStringList projectionsProj4  = settings.
value( QStringLiteral( 
"UI/recentProjectionsProj4" ) ).toStringList();
 
  483  QStringList projectionsWkt = settings.
value( QStringLiteral( 
"UI/recentProjectionsWkt" ) ).toStringList();
 
  484  QStringList projectionsAuthId = settings.
value( QStringLiteral( 
"UI/recentProjectionsAuthId" ) ).toStringList();
 
  485  int max = std::max( projectionsAuthId.size(), std::max( projectionsProj4.size(), projectionsWkt.size() ) );
 
  487  for ( 
int i = 0; i < max; ++i )
 
  489    const QString proj = projectionsProj4.value( i );
 
  490    const QString wkt = projectionsWkt.value( i );
 
  491    const QString authid = projectionsAuthId.value( i );
 
  494    if ( !authid.isEmpty() )
 
 
  510  settings.
remove( QStringLiteral( 
"UI/recentProjectionsAuthId" ) );
 
  511  settings.
remove( QStringLiteral( 
"UI/recentProjectionsWkt" ) );
 
  512  settings.
remove( QStringLiteral( 
"UI/recentProjectionsProj4" ) );
 
 
  523  QList<QgsCoordinateReferenceSystem> recent = 
recentCrs();
 
  524  recent.removeAll( 
crs );
 
  525  recent.insert( 0, 
crs );
 
  550  QList<QgsCoordinateReferenceSystem> recentSameType;
 
  553    return hasVertical( it ) == hasVertical( crs );
 
  557  const QList<QgsCoordinateReferenceSystem> toTrim = recentSameType.mid( 30 );
 
  560    recent.removeOne( crsTrimmed );
 
  565  authids.reserve( recent.size() );
 
  567  proj.reserve( recent.size() );
 
  569  wkt.reserve( recent.size() );
 
  572    authids << 
c.authid();
 
  578  settings.
setValue( QStringLiteral( 
"UI/recentProjectionsAuthId" ), authids );
 
  579  settings.
setValue( QStringLiteral( 
"UI/recentProjectionsWkt" ), wkt );
 
  580  settings.
setValue( QStringLiteral( 
"UI/recentProjectionsProj4" ), proj );
 
 
  590  QList<QgsCoordinateReferenceSystem> recent = 
recentCrs();
 
  591  recent.removeAll( 
crs );
 
  593  authids.reserve( recent.size() );
 
  595  proj.reserve( recent.size() );
 
  597  wkt.reserve( recent.size() );
 
  600    authids << 
c.authid();
 
  605  settings.
setValue( QStringLiteral( 
"UI/recentProjectionsAuthId" ), authids );
 
  606  settings.
setValue( QStringLiteral( 
"UI/recentProjectionsWkt" ), wkt );
 
  607  settings.
setValue( QStringLiteral( 
"UI/recentProjectionsProj4" ), proj );
 
 
@ Compound
Compound (horizontal + vertical) CRS.
 
@ Projected
Projected CRS.
 
@ DerivedProjected
Derived projected CRS.
 
@ Engineering
Engineering CRS.
 
@ Geographic3d
3D geopraphic CRS
 
@ Geographic2d
2D geographic CRS
 
@ Geocentric
Geocentric CRS.
 
CrsDefinitionFormat
CRS definition formats.
 
@ Wkt
WKT format (always recommended over proj string format)
 
static const int USER_CRS_START_ID
Minimum ID number for a user-defined projection.
 
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
 
static QString qgisUserDatabaseFilePath()
Returns the path to the user qgis.db file.
 
static QString srsDatabaseFilePath()
Returns the path to the srs.db file.
 
Contains information about a celestial body.
 
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)
 
QList< QgsCrsDbRecord > crsDbRecords() const
Returns the list of records from the QGIS srs db.
 
void userCrsAdded(const QString &id)
Emitted whenever a new user CRS definition is added.
 
void recentCrsRemoved(const QgsCoordinateReferenceSystem &crs)
Emitted when a recently used CRS has been removed from the recent CRS list.
 
void userCrsChanged(const QString &id)
Emitted whenever an existing user CRS definition is changed.
 
void recentCrsCleared()
Emitted when the list of recently used CRS has been cleared.
 
void recentCrsPushed(const QgsCoordinateReferenceSystem &crs)
Emitted when a recently used CRS has been pushed to the top of the recent CRS list.
 
QList< QgsCelestialBody > celestialBodies() const
Returns a list of all known celestial bodies.
 
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, Qgis::CrsDefinitionFormat nativeFormat=Qgis::CrsDefinitionFormat::Wkt)
Updates the definition of the existing user CRS with matching id.
 
QgsCoordinateReferenceSystemRegistry(QObject *parent=nullptr)
Constructor for QgsCoordinateReferenceSystemRegistry, with the specified parent object.
 
void removeRecent(const QgsCoordinateReferenceSystem &crs)
Removes a CRS from the list of recently used CRS.
 
~QgsCoordinateReferenceSystemRegistry()
 
long addUserCrs(const QgsCoordinateReferenceSystem &crs, const QString &name, Qgis::CrsDefinitionFormat nativeFormat=Qgis::CrsDefinitionFormat::Wkt)
Adds a new crs definition as a custom ("USER") CRS.
 
QSet< QString > authorities() const
Returns a list of all known authorities.
 
bool removeUserCrs(long id)
Removes the existing user CRS with matching id.
 
void clearRecent()
Cleans the list of recently used CRS.
 
QList< QgsCoordinateReferenceSystemRegistry::UserCrsDetails > userCrsList() const
Returns a list containing the details of all registered custom (user-defined) CRSes.
 
QList< QgsCoordinateReferenceSystem > recentCrs()
Returns a list of recently used CRS.
 
void pushRecent(const QgsCoordinateReferenceSystem &crs)
Pushes a recently used CRS to the top of the recent CRS list.
 
QMap< QString, QgsProjOperation > projOperations() const
Returns a map of all valid PROJ operations.
 
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.
 
static void invalidateCache(bool disableCache=false)
Clears the internal cache used to initialize QgsCoordinateReferenceSystem objects.
 
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
 
long srsid() const
Returns the internal CRS ID, if available.
 
Qgis::CrsType type() const
Returns the type of the CRS.
 
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
 
static PJ_CONTEXT * get()
Returns a thread local instance of a proj context, safe for use in the current thread.
 
Contains information about a PROJ operation.
 
QString id() const
ID of operation.
 
A convenience class that simplifies locking and unlocking QReadWriteLocks.
 
void changeMode(Mode mode)
Change the mode of the lock to mode.
 
Scoped object for logging of the runtime for a single operation or group of operations.
 
Stores settings for use within QGIS.
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
 
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
 
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
 
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.
 
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
 
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
 
#define BUILTIN_UNREACHABLE
 
#define QgsDebugMsgLevel(str, level)
 
#define QgsDebugError(str)
 
const QgsCoordinateReferenceSystem & crs
 
QString projectionAcronym