QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsCoordinateReferenceSystem Class Reference

Class for storing a coordinate reference system (CRS) More...

#include <qgscoordinatereferencesystem.h>

Public Types

enum  CrsType { InternalCrsId, PostgisCrsId, EpsgCrsId }
 

Public Member Functions

 QgsCoordinateReferenceSystem ()
 Default constructor. More...
 
 QgsCoordinateReferenceSystem (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
 Get the authority identifier for this srs. More...
 
bool axisInverted () const
 Return if axis is inverted (eg. More...
 
bool createFromId (const long theId, CrsType theType=PostgisCrsId)
 
bool createFromOgcWmsCrs (QString theCrs)
 Set up this CRS from the given OGC CRS. More...
 
bool createFromProj4 (const QString &theProjString)
 Set up this srs by passing it a proj4 style formatted string. More...
 
bool createFromSrid (const long theSrid)
 Set up this srs by fetching the appropriate information from the sqlite backend. More...
 
bool createFromSrsId (const long theSrsId)
 Set up this srs by fetching the appropriate information from the sqlite backend. More...
 
bool createFromString (const QString &theDefinition)
 Set up this srs from a string definition, by default a WKT definition. More...
 
bool createFromUserInput (const QString &theDefinition)
 Set up this srs from a various text formats. More...
 
bool createFromWkt (const QString &theWkt)
 Set up this srs using a Wkt spatial ref sys definition. More...
 
QString description () const
 Get the Description. More...
 
QString ellipsoidAcronym () const
 Get the Ellipsoid Acronym. 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
 Get this Geographic? flag. More...
 
bool isValid () const
 Find out whether this CRS is correctly initialised and usable. More...
 
QGis::UnitType mapUnits () const
 Get the units that the projection is in. 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
 Get the postgis srid for this srs. More...
 
QString projectionAcronym () const
 Get the Projection Acronym. More...
 
bool readXML (QDomNode &theNode)
 Restores state from the given Dom node. More...
 
bool saveAsUserCRS (QString name)
 Save the proj4-string as a custom CRS. More...
 
void setValidationHint (QString html)
 Set user hint for validation. More...
 
long srsid () const
 Get the SrsId - if possible. More...
 
QString toProj4 () const
 Get the Proj Proj4 string representation of this srs. More...
 
QString toWkt () const
 A helper to get an wkt representation of this srs. 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...
 

Detailed Description

Class for storing a coordinate reference system (CRS)

Definition at line 50 of file qgscoordinatereferencesystem.h.

Constructor & Destructor Documentation

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( )

Default constructor.

Definition at line 52 of file qgscoordinatereferencesystem.cpp.

QgsCoordinateReferenceSystem::~QgsCoordinateReferenceSystem ( )

Definition at line 91 of file qgscoordinatereferencesystem.cpp.

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( QString  theDefinition)
explicit

Constructs a CRS object from a string definition as defined in the createFromString member function (by default a WKT definition).

Parameters
theDefinitionA String containing a coordinate reference system definition.

Definition at line 64 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.

Note
We encourage you to use EpsgCrsId, Wkt or Proj4 to describe CRS's in your code wherever possible. QGSI CRS_IDs are not guaranteed to be permanent / involatile.
Parameters
theIdThe ID no valid for the chosen coordinate system id type
theTypeOne of the types described in QgsCoordinateReferenceSystem::CrsType

Definition at line 78 of file qgscoordinatereferencesystem.cpp.

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem ( const QgsCoordinateReferenceSystem srs)

copy constructor

Definition at line 258 of file qgscoordinatereferencesystem.cpp.

Member Function Documentation

QString QgsCoordinateReferenceSystem::authid ( ) const

Get the authority identifier for this srs.

Returns
QString the Authority identifier for this srs

Definition at line 834 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::axisInverted ( ) const

Return if axis is inverted (eg.

for WMS 1.3)

Returns
bool Whether this is crs axis is inverted

Definition at line 405 of file qgscoordinatereferencesystem.cpp.

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

Definition at line 96 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs ( QString  theCrs)

Set up this CRS from the given OGC CRS.

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

Return values
falseif not given an valid label

Definition at line 211 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::createFromProj4 ( const QString theProjString)

Set up this srs 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:

  • perform a whole text search on srs name (if not null). The srs name will have been set if this method has been delegated to from createFromWkt.
  • if the above does not match perform a whole text search on proj4 string (if not null)
  • if none of the above match convert the proj4 string to an OGR CRS then check if its a geocs or a proj cs (using ogr isGeographic) then sequentially walk through the database (first users qgis.db srs tbl then system srs.db tbl), converting each entry into an ogr srs and using isSame or isSameGeocs (essentially calling the == overloaded operator). We'll try to be smart about this and first parse out the proj and ellpse strings and only check for a match in entities that have the same ellps and proj entries so that it doesn't munch yer cpu so much.
Parameters
theProjStringA proj4 format string
Returns
bool TRUE if success else false

Definition at line 512 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::createFromSrid ( const long  theSrid)

Set up this srs 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.

Note
Any members will be overwritten during this process.
Parameters
theSridThe postgis SRID for the desired spatial reference system.

Definition at line 309 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::createFromSrsId ( const long  theSrsId)

Set up this srs 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

Note
Any members will be overwritten during this process.
Parameters
theSrsIdThe QGIS SrsId for the desired spatial reference system.
Returns
bool TRUE if success else false

Definition at line 314 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::createFromString ( const QString theDefinition)

Set up this srs 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.

Parameters
theDefinitionA String containing a coordinate reference system definition.

Definition at line 117 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::createFromUserInput ( const QString theDefinition)

Set up this srs 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 )

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

Definition at line 161 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::createFromWkt ( const QString theWkt)

Set up this srs using a Wkt spatial ref sys definition.

The wkt will be converted to a proj4 string using OGR helper functions. After this the srs databasses 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.

Note
Any members will be overwritten during this process.
SRID and EpsgCrsId may be blank if no match can be found on srs db.
Parameters
theWktThe Wkt for the desired spatial reference system.
Returns
bool TRUE if success else false

Definition at line 431 of file qgscoordinatereferencesystem.cpp.

CUSTOM_CRS_VALIDATION QgsCoordinateReferenceSystem::customSrsValidation ( )
static

Gets custom function.

Note
not available in python bindings

Definition at line 1414 of file qgscoordinatereferencesystem.cpp.

QString QgsCoordinateReferenceSystem::description ( ) const

Get the Description.

Returns
QString the Description A textual description of the srs.
Note
A zero length string will be returned if the description is uninitialised

Definition at line 839 of file qgscoordinatereferencesystem.cpp.

QString QgsCoordinateReferenceSystem::ellipsoidAcronym ( ) const

Get the Ellipsoid Acronym.

Returns
QString theEllipsoidAcronym The official proj4 acronym for the ellipoid
Note
A zero length string will be returned if the ellipsoidAcronym is uninitialised

Definition at line 863 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.

Note
The ellipsoid and projection acronyms must be set as well as the proj4string!
Returns
long the SrsId of the matched CRS

Definition at line 1021 of file qgscoordinatereferencesystem.cpp.

QString QgsCoordinateReferenceSystem::geographicCRSAuthId ( ) const

Returns auth id of related geographic CRS.

Definition at line 2146 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::geographicFlag ( ) const

Get this Geographic? flag.

Returns
bool theGeoFlag Whether this is a geographic or projected coordinate system

Definition at line 892 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::isValid ( ) const

Find out whether this CRS is correctly initialised and usable.

Definition at line 507 of file qgscoordinatereferencesystem.cpp.

QGis::UnitType QgsCoordinateReferenceSystem::mapUnits ( ) const

Get the units that the projection is in.

Returns
QGis::UnitType that gives the units for the coordinate system

Definition at line 897 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 1130 of file qgscoordinatereferencesystem.cpp.

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

Assignment operator.

Definition at line 265 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 1124 of file qgscoordinatereferencesystem.cpp.

long QgsCoordinateReferenceSystem::postgisSrid ( ) const

Get the postgis srid for this srs.

Returns
long theSRID the Postgis spatial_ref_sys identifier for this srs (defaults to 0)

Definition at line 829 of file qgscoordinatereferencesystem.cpp.

QString QgsCoordinateReferenceSystem::projectionAcronym ( ) const

Get the Projection Acronym.

Returns
QString theProjectionAcronym The official proj4 acronym for the projection family
Note
A zero length string will be returned if the projectionAcronym is uninitialised

Definition at line 851 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::readXML ( 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 1149 of file qgscoordinatereferencesystem.cpp.

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 2162 of file qgscoordinatereferencesystem.cpp.

bool QgsCoordinateReferenceSystem::saveAsUserCRS ( 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 1454 of file qgscoordinatereferencesystem.cpp.

void QgsCoordinateReferenceSystem::setCustomSrsValidation ( 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 1409 of file qgscoordinatereferencesystem.cpp.

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 188 of file qgscoordinatereferencesystem.cpp.

void QgsCoordinateReferenceSystem::setValidationHint ( QString  html)

Set user hint for validation.

Definition at line 1441 of file qgscoordinatereferencesystem.cpp.

long QgsCoordinateReferenceSystem::srsid ( ) const

Get the SrsId - if possible.

Returns
long theSrsId The internal sqlite3 srs.db primary key for this srs

Definition at line 824 of file qgscoordinatereferencesystem.cpp.

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.

Definition at line 1691 of file qgscoordinatereferencesystem.cpp.

QString QgsCoordinateReferenceSystem::toProj4 ( ) const

Get the Proj Proj4 string representation of this srs.

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
QString theProj4String Proj4 format specifies that define this srs.
Note
A zero length string will be returned if the toProj4 is uninitialised

Definition at line 875 of file qgscoordinatereferencesystem.cpp.

QString QgsCoordinateReferenceSystem::toWkt ( ) const

A helper to get an wkt representation of this srs.

Returns
string containing Wkt of the srs

Definition at line 1135 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.

Note
It is not usually necessary to use this function, unless you are trying to force this srs to be valid.

Definition at line 294 of file qgscoordinatereferencesystem.cpp.

QString QgsCoordinateReferenceSystem::validationHint ( )

Get user hint for validation.

Definition at line 1446 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.

1 <spatialrefsys>
2  <proj4>+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs </proj4>
3  <srsid>2585</srsid>
4  <srid>4326</srid>
5  <epsg>4326</epsg>
6  <description>WGS 84</description>
7  <projectionacronym>longlat</projectionacronym>
8  <ellipsoidacronym>WGS84</ellipsoidacronym>
9  </spatialrefsys>
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 1268 of file qgscoordinatereferencesystem.cpp.


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