QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
QgsCoordinateTransform Class Reference

Class for doing transforms between two map coordinate systems. More...

#include <qgscoordinatetransform.h>

Inheritance diagram for QgsCoordinateTransform:
Inheritance graph
[legend]
Collaboration diagram for QgsCoordinateTransform:
Collaboration graph
[legend]

Public Types

enum  TransformDirection { ForwardTransform, ReverseTransform }
 Enum used to indicate the direction (forward or inverse) of the transform. More...
 

Public Slots

void initialise ()
 initialise is used to actually create the Transformer instance More...
 
bool readXML (QDomNode &theNode)
 
bool writeXML (QDomNode &theNode, QDomDocument &theDoc)
 

Signals

void invalidTransformInput () const
 Signal when an invalid pj_transform() has occured. More...
 

Public Member Functions

 QgsCoordinateTransform ()
 
 QgsCoordinateTransform (const QgsCoordinateReferenceSystem &theSource, const QgsCoordinateReferenceSystem &theDest)
 Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects. More...
 
 QgsCoordinateTransform (long theSourceSrsId, long theDestSrsId)
 Constructs a QgsCoordinateTransform using CRS ID of source and destination CRS. More...
 
 QgsCoordinateTransform (QString theSourceWkt, QString theDestWkt)
 
 QgsCoordinateTransform (long theSourceSrid, QString theDestWkt, QgsCoordinateReferenceSystem::CrsType theSourceCRSType=QgsCoordinateReferenceSystem::PostgisCrsId)
 
 ~QgsCoordinateTransform ()
 destructor More...
 
QgsCoordinateTransformclone () const
 
void setSourceCrs (const QgsCoordinateReferenceSystem &theCRS)
 
void setDestCRS (const QgsCoordinateReferenceSystem &theCRS)
 
const
QgsCoordinateReferenceSystem
sourceCrs () const
 
const
QgsCoordinateReferenceSystem
destCRS () const
 
QgsPoint transform (const QgsPoint p, TransformDirection direction=ForwardTransform) const
 
QgsPoint transform (const double x, const double y, TransformDirection direction=ForwardTransform) const
 
QgsRectangle transformBoundingBox (const QgsRectangle theRect, TransformDirection direction=ForwardTransform) const
 
void transformInPlace (double &x, double &y, double &z, TransformDirection direction=ForwardTransform) const
 
void transformInPlace (QVector< double > &x, QVector< double > &y, QVector< double > &z, TransformDirection direction=ForwardTransform) const
 
void transformPolygon (QPolygonF &poly, TransformDirection direction=ForwardTransform) const
 
QgsRectangle transform (const QgsRectangle theRect, TransformDirection direction=ForwardTransform) const
 
void transformCoords (const int &numPoint, double *x, double *y, double *z, TransformDirection direction=ForwardTransform) const
 
bool isInitialised () const
 
bool isShortCircuited ()
 
void setDestCRSID (long theCRSID)
 
int sourceDatumTransform () const
 
void setSourceDatumTransform (int dt)
 
int destinationDatumTransform () const
 
void setDestinationDatumTransform (int dt)
 

Static Public Member Functions

static QList< QList< int > > datumTransformations (const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS)
 Returns list of datum transformations for the given src and dest CRS. More...
 
static QString datumTransformString (int datumTransform)
 
static bool datumTransformCrsInfo (int datumTransform, int &epsgNr, QString &srcProjection, QString &dstProjection, QString &remarks, QString &scope, bool &preferred, bool &deprecated)
 Gets name of source and dest geographical CRS (to show in a tooltip) More...
 

Private Member Functions

void setFinder ()
 
void addNullGridShifts (QString &srcProjString, QString &destProjString)
 In certain situations, null grid shifts have to be added to src / dst proj string. More...
 

Static Private Member Functions

static QString stripDatumTransform (const QString &proj4)
 Removes +nadgrids and +towgs84 from proj4 string. More...
 
static void searchDatumTransform (const QString &sql, QList< int > &transforms)
 

Private Attributes

bool mShortCircuit
 
bool mInitialisedFlag
 
QgsCoordinateReferenceSystem mSourceCRS
 
QgsCoordinateReferenceSystem mDestCRS
 
projPJ mSourceProjection
 
projPJ mDestinationProjection
 
int mSourceDatumTransform
 
int mDestinationDatumTransform
 

Detailed Description

Class for doing transforms between two map coordinate systems.

This class can convert map coordinates to a different coordinate reference system. It is normally associated with a map layer and is used to transform between the layer's coordinate system and the coordinate system of the map canvas, although it can be used in a more general sense to transform coordinates.

All references to source and destination coordinate systems refer to layer and map canvas respectively. All operations are from the perspective of the layer. For example, a forward transformation transforms coordinates from the layers coordinate system to the map canvas.

Definition at line 52 of file qgscoordinatetransform.h.

Constructor & Destructor Documentation

QgsCoordinateTransform::QgsCoordinateTransform ( )

Default constructor. Make sure you use initialised() manually if you use this one!

Definition at line 40 of file qgscoordinatetransform.cpp.

References setFinder().

Referenced by clone().

QgsCoordinateTransform::QgsCoordinateTransform ( const QgsCoordinateReferenceSystem theSource,
const QgsCoordinateReferenceSystem theDest 
)

Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects.

Parameters
theSourceCRS, typically of the layer's coordinate system
theDestCRS, typically of the map canvas coordinate system

Definition at line 51 of file qgscoordinatetransform.cpp.

References initialise(), mDestCRS, mSourceCRS, and setFinder().

QgsCoordinateTransform::QgsCoordinateTransform ( long  theSourceSrsId,
long  theDestSrsId 
)

Constructs a QgsCoordinateTransform using CRS ID of source and destination CRS.

Definition at line 65 of file qgscoordinatetransform.cpp.

References initialise().

QgsCoordinateTransform::QgsCoordinateTransform ( QString  theSourceWkt,
QString  theDestWkt 
)

Constructs a QgsCoordinateTransform using the Well Known Text representation of the layer and map canvas coordinate systems

Parameters
theSourceWktWkt, typically of the layer's coordinate system
theDestWktWkt, typically of the map canvas coordinate system

Definition at line 78 of file qgscoordinatetransform.cpp.

References QgsCoordinateReferenceSystem::createFromWkt(), initialise(), mDestCRS, mSourceCRS, and setFinder().

QgsCoordinateTransform::QgsCoordinateTransform ( long  theSourceSrid,
QString  theDestWkt,
QgsCoordinateReferenceSystem::CrsType  theSourceCRSType = QgsCoordinateReferenceSystem::PostgisCrsId 
)

Constructs a QgsCoordinateTransform using a Spatial Reference Id of the layer and map canvas coordinate system as Wkt

Parameters
theSourceSridSpatial Ref Id of the layer's coordinate system
theDestWktWkt of the map canvas coordinate system
theSourceCRSTypeOn of the enum members defined in QgsCoordinateReferenceSystem::CrsType

Definition at line 96 of file qgscoordinatetransform.cpp.

References QgsCoordinateReferenceSystem::createFromId(), QgsCoordinateReferenceSystem::createFromWkt(), initialise(), mDestCRS, mSourceCRS, and setFinder().

QgsCoordinateTransform::~QgsCoordinateTransform ( )

destructor

Definition at line 117 of file qgscoordinatetransform.cpp.

References mDestinationProjection, and mSourceProjection.

Member Function Documentation

void QgsCoordinateTransform::addNullGridShifts ( QString &  srcProjString,
QString &  destProjString 
)
private

In certain situations, null grid shifts have to be added to src / dst proj string.

Definition at line 998 of file qgscoordinatetransform.cpp.

References QgsCoordinateReferenceSystem::authid(), mDestCRS, mDestinationDatumTransform, mSourceCRS, and mSourceDatumTransform.

Referenced by initialise().

QgsCoordinateTransform * QgsCoordinateTransform::clone ( ) const
QList< QList< int > > QgsCoordinateTransform::datumTransformations ( const QgsCoordinateReferenceSystem srcCRS,
const QgsCoordinateReferenceSystem destCRS 
)
static

Returns list of datum transformations for the given src and dest CRS.

Note
not available in python bindings

Definition at line 782 of file qgscoordinatetransform.cpp.

References QgsCoordinateReferenceSystem::geographicCRSAuthId(), and searchDatumTransform().

Referenced by QgsMapCanvas::getDatumTransformInfo().

bool QgsCoordinateTransform::datumTransformCrsInfo ( int  datumTransform,
int &  epsgNr,
QString &  srcProjection,
QString &  dstProjection,
QString &  remarks,
QString &  scope,
bool &  preferred,
bool &  deprecated 
)
static

Gets name of source and dest geographical CRS (to show in a tooltip)

Returns
epsgNr epsg code of the transformation (or 0 if not in epsg db)

Definition at line 951 of file qgscoordinatetransform.cpp.

References QgsCoordinateReferenceSystem::createFromOgcWmsCrs(), QgsCoordinateReferenceSystem::description(), and QgsApplication::srsDbFilePath().

Referenced by QgsDatumTransformDialog::load().

QString QgsCoordinateTransform::datumTransformString ( int  datumTransform)
static
const QgsCoordinateReferenceSystem& QgsCoordinateTransform::destCRS ( ) const
inline
int QgsCoordinateTransform::destinationDatumTransform ( ) const
inline
void QgsCoordinateTransform::initialise ( )
slot
void QgsCoordinateTransform::invalidTransformInput ( ) const
signal

Signal when an invalid pj_transform() has occured.

Referenced by transformCoords().

bool QgsCoordinateTransform::isInitialised ( ) const
inline

Flag to indicate whether the coordinate systems have been initialised

Returns
true if initialised, otherwise false

Definition at line 201 of file qgscoordinatetransform.h.

Referenced by operator<<().

bool QgsCoordinateTransform::isShortCircuited ( )
inline

See if the transform short circuits because src and dest are equivalent

Returns
bool True if it short circuits

Definition at line 206 of file qgscoordinatetransform.h.

Referenced by operator<<().

bool QgsCoordinateTransform::readXML ( QDomNode &  theNode)
slot

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 715 of file qgscoordinatetransform.cpp.

References initialise(), mDestCRS, mDestinationDatumTransform, mSourceCRS, mSourceDatumTransform, QgsDebugMsg, and QgsCoordinateReferenceSystem::readXML().

void QgsCoordinateTransform::searchDatumTransform ( const QString &  sql,
QList< int > &  transforms 
)
staticprivate

Definition at line 870 of file qgscoordinatetransform.cpp.

References QgsApplication::srsDbFilePath().

Referenced by datumTransformations().

void QgsCoordinateTransform::setDestCRS ( const QgsCoordinateReferenceSystem theCRS)

Mutator for dest QgsCoordinateReferenceSystem

Parameters
theCRSof the destination coordinate system

Definition at line 144 of file qgscoordinatetransform.cpp.

References initialise(), and mDestCRS.

Referenced by QgsAtlasComposition::computeExtent(), QgsComposerMapGrid::crsGridParams(), QgsLineVectorLayerDirector::makeGraph(), and QgsDistanceArea::setEllipsoid().

void QgsCoordinateTransform::setDestCRSID ( long  theCRSID)

Change the destination coordinate system by passing it a qgis srsid A QGIS srsid is a unique key value to an entry on the tbl_srs in the srs.db sqlite database.

Note
This slot will usually be called if the project properties change and a different coordinate system is selected.
This coord transform will be reinitialised when this slot is called to check if short circuiting is needed or not etc.
Parameters
theCRSID- A long representing the srsid of the srs to be used

todo Add some logic here to determine if the srsid is a system or user one

Definition at line 150 of file qgscoordinatetransform.cpp.

References QgsCoordinateReferenceSystem::createFromSrsId(), initialise(), and mDestCRS.

void QgsCoordinateTransform::setDestinationDatumTransform ( int  dt)
inline

Definition at line 231 of file qgscoordinatetransform.h.

Referenced by clone(), and QgsCoordinateTransformCache::transform().

void QgsCoordinateTransform::setFinder ( )
private

Finder for PROJ grid files.

Definition at line 766 of file qgscoordinatetransform.cpp.

References finder().

Referenced by QgsCoordinateTransform().

void QgsCoordinateTransform::setSourceCrs ( const QgsCoordinateReferenceSystem theCRS)
void QgsCoordinateTransform::setSourceDatumTransform ( int  dt)
inline

Definition at line 229 of file qgscoordinatetransform.h.

Referenced by clone(), and QgsCoordinateTransformCache::transform().

const QgsCoordinateReferenceSystem& QgsCoordinateTransform::sourceCrs ( ) const
inline
int QgsCoordinateTransform::sourceDatumTransform ( ) const
inline
QString QgsCoordinateTransform::stripDatumTransform ( const QString &  proj4)
staticprivate

Removes +nadgrids and +towgs84 from proj4 string.

Definition at line 850 of file qgscoordinatetransform.cpp.

Referenced by initialise().

QgsPoint QgsCoordinateTransform::transform ( const QgsPoint  p,
TransformDirection  direction = ForwardTransform 
) const
QgsPoint QgsCoordinateTransform::transform ( const double  x,
const double  y = 0,
TransformDirection  direction = ForwardTransform 
) const

Transform the point specified by x,y from Source Coordinate System to Destination Coordinate System If the direction is ForwardTransform then coordinates are transformed from layer CS –> map canvas CS, otherwise points are transformed from map canvas CS to layerCS.

Parameters
xx cordinate of point to transform
yy coordinate of point to transform
directionTransformDirection (defaults to ForwardTransform)
Returns
QgsPoint in Destination Coordinate System

Definition at line 299 of file qgscoordinatetransform.cpp.

References QgsDebugMsg, and transform().

QgsRectangle QgsCoordinateTransform::transform ( const QgsRectangle  theRect,
TransformDirection  direction = ForwardTransform 
) const

Transform a QgsRectangle to the dest Coordinate system If the direction is ForwardTransform then coordinates are transformed from layer CS –> map canvas CS, otherwise points are transformed from map canvas CS to layerCS.

Parameters
theRectrect to transform
directionTransformDirection (defaults to ForwardTransform)
Returns
QgsRectangle in Destination Coordinate System

Definition at line 313 of file qgscoordinatetransform.cpp.

References mInitialisedFlag, mShortCircuit, QgsDebugMsg, transformCoords(), QgsRectangle::xMaximum(), QgsRectangle::xMinimum(), QgsRectangle::yMaximum(), and QgsRectangle::yMinimum().

QgsRectangle QgsCoordinateTransform::transformBoundingBox ( const QgsRectangle  theRect,
TransformDirection  direction = ForwardTransform 
) const

Transform a QgsRectangle to the dest Coordinate system If the direction is ForwardTransform then coordinates are transformed from layer CS –> map canvas CS, otherwise points are transformed from map canvas CS to layerCS. It assumes that rect is a bounding box, and creates a bounding box in the proejcted CS, so that all points in source rectangle is within returned rectangle.

Parameters
theRectrect to transform
directionTransformDirection (defaults to ForwardTransform)
Returns
QgsRectangle in Destination Coordinate System

Definition at line 523 of file qgscoordinatetransform.cpp.

References QgsRectangle::combineExtentWith(), QgsRectangle::height(), QgsRectangle::isEmpty(), mInitialisedFlag, mShortCircuit, QgsDebugMsg, QgsRectangle::setMinimal(), QgsRectangle::toString(), transform(), transformCoords(), QgsRectangle::width(), QgsRectangle::xMinimum(), and QgsRectangle::yMinimum().

Referenced by QgsMapRenderer::layerExtentToOutputExtent(), QgsMapRenderer::outputExtentToLayerExtent(), QgsRasterLayerRenderer::QgsRasterLayerRenderer(), QgsMapRendererJob::reprojectToLayerExtent(), QgsMapRenderer::setDestinationCrs(), QgsExtentGroupBox::setOutputExtent(), and QgsMapRenderer::splitLayersExtent().

void QgsCoordinateTransform::transformCoords ( const int &  numPoint,
double *  x,
double *  y,
double *  z,
TransformDirection  direction = ForwardTransform 
) const

Transform an array of coordinates to a different Coordinate System If the direction is ForwardTransform then coordinates are transformed from layer CS –> map canvas CS, otherwise points are transformed from map canvas CS to layerCS.

Parameters
numPointnumber of coordinates in arrays
xarray of x coordinates to transform
yarray of y coordinates to transform
zarray of z coordinates to transform
directionTransformDirection (defaults to ForwardTransform)
Returns
QgsRectangle in Destination Coordinate System

Definition at line 609 of file qgscoordinatetransform.cpp.

References ForwardTransform, invalidTransformInput(), QgsCoordinateReferenceSystem::isValid(), QgsMessageLog::logMessage(), mDestCRS, mDestinationProjection, mSourceCRS, mSourceProjection, QgsDebugMsg, ReverseTransform, QgsCoordinateReferenceSystem::toProj4(), and tr.

Referenced by transform(), transformBoundingBox(), transformInPlace(), and transformPolygon().

void QgsCoordinateTransform::transformInPlace ( double &  x,
double &  y,
double &  z,
TransformDirection  direction = ForwardTransform 
) const
void QgsCoordinateTransform::transformInPlace ( QVector< double > &  x,
QVector< double > &  y,
QVector< double > &  z,
TransformDirection  direction = ForwardTransform 
) const
Note
not available in python bindings

Definition at line 411 of file qgscoordinatetransform.cpp.

References mInitialisedFlag, mShortCircuit, QgsDebugMsg, and transformCoords().

void QgsCoordinateTransform::transformPolygon ( QPolygonF &  poly,
TransformDirection  direction = ForwardTransform 
) const
bool QgsCoordinateTransform::writeXML ( QDomNode &  theNode,
QDomDocument &  theDoc 
)
slot

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 734 of file qgscoordinatetransform.cpp.

References mDestCRS, mDestinationDatumTransform, mSourceCRS, mSourceDatumTransform, and QgsCoordinateReferenceSystem::writeXML().

Member Data Documentation

QgsCoordinateReferenceSystem QgsCoordinateTransform::mDestCRS
private

QgsCoordinateReferenceSystem of the destination (map canvas) coordinate system

Definition at line 275 of file qgscoordinatetransform.h.

Referenced by addNullGridShifts(), initialise(), QgsCoordinateTransform(), readXML(), setDestCRS(), setDestCRSID(), transformCoords(), and writeXML().

int QgsCoordinateTransform::mDestinationDatumTransform
private

Definition at line 288 of file qgscoordinatetransform.h.

Referenced by addNullGridShifts(), initialise(), readXML(), and writeXML().

projPJ QgsCoordinateTransform::mDestinationProjection
private

Proj4 data structure of the destination projection (map canvas coordinate system)

Definition at line 285 of file qgscoordinatetransform.h.

Referenced by initialise(), transformCoords(), and ~QgsCoordinateTransform().

bool QgsCoordinateTransform::mInitialisedFlag
private

flag to show whether the transform is properly initialised or not

Definition at line 265 of file qgscoordinatetransform.h.

Referenced by initialise(), transform(), transformBoundingBox(), transformInPlace(), and transformPolygon().

bool QgsCoordinateTransform::mShortCircuit
private

Flag to indicate that the source and destination coordinate systems are equal and not transformation needs to be done

Definition at line 260 of file qgscoordinatetransform.h.

Referenced by initialise(), transform(), transformBoundingBox(), transformInPlace(), and transformPolygon().

QgsCoordinateReferenceSystem QgsCoordinateTransform::mSourceCRS
private
int QgsCoordinateTransform::mSourceDatumTransform
private

Definition at line 287 of file qgscoordinatetransform.h.

Referenced by addNullGridShifts(), initialise(), readXML(), and writeXML().

projPJ QgsCoordinateTransform::mSourceProjection
private

Proj4 data structure of the source projection (layer coordinate system)

Definition at line 280 of file qgscoordinatetransform.h.

Referenced by initialise(), transformCoords(), and ~QgsCoordinateTransform().


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