QGIS API Documentation  2.99.0-Master (e077efd)
Public Types | Public Member Functions | Static Public Member Functions | Properties | Friends | List of all members
QgsCoordinateReferenceSystem Class Reference

This class represents a coordinate reference system (CRS). More...

#include <qgscoordinatereferencesystem.h>

Public Types

enum  CrsType { InternalCrsId, PostgisCrsId, EpsgCrsId }
 Enumeration of types of IDs accepted in createFromId() method. More...
 

Public Member Functions

 QgsCoordinateReferenceSystem ()
 Constructs an invalid CRS object. More...
 
 QgsCoordinateReferenceSystem (const QString &theDefinition)
 
 QgsCoordinateReferenceSystem (const long theId, CrsType theType=PostgisCrsId)
 Constructor a CRS object using a postgis SRID, an EPSG code or an internal QGIS CRS ID. More...
 
 QgsCoordinateReferenceSystem (const QgsCoordinateReferenceSystem &srs)
 Copy constructor. More...
 
 ~QgsCoordinateReferenceSystem ()
 
QString authid () const
 Returns the authority identifier for the CRS. More...
 
bool createFromId (const long theId, CrsType theType=PostgisCrsId)
 Sets this CRS by lookup of the given ID in the CRS database. More...
 
bool createFromOgcWmsCrs (const QString &theCrs)
 Sets this CRS to the given OGC WMS-format Coordinate Reference Systems. More...
 
bool createFromProj4 (const QString &theProjString)
 Sets this CRS by passing it a PROJ.4 style formatted string. More...
 
bool createFromSrid (const long theSrid)
 Sets this CRS by lookup of the given PostGIS SRID in the CRS database. More...
 
bool createFromSrsId (const long theSrsId)
 Sets this CRS by lookup of internal QGIS CRS ID in the CRS database. More...
 
bool createFromString (const QString &theDefinition)
 Set up this CRS from a string definition. More...
 
bool createFromUserInput (const QString &theDefinition)
 Set up this CRS from various text formats. More...
 
bool createFromWkt (const QString &theWkt)
 Sets this CRS using a WKT definition. More...
 
QString description () const
 Returns the descriptive name of the CRS, eg "WGS 84" or "GDA 94 / Vicgrid94". More...
 
QString ellipsoidAcronym () const
 Returns the ellipsoid acronym for the ellipsoid used by the CRS. More...
 
long findMatchingProj ()
 Walks the CRS databases (both system and user database) trying to match stored PROJ.4 string to a database entry in order to fill in further pieces of information about CRS. More...
 
QString geographicCrsAuthId () const
 Returns auth id of related geographic CRS. More...
 
bool hasAxisInverted () const
 Returns whether axis is inverted (eg. More...
 
bool isGeographic () const
 Returns whether the CRS is a geographic CRS (using lat/lon coordinates) More...
 
bool isValid () const
 Returns whether this CRS is correctly initialized and usable. More...
 
QgsUnitTypes::DistanceUnit mapUnits () const
 Returns the units for the projection used by the CRS. More...
 
bool operator!= (const QgsCoordinateReferenceSystem &theSrs) const
 Overloaded != operator used to compare to CRS's. More...
 
QgsCoordinateReferenceSystemoperator= (const QgsCoordinateReferenceSystem &srs)
 Assignment operator. More...
 
bool operator== (const QgsCoordinateReferenceSystem &theSrs) const
 Overloaded == operator used to compare to CRS's. More...
 
long postgisSrid () const
 Returns PostGIS SRID for the CRS. More...
 
QString projectionAcronym () const
 Returns the projection acronym for the projection used by the CRS. More...
 
bool readXml (const QDomNode &theNode)
 Restores state from the given DOM node. More...
 
bool saveAsUserCrs (const QString &name)
 Save the proj4-string as a custom CRS. More...
 
void setValidationHint (const QString &html)
 Set user hint for validation. More...
 
long srsid () const
 Returns the internal CRS ID, if available. More...
 
QString toProj4 () const
 Returns a Proj4 string representation of this CRS. More...
 
QString toWkt () const
 Returns a WKT representation of this CRS. More...
 
void validate ()
 Perform some validation on this CRS. More...
 
QString validationHint ()
 Get user hint for validation. More...
 
bool writeXml (QDomNode &theNode, QDomDocument &theDoc) const
 Stores state to the given Dom node in the given document. More...
 

Static Public Member Functions

static CUSTOM_CRS_VALIDATION customCrsValidation ()
 Gets custom function. More...
 
static Q_INVOKABLE QgsCoordinateReferenceSystem fromEpsgId (long epsg)
 Creates a CRS from a given EPSG ID. More...
 
static QgsCoordinateReferenceSystem fromOgcWmsCrs (const QString &ogcCrs)
 Creates a CRS from a given OGC WMS-format Coordinate Reference System string. More...
 
static QgsCoordinateReferenceSystem fromProj4 (const QString &proj4)
 Creates a CRS from a proj4 style formatted string. More...
 
static QgsCoordinateReferenceSystem fromSrsId (long srsId)
 Creates a CRS from a specified QGIS SRS ID. More...
 
static QgsCoordinateReferenceSystem fromWkt (const QString &wkt)
 Creates a CRS from a WKT spatial ref sys definition string. More...
 
static void invalidateCache ()
 Clears the internal cache used to initialise QgsCoordinateReferenceSystem objects. More...
 
static QStringList recentProjections ()
 Returns a list of recently used projections. More...
 
static void setCustomCrsValidation (CUSTOM_CRS_VALIDATION f)
 Sets custom function to force valid CRS QGIS uses implementation in QgisGui::customSrsValidation. More...
 
static void setupESRIWktFix ()
 Make sure that ESRI WKT import is done properly. More...
 
static int syncDb ()
 Update proj.4 parameters in our database from proj.4. More...
 

Properties

QgsUnitTypes::DistanceUnit mapUnits
 

Friends

class TestQgsCoordinateReferenceSystem
 

Detailed Description

This class represents a coordinate reference system (CRS).

Coordinate reference system object defines a specific map projection, as well as transformations between different coordinate reference systems. There are various ways how a CRS can be defined: using well-known text (WKT), PROJ.4 string or combination of authority and code (e.g. EPSG:4326). QGIS comes with its internal database of coordinate reference systems (stored in SQLite) that allows lookups of CRS and seamless conversions between the various definitions.

Most commonly one comes across two types of coordinate systems:

  1. Geographic coordinate systems - based on a geodetic datum, normally with coordinates being latitude/longitude in degrees. The most common one is World Geodetic System 84 (WGS84).
  2. Projected coordinate systems - based on a geodetic datum with coordinates projected to a plane, typically using meters or feet as units. Common projected coordinate systems are Universal Transverse Mercator or Albers Equal Area.

Internally QGIS uses proj4 library for all the math behind coordinate transformations, so in case of any troubles with projections it is best to examine the PROJ.4 representation within the object, as that is the representation that will be ultimately used.

Methods that allow inspection of CRS instances include isValid(), authid(), description(), toWkt(), toProj4(), mapUnits() and others. Creation of CRS instances is further described in Object Construction and Copying section below. Transformations between coordinate reference systems are done using QgsCoordinateTransform class.

For example, the following code will create and inspect "British national grid" CRS:

crs = QgsCoordinateReferenceSystem("EPSG:27700")
if crs.isValid():
print("CRS Description: {}".format(crs.description()))
print("CRS PROJ.4 text: {}".format(crs.toProj4()))
else:
print("Invalid CRS!")

This will produce the following output:

CRS Description: OSGB 1936 / British National Grid
CRS PROJ.4 text: +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 [output trimmed]

CRS Definition Formats

This section gives an overview of various supported CRS definition formats:

  1. Authority and Code. Also referred to as OGC WMS format within QGIS as they have been widely used in OGC standards. These are encoded as <auth>:<code>, for example EPSG:4326 refers to WGS84 system. EPSG is the most commonly used authority that covers a wide range of coordinate systems around the world.

    An extended variant of this format is OGC URN. Syntax of URN for CRS definition is urn:ogc:def:crs:<auth>:[<version>]:<code>. This class can also parse URNs (versions are currently ignored). For example, WGS84 may be encoded as urn:ogc:def:crs:OGC:1.3:CRS84.

    QGIS adds support for "USER" authority that refers to IDs used internally in QGIS. This variant is best avoided or used with caution as the IDs are not permanent and they refer to different CRS on different machines or user profiles.

    See authid() and createFromOgcWmsCrs() methods.

  2. PROJ.4 string. This is a string consisting of a series of key/value pairs in the following format: +param1=value1 +param2=value2 [...]. This is the format natively used by the underlying proj4 library. For example, the definition of WGS84 looks like this:

    +proj=longlat +datum=WGS84 +no_defs
    

    See toProj4() and createFromProj4() methods.

  3. Well-known text (WKT). Defined by Open Geospatial Consortium (OGC), this is another common format to define CRS. For WGS84 the OGC WKT definition is the following:

    GEOGCS["WGS 84",
           DATUM["WGS_1984",
             SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],
             AUTHORITY["EPSG","6326"]],
           PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
           UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],
           AUTHORITY["EPSG","4326"]]
    

    See toWkt() and createFromWkt() methods.

CRS Database and Custom CRS

The database of CRS shipped with QGIS is stored in a SQLite database (see QgsApplication::srsDbFilePath()) and it is based on the data files maintained by GDAL project (a variety of .csv and .wkt files).

Sometimes it happens that users need to use a CRS definition that is not well known or that has been only created with a specific purpose (and thus its definition is not available in our database of CRS). Whenever a new CRS definition is seen, it will be added to the local databse (in user's home directory, see QgsApplication::qgisUserDbFilePath()). QGIS also features a GUI for management of local custom CRS definitions.

There are therefore two databases: one for shipped CRS definitions and one for custom CRS definitions. Custom CRS have internal IDs (accessible with srsid()) greater or equal to USER_CRS_START_ID. The local CRS databases should never be accessed directly with SQLite functions, instead you should use QgsCoordinateReferenceSystem API for CRS lookups and for managements of custom CRS.

Validation

In some cases (most prominently when loading a map layer), QGIS will try to ensure that the given map layer CRS is valid using validate() call. If not, a custom validation function will be called - such function may for example show a GUI for manual CRS selection. The validation function is configured using setCustomCrsValidation(). If validation fails or no validation function is set, the default CRS is assigned (WGS84). QGIS application registers its validation function that will act according to user's settings (either show CRS selector dialog or use project/custom CRS).

Object Construction and Copying

The easiest way of creating CRS instances is to use QgsCoordinateReferenceSystem(const QString&) constructor that automatically recognizes definition format from the given string.

Creation of CRS object involves some queries in a local SQLite database, which may be potentially expensive. Consequently, CRS creation methods use an internal cache to avoid unnecessary database lookups. If the CRS database is modified, then it is necessary to call invalidateCache() to ensure that outdated records are not being returned from the cache.

Since QGIS 2.16 QgsCoordinateReferenceSystem objects are implicitly shared.

Caveats

There are two different flavours of WKT: one is defined by OGC, the other is the standard used by ESRI. They look very similar, but they are not the same. QGIS is able to consume both flavours.

See also
QgsCoordinateTransform

Definition at line 185 of file qgscoordinatereferencesystem.h.

Member Enumeration Documentation

§ CrsType

Enumeration of types of IDs accepted in createFromId() method.

Enumerator
InternalCrsId 

Internal ID used by QGIS in the local SQLite database.

PostgisCrsId 

SRID used in PostGIS.

EpsgCrsId 

EPSG code.

Definition at line 194 of file qgscoordinatereferencesystem.h.

Constructor & Destructor Documentation

§ QgsCoordinateReferenceSystem() [1/4]

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( )

Constructs an invalid CRS object.

Definition at line 65 of file qgscoordinatereferencesystem.cpp.

§ ~QgsCoordinateReferenceSystem()

QgsCoordinateReferenceSystem::~QgsCoordinateReferenceSystem ( )

Definition at line 126 of file qgscoordinatereferencesystem.cpp.

§ QgsCoordinateReferenceSystem() [2/4]

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( const QString &  theDefinition)
explicit

Constructs a CRS object from a string definition using createFromString()

It supports the following formats:

If no prefix is specified, WKT definition is assumed.

Parameters
theDefinitionA String containing a coordinate reference system definition.
See also
createFromString()

Definition at line 70 of file qgscoordinatereferencesystem.cpp.

§ QgsCoordinateReferenceSystem() [3/4]

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( const long  theId,
CrsType  theType = PostgisCrsId 
)

Constructor a CRS object using a postgis SRID, an EPSG code or an internal QGIS CRS ID.

Note
We encourage you to use EPSG code, WKT or Proj4 to describe CRS's in your code wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile.
Parameters
theIdThe ID valid for the chosen CRS ID type
theTypeOne of the types described in CrsType

Definition at line 76 of file qgscoordinatereferencesystem.cpp.

§ QgsCoordinateReferenceSystem() [4/4]

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( const QgsCoordinateReferenceSystem srs)

Copy constructor.

Definition at line 82 of file qgscoordinatereferencesystem.cpp.

Member Function Documentation

§ authid()

QString QgsCoordinateReferenceSystem::authid ( ) const

Returns the authority identifier for the CRS.

The identifier includes both the authority (eg EPSG) and the CRS number (eg 4326). This is the best method to use when showing a very short CRS identifier to a user, eg "EPSG:4326".

If CRS object is a custom CRS (not found in database), the method will return internal QGIS CRS ID with "QGIS" authority, for example "QGIS:100005"

Returns
the authority identifier for this CRS
See also
description()

Definition at line 960 of file qgscoordinatereferencesystem.cpp.

§ createFromId()

bool QgsCoordinateReferenceSystem::createFromId ( const long  theId,
CrsType  theType = PostgisCrsId 
)

Sets this CRS by lookup of the given ID in the CRS database.

Note
We encourage you to use EPSG code, WKT or Proj4 to describe CRS's in your code wherever possible. Internal QGIS CRS IDs are not guaranteed to be permanent / involatile.
Returns
True on success else false

Definition at line 130 of file qgscoordinatereferencesystem.cpp.

§ createFromOgcWmsCrs()

bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs ( const QString &  theCrs)

Sets this CRS to the given OGC WMS-format Coordinate Reference Systems.

Accepts both "<auth>:<code>" format and OGC URN "urn:ogc:def:crs:<auth>:[<version>]:<code>". It also recognizes "QGIS", "USER", "CUSTOM" authorities, which all have the same meaning and refer to QGIS internal CRS IDs.

Note
this method uses an internal cache. Call invalidateCache() to clear the cache.
Returns
True on success else false
See also
fromOgcWmsCrs()

Definition at line 260 of file qgscoordinatereferencesystem.cpp.

§ createFromProj4()

bool QgsCoordinateReferenceSystem::createFromProj4 ( const QString &  theProjString)

Sets this CRS by passing it a PROJ.4 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 in the parameters member. The reason for this is so that we can easily present the user with 'natural language' representation of the projection and ellipsoid by looking them up in the srs.db sqlite database.

We try to match the proj4 string to internal QGIS CRS ID using the following logic:

  • perform a whole text search on proj4 string (if not null)
  • if not match is found, split proj4 into individual parameters and try to find a match where the parameters are in a different order
  • if none of the above match, use findMatchingProj()
Note
Some members may be left blank if no match can be found in CRS database.
this method uses an internal cache. Call invalidateCache() to clear the cache.
Parameters
theProjStringA proj4 format string
Returns
True on success else false
See also
fromProj4()

Definition at line 624 of file qgscoordinatereferencesystem.cpp.

§ createFromSrid()

bool QgsCoordinateReferenceSystem::createFromSrid ( const long  theSrid)

Sets this CRS by lookup of the given PostGIS SRID in the CRS database.

Parameters
theSridThe postgis SRID for the desired spatial reference system.
Returns
True on success else false

Definition at line 359 of file qgscoordinatereferencesystem.cpp.

§ createFromSrsId()

bool QgsCoordinateReferenceSystem::createFromSrsId ( const long  theSrsId)

Sets this CRS by lookup of internal QGIS CRS ID in the CRS database.

If the srsid is < USER_CRS_START_ID, system CRS database is used, otherwise user's local CRS database from home directory is used.

Note
this method uses an internal cache. Call invalidateCache() to clear the cache.
Parameters
theSrsIdThe internal QGIS CRS ID for the desired spatial reference system.
Returns
True on success else false
See also
fromSrsId()

Definition at line 381 of file qgscoordinatereferencesystem.cpp.

§ createFromString()

bool QgsCoordinateReferenceSystem::createFromString ( const QString &  theDefinition)

Set up this CRS from a string definition.

It supports the following formats:

If no prefix is specified, WKT definition is assumed.

Parameters
theDefinitionA String containing a coordinate reference system definition.
Returns
True on success else false

Definition at line 151 of file qgscoordinatereferencesystem.cpp.

§ createFromUserInput()

bool QgsCoordinateReferenceSystem::createFromUserInput ( const QString &  theDefinition)

Set up this CRS from various text formats.

Valid formats: WKT string, "EPSG:n", "EPSGA:n", "AUTO:proj_id,unit_id,lon0,lat0", "urn:ogc:def:crs:EPSG::n", PROJ.4 string, filename (with WKT, XML or PROJ.4 string), well known name (such as NAD27, NAD83, WGS84 or WGS72), ESRI::[WKT string] (directly or in a file), "IGNF:xxx"

For more details on supported formats see OGRSpatialReference::SetFromUserInput() ( http://www.gdal.org/ogr/classOGRSpatialReference.html#aec3c6a49533fe457ddc763d699ff8796 )

Note
this function generates a WKT string using OSRSetFromUserInput() and passes it to createFromWkt() function.
Parameters
theDefinitionA String containing a coordinate reference system definition.
Returns
True on success else false

Definition at line 210 of file qgscoordinatereferencesystem.cpp.

§ createFromWkt()

bool QgsCoordinateReferenceSystem::createFromWkt ( const QString &  theWkt)

Sets this CRS using a WKT definition.

If EPSG code of the WKT definition can be determined, it is extracted and createFromOgcWmsCrs() is used to initialize the object. Otherwise the WKT will be converted to a proj4 string and createFromProj4() set up the object.

Note
Some members may be left blank if no match can be found in CRS database.
this method uses an internal cache. Call invalidateCache() to clear the cache.
Parameters
theWktThe WKT for the desired spatial reference system.
Returns
True on success else false
See also
fromWkt()

Definition at line 518 of file qgscoordinatereferencesystem.cpp.

§ customCrsValidation()

CUSTOM_CRS_VALIDATION QgsCoordinateReferenceSystem::customCrsValidation ( )
static

Gets custom function.

Note
not available in python bindings

Definition at line 1557 of file qgscoordinatereferencesystem.cpp.

§ description()

QString QgsCoordinateReferenceSystem::description ( ) const

Returns the descriptive name of the CRS, eg "WGS 84" or "GDA 94 / Vicgrid94".

In most cases this is the best method to use when showing a friendly identifier for the CRS to a user.

Returns
descriptive name of the CRS
Note
an empty string will be returned if the description is not available for the CRS
See also
authid()

Definition at line 965 of file qgscoordinatereferencesystem.cpp.

§ ellipsoidAcronym()

QString QgsCoordinateReferenceSystem::ellipsoidAcronym ( ) const

Returns the ellipsoid acronym for the ellipsoid used by the CRS.

Returns
the official proj4 acronym for the ellipoid
Note
an empty string will be returned if the ellipsoidAcronym is not available for the CRS
See also
projectionAcronym()

Definition at line 989 of file qgscoordinatereferencesystem.cpp.

§ findMatchingProj()

long QgsCoordinateReferenceSystem::findMatchingProj ( )

Walks the CRS databases (both system and user database) trying to match stored PROJ.4 string to a database entry in order to fill in further pieces of information about CRS.

Note
The ellipsoid and projection acronyms must be set as well as the proj4string!
Returns
long the SrsId of the matched CRS, zero if no match was found

Definition at line 1162 of file qgscoordinatereferencesystem.cpp.

§ fromEpsgId()

QgsCoordinateReferenceSystem QgsCoordinateReferenceSystem::fromEpsgId ( long  epsg)
static

Creates a CRS from a given EPSG ID.

Parameters
epsgepsg CRS ID
Returns
matching CRS, or an invalid CRS if string could not be matched
Note
added in QGIS 3.0

Definition at line 100 of file qgscoordinatereferencesystem.cpp.

§ fromOgcWmsCrs()

QgsCoordinateReferenceSystem QgsCoordinateReferenceSystem::fromOgcWmsCrs ( const QString &  ogcCrs)
static

Creates a CRS from a given OGC WMS-format Coordinate Reference System string.

Parameters
ogcCrsOGR compliant CRS definition, eg "EPSG:4326"
Returns
matching CRS, or an invalid CRS if string could not be matched
Note
added in QGIS 3.0
See also
createFromOgcWmsCrs()

Definition at line 93 of file qgscoordinatereferencesystem.cpp.

§ fromProj4()

QgsCoordinateReferenceSystem QgsCoordinateReferenceSystem::fromProj4 ( const QString &  proj4)
static

Creates a CRS from a proj4 style formatted string.

Parameters
proj4proj4 format string
Returns
matching CRS, or an invalid CRS if string could not be matched
Note
added in QGIS 3.0
See also
createFromProj4()

Definition at line 105 of file qgscoordinatereferencesystem.cpp.

§ fromSrsId()

QgsCoordinateReferenceSystem QgsCoordinateReferenceSystem::fromSrsId ( long  srsId)
static

Creates a CRS from a specified QGIS SRS ID.

Parameters
srsIdinternal QGIS SRS ID
Returns
matching CRS, or an invalid CRS if ID could not be found
Note
added in QGIS 3.0
See also
createFromSrsId()

Definition at line 119 of file qgscoordinatereferencesystem.cpp.

§ fromWkt()

QgsCoordinateReferenceSystem QgsCoordinateReferenceSystem::fromWkt ( const QString &  wkt)
static

Creates a CRS from a WKT spatial ref sys definition string.

Parameters
wktWKT for the desired spatial reference system.
Returns
matching CRS, or an invalid CRS if string could not be matched
Note
added in QGIS 3.0
See also
createFromWkt()

Definition at line 112 of file qgscoordinatereferencesystem.cpp.

§ geographicCrsAuthId()

QString QgsCoordinateReferenceSystem::geographicCrsAuthId ( ) const

Returns auth id of related geographic CRS.

Definition at line 2295 of file qgscoordinatereferencesystem.cpp.

§ hasAxisInverted()

bool QgsCoordinateReferenceSystem::hasAxisInverted ( ) const

Returns whether axis is inverted (eg.

for WMS 1.3) for the CRS.

Returns
true if CRS axis is inverted

Definition at line 491 of file qgscoordinatereferencesystem.cpp.

§ invalidateCache()

void QgsCoordinateReferenceSystem::invalidateCache ( )
static

Clears the internal cache used to initialise QgsCoordinateReferenceSystem objects.

This should be called whenever the srs database has been modified in order to ensure that outdated CRS objects are not created.

Note
added in QGIS 3.0

Definition at line 2353 of file qgscoordinatereferencesystem.cpp.

§ isGeographic()

bool QgsCoordinateReferenceSystem::isGeographic ( ) const

Returns whether the CRS is a geographic CRS (using lat/lon coordinates)

Returns
true if CRS is geographic, or false if it is a projected CRS

Definition at line 1017 of file qgscoordinatereferencesystem.cpp.

§ isValid()

bool QgsCoordinateReferenceSystem::isValid ( ) const

Returns whether this CRS is correctly initialized and usable.

Definition at line 619 of file qgscoordinatereferencesystem.cpp.

§ mapUnits()

QgsUnitTypes::DistanceUnit QgsCoordinateReferenceSystem::mapUnits ( ) const

Returns the units for the projection used by the CRS.

§ operator!=()

bool QgsCoordinateReferenceSystem::operator!= ( const QgsCoordinateReferenceSystem theSrs) const

Overloaded != operator used to compare to CRS's.

Returns opposite bool value to operator ==

Definition at line 1270 of file qgscoordinatereferencesystem.cpp.

§ operator=()

QgsCoordinateReferenceSystem & QgsCoordinateReferenceSystem::operator= ( const QgsCoordinateReferenceSystem srs)

Assignment operator.

Definition at line 87 of file qgscoordinatereferencesystem.cpp.

§ operator==()

bool QgsCoordinateReferenceSystem::operator== ( const QgsCoordinateReferenceSystem theSrs) const

Overloaded == operator used to compare to CRS's.

Internally it will use authid() for comparison.

Definition at line 1264 of file qgscoordinatereferencesystem.cpp.

§ postgisSrid()

long QgsCoordinateReferenceSystem::postgisSrid ( ) const

Returns PostGIS SRID for the CRS.

Returns
the PostGIS spatial_ref_sys identifier for this CRS (defaults to 0)

Definition at line 955 of file qgscoordinatereferencesystem.cpp.

§ projectionAcronym()

QString QgsCoordinateReferenceSystem::projectionAcronym ( ) const

Returns the projection acronym for the projection used by the CRS.

Returns
the official proj4 acronym for the projection family
Note
an empty string will be returned if the projectionAcronym is not available for the CRS
See also
ellipsoidAcronym()

Definition at line 977 of file qgscoordinatereferencesystem.cpp.

§ readXml()

bool QgsCoordinateReferenceSystem::readXml ( const QDomNode &  theNode)

Restores state from the given DOM node.

Parameters
theNodeThe node from which state will be restored
Returns
bool True on success, False on failure

Definition at line 1289 of file qgscoordinatereferencesystem.cpp.

§ recentProjections()

QStringList QgsCoordinateReferenceSystem::recentProjections ( )
static

Returns a list of recently used projections.

Returns
list of srsid for recently used projections
Note
added in QGIS 2.7

Definition at line 2311 of file qgscoordinatereferencesystem.cpp.

§ saveAsUserCrs()

bool QgsCoordinateReferenceSystem::saveAsUserCrs ( const QString &  name)

Save the proj4-string as a custom CRS.

Copied from QgsCustomProjectionDialog /// Please refactor into SQL handler !!! ///.

Returns
bool true if success else false

Definition at line 1598 of file qgscoordinatereferencesystem.cpp.

§ setCustomCrsValidation()

void QgsCoordinateReferenceSystem::setCustomCrsValidation ( CUSTOM_CRS_VALIDATION  f)
static

Sets custom function to force valid CRS QGIS uses implementation in QgisGui::customSrsValidation.

Note
not available in python bindings

Definition at line 1552 of file qgscoordinatereferencesystem.cpp.

§ setupESRIWktFix()

void QgsCoordinateReferenceSystem::setupESRIWktFix ( )
static

Make sure that ESRI WKT import is done properly.

This is required for proper shapefile CRS import when using gdal>= 1.9.

Note
This function is called by createFromUserInput() and QgsOgrProvider::crs(), there is usually no need to call it from elsewhere.
This function sets CPL config option GDAL_FIX_ESRI_WKT to a proper value, unless it has been set by the user through the commandline or an environment variable. For more details refer to OGRSpatialReference::morphFromESRI() .

Definition at line 237 of file qgscoordinatereferencesystem.cpp.

§ setValidationHint()

void QgsCoordinateReferenceSystem::setValidationHint ( const QString &  html)

Set user hint for validation.

Definition at line 1584 of file qgscoordinatereferencesystem.cpp.

§ srsid()

long QgsCoordinateReferenceSystem::srsid ( ) const

Returns the internal CRS ID, if available.

Returns
the internal sqlite3 srs.db primary key for this CRS

Definition at line 950 of file qgscoordinatereferencesystem.cpp.

§ syncDb()

int QgsCoordinateReferenceSystem::syncDb ( )
static

Update proj.4 parameters in our database from proj.4.

Returns
number of updated CRS on success and negative number of failed updates in case of errors.
Note
This is used internally and should not be necessary to call in client code

Definition at line 1839 of file qgscoordinatereferencesystem.cpp.

§ toProj4()

QString QgsCoordinateReferenceSystem::toProj4 ( ) const

Returns a Proj4 string representation of this CRS.

If proj and ellps keys are found in the parameters, they will be stripped out and the projection and ellipsoid acronyms will be overridden with these.

Returns
Proj4 format string that defines this CRS.
Note
an empty string will be returned if the CRS could not be represented by a Proj4 string
See also
toWkt()

Definition at line 1001 of file qgscoordinatereferencesystem.cpp.

§ toWkt()

QString QgsCoordinateReferenceSystem::toWkt ( ) const

Returns a WKT representation of this CRS.

Returns
string containing WKT of the CRS
See also
toProj4()

Definition at line 1275 of file qgscoordinatereferencesystem.cpp.

§ validate()

void QgsCoordinateReferenceSystem::validate ( )

Perform some validation on this CRS.

If the CRS doesn't validate the default behaviour settings for layers with unknown CRS will be consulted and acted on accordingly. By hell or high water this method will do its best to make sure that this CRS is valid - even if that involves resorting to a hard coded default of geocs:wgs84.

Note
It is not usually necessary to use this function, unless you are trying to force this CRS to be valid.
See also
setCustomCrsValidation(), customCrsValidation()

Definition at line 342 of file qgscoordinatereferencesystem.cpp.

§ validationHint()

QString QgsCoordinateReferenceSystem::validationHint ( )

Get user hint for validation.

Definition at line 1590 of file qgscoordinatereferencesystem.cpp.

§ writeXml()

bool QgsCoordinateReferenceSystem::writeXml ( QDomNode &  theNode,
QDomDocument &  theDoc 
) const

Stores state to the given Dom node in the given document.

Parameters
theNodeThe node in which state will be restored
theDocThe document in which state will be stored
Returns
bool True on success, False on failure

Definition at line 1411 of file qgscoordinatereferencesystem.cpp.

Friends And Related Function Documentation

§ TestQgsCoordinateReferenceSystem

friend class TestQgsCoordinateReferenceSystem
friend

Definition at line 702 of file qgscoordinatereferencesystem.h.

Property Documentation

§ mapUnits

QgsUnitTypes::DistanceUnit QgsCoordinateReferenceSystem::mapUnits
read

Definition at line 189 of file qgscoordinatereferencesystem.h.


The documentation for this class was generated from the following files: