QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
|
Class for storing a coordinate reference system (CRS) More...
#include <qgscoordinatereferencesystem.h>
Public Types | |
enum | CrsType { InternalCrsId, PostgisCrsId, EpsgCrsId } |
Public Member Functions | |
QgsCoordinateReferenceSystem () | |
QgsCoordinateReferenceSystem (const QString &theDefinition) | |
QgsCoordinateReferenceSystem (const long theId, CrsType theType=PostgisCrsId) | |
Use this constructor when you want to create a CRS object using a postgis SRID, an EpsgCrsId id or a QGIS CRS_ID. More... | |
QgsCoordinateReferenceSystem (const QgsCoordinateReferenceSystem &srs) | |
Copy constructor. More... | |
~QgsCoordinateReferenceSystem () | |
QString | authid () const |
Returns the authority identifier for the CRS, which includes both the authority (eg EPSG) and the CRS number (eg 4326). More... | |
bool | axisInverted () const |
Returns whether axis is inverted (eg. More... | |
bool | createFromId (const long theId, CrsType theType=PostgisCrsId) |
bool | createFromOgcWmsCrs (const QString &theCrs) |
Sets this CRS to the given OGC WMS-format Coordinate Reference Systems. More... | |
bool | createFromProj4 (const QString &theProjString) |
Set up this CRS by passing it a proj4 style formatted string. More... | |
bool | createFromSrid (const long theSrid) |
Set up this CRS by fetching the appropriate information from the sqlite backend. More... | |
bool | createFromSrsId (const long theSrsId) |
Set up this CRS by fetching the appropriate information from the sqlite backend. More... | |
bool | createFromString (const QString &theDefinition) |
Set up this CRS from a string definition, by default a WKT definition. More... | |
bool | createFromUserInput (const QString &theDefinition) |
Set up this CRS from a various text formats. More... | |
bool | createFromWkt (const QString &theWkt) |
Set up this CRS using a WKT spatial ref sys 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 () |
This is a globbing function to try to find a record in the database that matches a CRS defined only by a proj4string. More... | |
QString | geographicCRSAuthId () const |
Returns auth id of related geographic CRS. More... | |
bool | geographicFlag () const |
Returns whether the CRS is a geographic CRS. More... | |
bool | isValid () const |
Returns whether this CRS is correctly initialized and usable. More... | |
QGis::UnitType | 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... | |
QgsCoordinateReferenceSystem & | operator= (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 SrsId, 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 | customSrsValidation () |
Gets custom function. More... | |
static QStringList | recentProjections () |
Returns a list of recently used projections. More... | |
static void | setCustomSrsValidation (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... | |
Class for storing a coordinate reference system (CRS)
Definition at line 52 of file qgscoordinatereferencesystem.h.
Enumerator | |
---|---|
InternalCrsId | |
PostgisCrsId | |
EpsgCrsId |
Definition at line 56 of file qgscoordinatereferencesystem.h.
QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem | ( | ) |
Definition at line 53 of file qgscoordinatereferencesystem.cpp.
QgsCoordinateReferenceSystem::~QgsCoordinateReferenceSystem | ( | ) |
Definition at line 81 of file qgscoordinatereferencesystem.cpp.
|
explicit |
Constructs a CRS object from a string definition as defined in the createFromString member function (by default a WKT definition).
theDefinition | A String containing a coordinate reference system definition. |
Definition at line 58 of file qgscoordinatereferencesystem.cpp.
QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem | ( | const long | theId, |
CrsType | theType = PostgisCrsId |
||
) |
Use this constructor when you want to create a CRS object using a postgis SRID, an EpsgCrsId id or a QGIS CRS_ID.
theId | The ID no valid for the chosen coordinate system id type |
theType | One of the types described in QgsCoordinateReferenceSystem::CrsType |
Definition at line 64 of file qgscoordinatereferencesystem.cpp.
QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem | ( | const QgsCoordinateReferenceSystem & | srs | ) |
Copy constructor.
Definition at line 70 of file qgscoordinatereferencesystem.cpp.
QString QgsCoordinateReferenceSystem::authid | ( | ) | const |
Returns the authority identifier for the CRS, which 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".
Definition at line 805 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::axisInverted | ( | ) | const |
Returns whether axis is inverted (eg.
for WMS 1.3) for the CRS.
Definition at line 371 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::createFromId | ( | const long | theId, |
CrsType | theType = PostgisCrsId |
||
) |
Definition at line 85 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs | ( | const QString & | theCrs | ) |
Sets this CRS to the given OGC WMS-format Coordinate Reference Systems.
Definition at line 200 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::createFromProj4 | ( | const QString & | theProjString | ) |
Set up this CRS 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 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.bs sqlite database. Also having the ellipse and proj elements stripped out is helpful to speed up globbing queries (see below).
We try to match the proj string to and srsid using the following logic:
theProjString | A proj4 format string |
Definition at line 481 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::createFromSrid | ( | const long | theSrid | ) |
Set up this CRS by fetching the appropriate information from the sqlite backend.
First the system level read only srs.db will be checked and then the users ~/.qgis/qgis.db database will be checked for a match.
theSrid | The postgis SRID for the desired spatial reference system. |
Definition at line 273 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::createFromSrsId | ( | const long | theSrsId | ) |
Set up this CRS by fetching the appropriate information from the 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
theSrsId | The QGIS SrsId for the desired spatial reference system. |
Definition at line 278 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::createFromString | ( | const QString & | theDefinition | ) |
Set up this CRS from a string definition, by default a WKT definition.
Otherwise the string defines a authority, followed by a colon, followed by the definition. The authority can be one of "epsg", "postgis", "internal" for integer definitions, and "wkt" or "proj4" for string definitions. The implementation of each authority uses the corresponding createFrom... function.
theDefinition | A String containing a coordinate reference system definition. |
Definition at line 106 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::createFromUserInput | ( | const QString & | theDefinition | ) |
Set up this CRS from a 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 )
theDefinition | A String containing a coordinate reference system definition. |
Definition at line 150 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::createFromWkt | ( | const QString & | theWkt | ) |
Set up this CRS using a WKT spatial ref sys definition.
The WKT will be converted to a proj4 string using OGR helper functions. After this the SRS databases will be searched for matches. First the system level read only srs.db will be checked and then the users ~/.qgis/qgis.db database will be checked for a match.
theWkt | The WKT for the desired spatial reference system. |
Definition at line 398 of file qgscoordinatereferencesystem.cpp.
|
static |
Gets custom function.
Definition at line 1412 of file qgscoordinatereferencesystem.cpp.
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.
Definition at line 810 of file qgscoordinatereferencesystem.cpp.
QString QgsCoordinateReferenceSystem::ellipsoidAcronym | ( | ) | const |
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
Definition at line 834 of file qgscoordinatereferencesystem.cpp.
long QgsCoordinateReferenceSystem::findMatchingProj | ( | ) |
This is a globbing function to try to find a record in the database that matches a CRS defined only by a proj4string.
The goal is to learn what the tbl_srs.srs_id value is for the CRS. Internally the source CRS is converted to an OGR srs object using the proj4string call and then every record in the database that matches projection and ellipsoid will be converted to an OGR srs in turn and compared to the source CRS. There are some gotchas with using ogr isSame() srs comparison, but its more effective than using straight string comparison of proj4params.
Definition at line 1017 of file qgscoordinatereferencesystem.cpp.
QString QgsCoordinateReferenceSystem::geographicCRSAuthId | ( | ) | const |
Returns auth id of related geographic CRS.
Definition at line 2155 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::geographicFlag | ( | ) | const |
Returns whether the CRS is a geographic CRS.
Definition at line 862 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::isValid | ( | ) | const |
Returns whether this CRS is correctly initialized and usable.
Definition at line 476 of file qgscoordinatereferencesystem.cpp.
QGis::UnitType QgsCoordinateReferenceSystem::mapUnits | ( | ) | const |
Returns the units for the projection used by the CRS.
Definition at line 867 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::operator!= | ( | const QgsCoordinateReferenceSystem & | theSrs | ) | const |
Overloaded != operator used to compare to CRS's.
Returns opposite bool value to operator ==
Definition at line 1125 of file qgscoordinatereferencesystem.cpp.
QgsCoordinateReferenceSystem & QgsCoordinateReferenceSystem::operator= | ( | const QgsCoordinateReferenceSystem & | srs | ) |
Assignment operator.
Definition at line 75 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::operator== | ( | const QgsCoordinateReferenceSystem & | theSrs | ) | const |
Overloaded == operator used to compare to CRS's.
Internally it will delegate to the equals method described below
Definition at line 1119 of file qgscoordinatereferencesystem.cpp.
long QgsCoordinateReferenceSystem::postgisSrid | ( | ) | const |
Returns PostGIS SRID for the CRS.
Definition at line 800 of file qgscoordinatereferencesystem.cpp.
QString QgsCoordinateReferenceSystem::projectionAcronym | ( | ) | const |
Returns the projection acronym for the projection used by the CRS.
Definition at line 822 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::readXML | ( | const QDomNode & | theNode | ) |
Restores state from the given Dom node.
theNode | The node from which state will be restored |
Definition at line 1144 of file qgscoordinatereferencesystem.cpp.
|
static |
Returns a list of recently used projections.
Definition at line 2171 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::saveAsUserCRS | ( | const QString & | name | ) |
Save the proj4-string as a custom CRS.
Copied from QgsCustomProjectionDialog /// Please refactor into SQL handler !!! ///.
Definition at line 1453 of file qgscoordinatereferencesystem.cpp.
|
static |
Sets custom function to force valid CRS QGIS uses implementation in QgisGui::customSrsValidation.
Definition at line 1407 of file qgscoordinatereferencesystem.cpp.
|
static |
Make sure that ESRI WKT import is done properly.
This is required for proper shapefile CRS import when using gdal>= 1.9.
Definition at line 177 of file qgscoordinatereferencesystem.cpp.
void QgsCoordinateReferenceSystem::setValidationHint | ( | const QString & | html | ) |
Set user hint for validation.
Definition at line 1439 of file qgscoordinatereferencesystem.cpp.
long QgsCoordinateReferenceSystem::srsid | ( | ) | const |
Returns the SrsId, if available.
Definition at line 795 of file qgscoordinatereferencesystem.cpp.
|
static |
Update proj.4 parameters in our database from proj.4.
Definition at line 1694 of file qgscoordinatereferencesystem.cpp.
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.
Definition at line 846 of file qgscoordinatereferencesystem.cpp.
QString QgsCoordinateReferenceSystem::toWkt | ( | ) | const |
Returns a WKT representation of this CRS.
Definition at line 1130 of file qgscoordinatereferencesystem.cpp.
void QgsCoordinateReferenceSystem::validate | ( | ) |
Perform some validation on this CRS.
If the sts 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.
Definition at line 256 of file qgscoordinatereferencesystem.cpp.
QString QgsCoordinateReferenceSystem::validationHint | ( | ) |
Get user hint for validation.
Definition at line 1445 of file qgscoordinatereferencesystem.cpp.
bool QgsCoordinateReferenceSystem::writeXML | ( | QDomNode & | theNode, |
QDomDocument & | theDoc | ||
) | const |
Stores state to the given Dom node in the given document.
Below is an example of the generated tag.
theNode | The node in which state will be restored |
theDoc | The document in which state will be stored |
Definition at line 1266 of file qgscoordinatereferencesystem.cpp.