QGIS API Documentation  2.99.0-Master (08ee180)
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsCoordinateTransform Class Reference

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

#include <qgscoordinatetransform.h>

Public Types

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

Public Member Functions

 QgsCoordinateTransform ()
 Default constructor, creates an invalid QgsCoordinateTransform. More...
 
 QgsCoordinateTransform (const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination)
 Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects. More...
 
 QgsCoordinateTransform (const QgsCoordinateTransform &o)
 Copy constructor. More...
 
 ~QgsCoordinateTransform ()
 
QgsCoordinateReferenceSystem destinationCrs () const
 Returns the destination coordinate reference system, which the transform will transform coordinates to. More...
 
int destinationDatumTransform () const
 
void initialise ()
 initialize is used to actually create the Transformer instance More...
 
bool isShortCircuited () const
 Returns true if the transform short circuits because the source and destination are equivalent. More...
 
bool isValid () const
 
QgsCoordinateTransformoperator= (const QgsCoordinateTransform &o)
 Assignment operator. More...
 
bool readXml (const QDomNode &node)
 Restores state from the given Dom node. More...
 
void setDestinationCrs (const QgsCoordinateReferenceSystem &crs)
 
void setDestinationDatumTransform (int dt)
 
void setSourceCrs (const QgsCoordinateReferenceSystem &crs)
 
void setSourceDatumTransform (int dt)
 
QgsCoordinateReferenceSystem sourceCrs () const
 Returns the source coordinate reference system, which the transform will transform coordinates from. More...
 
int sourceDatumTransform () const
 
QgsPoint transform (const QgsPoint &point, TransformDirection direction=ForwardTransform) const
 Transform the point from the source CRS to the destination CRS. More...
 
QgsPoint transform (const double x, const double y, TransformDirection direction=ForwardTransform) const
 Transform the point specified by x,y from the source CRS to the destination CRS. More...
 
QgsRectangle transform (const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform) const
 Transforms a rectangle to the destination CRS. More...
 
QgsRectangle transformBoundingBox (const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, const bool handle180Crossover=false) const
 Transforms a rectangle from the source CRS to the destination CRS. More...
 
void transformCoords (int numPoint, double *x, double *y, double *z, TransformDirection direction=ForwardTransform) const
 Transform an array of coordinates to the destination CRS. More...
 
void transformInPlace (double &x, double &y, double &z, TransformDirection direction=ForwardTransform) const
 Transforms an array of x, y and z double coordinates in place, from the source CRS to the destination CRS. More...
 
void transformInPlace (float &x, float &y, double &z, TransformDirection direction=ForwardTransform) const
 Transforms an array of x, y and z float coordinates in place, from the source CRS to the destination CRS. More...
 
void transformInPlace (float &x, float &y, float &z, TransformDirection direction=ForwardTransform) const
 Transforms an array of x, y and z float coordinates in place, from the source CRS to the destination CRS. More...
 
void transformInPlace (QVector< float > &x, QVector< float > &y, QVector< float > &z, TransformDirection direction=ForwardTransform) const
 Transforms a vector of x, y and z float coordinates in place, from the source CRS to the destination CRS. More...
 
void transformInPlace (QVector< double > &x, QVector< double > &y, QVector< double > &z, TransformDirection direction=ForwardTransform) const
 Transforms a vector of x, y and z double coordinates in place, from the source CRS to the destination CRS. More...
 
void transformPolygon (QPolygonF &polygon, TransformDirection direction=ForwardTransform) const
 Transforms a polygon to the destination coordinate system. More...
 
bool writeXml (QDomNode &node, QDomDocument &document) const
 Stores state to the given Dom node in the given document. More...
 

Static Public Member Functions

static QList< QList< int > > datumTransformations (const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destinationCrs)
 Returns list of datum transformations for the given src and dest CRS. More...
 
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...
 
static QString datumTransformString (int datumTransform)
 

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.

When used to transform between a layer and the map canvas, 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 layer's coordinate system to the map canvas.

Note
Since QGIS 3.0 QgsCoordinateReferenceSystem objects are implicitly shared.

Definition at line 42 of file qgscoordinatetransform.h.

Member Enumeration Documentation

§ TransformDirection

Enum used to indicate the direction (forward or inverse) of the transform.

Enumerator
ForwardTransform 

Transform from source to destination CRS.

ReverseTransform 

Transform from destination to source CRS.

Definition at line 48 of file qgscoordinatetransform.h.

Constructor & Destructor Documentation

§ QgsCoordinateTransform() [1/3]

QgsCoordinateTransform::QgsCoordinateTransform ( )

Default constructor, creates an invalid QgsCoordinateTransform.

Definition at line 43 of file qgscoordinatetransform.cpp.

§ QgsCoordinateTransform() [2/3]

QgsCoordinateTransform::QgsCoordinateTransform ( const QgsCoordinateReferenceSystem source,
const QgsCoordinateReferenceSystem destination 
)

Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects.

Parameters
sourcesource CRS, typically of the layer's coordinate system
destinationCRS, typically of the map canvas coordinate system

Definition at line 48 of file qgscoordinatetransform.cpp.

§ QgsCoordinateTransform() [3/3]

QgsCoordinateTransform::QgsCoordinateTransform ( const QgsCoordinateTransform o)

Copy constructor.

Definition at line 53 of file qgscoordinatetransform.cpp.

§ ~QgsCoordinateTransform()

QgsCoordinateTransform::~QgsCoordinateTransform ( )

Definition at line 64 of file qgscoordinatetransform.cpp.

Member Function Documentation

§ datumTransformations()

QList< QList< int > > QgsCoordinateTransform::datumTransformations ( const QgsCoordinateReferenceSystem srcCRS,
const QgsCoordinateReferenceSystem destinationCrs 
)
static

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

Note
not available in python bindings

Definition at line 622 of file qgscoordinatetransform.cpp.

§ datumTransformCrsInfo()

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

§ datumTransformString()

QString QgsCoordinateTransform::datumTransformString ( int  datumTransform)
static

Definition at line 719 of file qgscoordinatetransform.cpp.

§ destinationCrs()

QgsCoordinateReferenceSystem QgsCoordinateTransform::destinationCrs ( ) const

Returns the destination coordinate reference system, which the transform will transform coordinates to.

See also
setDestinationCrs()
sourceCrs()

Definition at line 87 of file qgscoordinatetransform.cpp.

§ destinationDatumTransform()

int QgsCoordinateTransform::destinationDatumTransform ( ) const

Definition at line 781 of file qgscoordinatetransform.cpp.

§ initialise()

void QgsCoordinateTransform::initialise ( )

initialize is used to actually create the Transformer instance

Definition at line 792 of file qgscoordinatetransform.cpp.

§ isShortCircuited()

bool QgsCoordinateTransform::isShortCircuited ( ) const

Returns true if the transform short circuits because the source and destination are equivalent.

Definition at line 565 of file qgscoordinatetransform.cpp.

§ isValid()

bool QgsCoordinateTransform::isValid ( ) const

Returns true if the coordinate transform is valid, ie both the source and destination CRS have been set and are valid.

Note
added in QGIS 3.0

Definition at line 560 of file qgscoordinatetransform.cpp.

§ operator=()

QgsCoordinateTransform & QgsCoordinateTransform::operator= ( const QgsCoordinateTransform o)

Assignment operator.

Definition at line 58 of file qgscoordinatetransform.cpp.

§ readXml()

bool QgsCoordinateTransform::readXml ( const QDomNode &  node)

Restores state from the given Dom node.

Parameters
nodeThe node from which state will be restored
Returns
bool True on success, False on failure
See also
writeXml()

Definition at line 570 of file qgscoordinatetransform.cpp.

§ setDestinationCrs()

void QgsCoordinateTransform::setDestinationCrs ( const QgsCoordinateReferenceSystem crs)

Sets the destination coordinate reference system.

Parameters
crsCRS to transform coordinates to
See also
destinationCrs()
setSourceCrs()

Definition at line 75 of file qgscoordinatetransform.cpp.

§ setDestinationDatumTransform()

void QgsCoordinateTransform::setDestinationDatumTransform ( int  dt)

Definition at line 786 of file qgscoordinatetransform.cpp.

§ setSourceCrs()

void QgsCoordinateTransform::setSourceCrs ( const QgsCoordinateReferenceSystem crs)

Sets the source coordinate reference system.

Parameters
crsCRS to transform coordinates from
See also
sourceCrs()
setDestinationCrs()

Definition at line 69 of file qgscoordinatetransform.cpp.

§ setSourceDatumTransform()

void QgsCoordinateTransform::setSourceDatumTransform ( int  dt)

Definition at line 775 of file qgscoordinatetransform.cpp.

§ sourceCrs()

QgsCoordinateReferenceSystem QgsCoordinateTransform::sourceCrs ( ) const

Returns the source coordinate reference system, which the transform will transform coordinates from.

See also
setSourceCrs()
destinationCrs()

Definition at line 82 of file qgscoordinatetransform.cpp.

§ sourceDatumTransform()

int QgsCoordinateTransform::sourceDatumTransform ( ) const

Definition at line 770 of file qgscoordinatetransform.cpp.

§ transform() [1/3]

QgsPoint QgsCoordinateTransform::transform ( const QgsPoint point,
TransformDirection  direction = ForwardTransform 
) const

Transform the point from the source CRS to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
pointpoint to transform
directiontransform direction (defaults to ForwardTransform)
Returns
transformed point

Definition at line 92 of file qgscoordinatetransform.cpp.

§ transform() [2/3]

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

Transform the point specified by x,y from the source CRS to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
xx coordinate of point to transform
yy coordinate of point to transform
directiontransform direction (defaults to ForwardTransform)
Returns
transformed point

Definition at line 116 of file qgscoordinatetransform.cpp.

§ transform() [3/3]

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

Transforms a rectangle to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
rectanglerectangle to transform
directiontransform direction (defaults to ForwardTransform)
Returns
transformed rectangle

Definition at line 130 of file qgscoordinatetransform.cpp.

§ transformBoundingBox()

QgsRectangle QgsCoordinateTransform::transformBoundingBox ( const QgsRectangle rectangle,
TransformDirection  direction = ForwardTransform,
const bool  handle180Crossover = false 
) const

Transforms a rectangle from the source CRS to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS. This method assumes that the rectangle is a bounding box, and creates a bounding box in the projected CRS, such that all points from the source rectangle are within the returned rectangle.

Parameters
rectanglerectangle to transform
directiontransform direction (defaults to ForwardTransform)
handle180Crossoverset to true if destination CRS is geographic and handling of extents crossing the 180 degree longitude line is required
Returns
rectangle in destination CRS

Definition at line 337 of file qgscoordinatetransform.cpp.

§ transformCoords()

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

Transform an array of coordinates to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
numPointnumber of coordinates in arrays
xarray of x coordinates to transform
yarray of y coordinates to transform
zarray of z coordinates to transform
directiontransform direction (defaults to ForwardTransform)

Definition at line 451 of file qgscoordinatetransform.cpp.

§ transformInPlace() [1/5]

void QgsCoordinateTransform::transformInPlace ( double &  x,
double &  y,
double &  z,
TransformDirection  direction = ForwardTransform 
) const

Transforms an array of x, y and z double coordinates in place, from the source CRS to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
xarray of x coordinates of points to transform
yarray of y coordinates of points to transform
zarray of z coordinates of points to transform. The z coordinates of the points must represent height relative to the vertical datum of the source CRS (generally ellipsoidal heights) and must be expressed in its vertical units (generally meters)
directiontransform direction (defaults to ForwardTransform)

Definition at line 166 of file qgscoordinatetransform.cpp.

§ transformInPlace() [2/5]

void QgsCoordinateTransform::transformInPlace ( float &  x,
float &  y,
double &  z,
TransformDirection  direction = ForwardTransform 
) const

Transforms an array of x, y and z float coordinates in place, from the source CRS to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
xarray of x coordinates of points to transform
yarray of y coordinates of points to transform
zarray of z coordinates of points to transform. The z coordinates of the points must represent height relative to the vertical datum of the source CRS (generally ellipsoidal heights) and must be expressed in its vertical units (generally meters)
directiontransform direction (defaults to ForwardTransform)
Note
not available in python bindings

Definition at line 187 of file qgscoordinatetransform.cpp.

§ transformInPlace() [3/5]

void QgsCoordinateTransform::transformInPlace ( float &  x,
float &  y,
float &  z,
TransformDirection  direction = ForwardTransform 
) const

Transforms an array of x, y and z float coordinates in place, from the source CRS to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
xarray of x coordinates of points to transform
yarray of y coordinates of points to transform
zarray of z coordinates of points to transform. The z coordinates of the points must represent height relative to the vertical datum of the source CRS (generally ellipsoidal heights) and must be expressed in its vertical units (generally meters)
directiontransform direction (defaults to ForwardTransform)
Note
not available in python bindings

Definition at line 196 of file qgscoordinatetransform.cpp.

§ transformInPlace() [4/5]

void QgsCoordinateTransform::transformInPlace ( QVector< float > &  x,
QVector< float > &  y,
QVector< float > &  z,
TransformDirection  direction = ForwardTransform 
) const

Transforms a vector of x, y and z float coordinates in place, from the source CRS to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
xvector of x coordinates of points to transform
yvector of y coordinates of points to transform
zvector of z coordinates of points to transform. The z coordinates of the points must represent height relative to the vertical datum of the source CRS (generally ellipsoidal heights) and must be expressed in its vertical units (generally meters)
directiontransform direction (defaults to ForwardTransform)
Note
not available in python bindings

Definition at line 292 of file qgscoordinatetransform.cpp.

§ transformInPlace() [5/5]

void QgsCoordinateTransform::transformInPlace ( QVector< double > &  x,
QVector< double > &  y,
QVector< double > &  z,
TransformDirection  direction = ForwardTransform 
) const

Transforms a vector of x, y and z double coordinates in place, from the source CRS to the destination CRS.

If the direction is ForwardTransform then coordinates are transformed from source to destination, otherwise points are transformed from destination to source CRS.

Parameters
xvector of x coordinates of points to transform
yvector of y coordinates of points to transform
zvector of z coordinates of points to transform. The z coordinates of the points must represent height relative to the vertical datum of the source CRS (generally ellipsoidal heights) and must be expressed in its vertical units (generally meters)
directiontransform direction (defaults to ForwardTransform)
Note
not available in python bindings

Definition at line 264 of file qgscoordinatetransform.cpp.

§ transformPolygon()

void QgsCoordinateTransform::transformPolygon ( QPolygonF &  polygon,
TransformDirection  direction = ForwardTransform 
) const

Transforms a polygon to the destination coordinate system.

Parameters
polygonpolygon to transform (occurs in place)
directiontransform direction (defaults to forward transformation)

Definition at line 223 of file qgscoordinatetransform.cpp.

§ writeXml()

bool QgsCoordinateTransform::writeXml ( QDomNode &  node,
QDomDocument &  document 
) const

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

Parameters
nodeThe node in which state will be restored
documentThe document in which state will be stored
Returns
bool True on success, False on failure
See also
readXml()

Definition at line 588 of file qgscoordinatetransform.cpp.


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