QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Classes | Public Types | Public Slots | Signals | 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>

Inheritance diagram for QgsCoordinateTransform:
Inheritance 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 ()
 initialize is used to actually create the Transformer instance More...
 
bool readXML (QDomNode &theNode)
 Restores state from the given Dom node. More...
 
bool writeXML (QDomNode &theNode, QDomDocument &theDoc)
 Stores state to the given Dom node in the given document. More...
 

Signals

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

Public Member Functions

 QgsCoordinateTransform ()
 Default constructor. More...
 
 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 (const QString &theSourceWkt, const QString &theDestWkt)
 
 QgsCoordinateTransform (long theSourceSrid, const QString &theDestWkt, QgsCoordinateReferenceSystem::CrsType theSourceCRSType=QgsCoordinateReferenceSystem::PostgisCrsId)
 
 ~QgsCoordinateTransform ()
 destructor More...
 
QgsCoordinateTransformclone () const
 
const QgsCoordinateReferenceSystemdestCRS () const
 
int destinationDatumTransform () const
 
bool isInitialised () const
 
bool isShortCircuited () const
 See if the transform short circuits because src and dest are equivalent. More...
 
void setDestCRS (const QgsCoordinateReferenceSystem &theCRS)
 
void 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. More...
 
void setDestinationDatumTransform (int dt)
 
void setSourceCrs (const QgsCoordinateReferenceSystem &theCRS)
 
void setSourceDatumTransform (int dt)
 
const QgsCoordinateReferenceSystemsourceCrs () const
 
int sourceDatumTransform () const
 
QgsPoint transform (const QgsPoint &p, TransformDirection direction=ForwardTransform) const
 Transform the point 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. More...
 
QgsPoint transform (const double x, const double y, 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. More...
 
QgsRectangle 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. More...
 
QgsRectangle transformBoundingBox (const QgsRectangle &theRect, TransformDirection direction=ForwardTransform, const bool handle180Crossover=false) 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. More...
 
void transformCoords (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. More...
 
void transformInPlace (double &x, double &y, double &z, TransformDirection direction=ForwardTransform) const
 
void transformInPlace (float &x, float &y, double &z, TransformDirection direction=ForwardTransform) const
 
void transformInPlace (float &x, float &y, float &z, TransformDirection direction=ForwardTransform) const
 
void transformInPlace (QVector< float > &x, QVector< float > &y, QVector< float > &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
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual ~QObject ()
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 

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 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)
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Additional Inherited Members

- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

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 55 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 97 of file qgscoordinatetransform.h.

Constructor & Destructor Documentation

◆ QgsCoordinateTransform() [1/5]

QgsCoordinateTransform::QgsCoordinateTransform ( )

Default constructor.

Make sure you use initialized() manually if you use this one!

Definition at line 42 of file qgscoordinatetransform.cpp.

◆ QgsCoordinateTransform() [2/5]

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

◆ QgsCoordinateTransform() [3/5]

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.

◆ QgsCoordinateTransform() [4/5]

QgsCoordinateTransform::QgsCoordinateTransform ( const QString theSourceWkt,
const 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 76 of file qgscoordinatetransform.cpp.

◆ QgsCoordinateTransform() [5/5]

QgsCoordinateTransform::QgsCoordinateTransform ( long  theSourceSrid,
const 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 92 of file qgscoordinatetransform.cpp.

◆ ~QgsCoordinateTransform()

QgsCoordinateTransform::~QgsCoordinateTransform ( )

destructor

Definition at line 111 of file qgscoordinatetransform.cpp.

Member Function Documentation

◆ clone()

QgsCoordinateTransform * QgsCoordinateTransform::clone ( ) const

Definition at line 116 of file qgscoordinatetransform.cpp.

◆ datumTransformations()

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

◆ datumTransformString()

QString QgsCoordinateTransform::datumTransformString ( int  datumTransform)
static

Definition at line 917 of file qgscoordinatetransform.cpp.

◆ destCRS()

const QgsCoordinateReferenceSystem& QgsCoordinateTransform::destCRS ( ) const
inline

Get the QgsCoordinateReferenceSystem representation of the map canvas coordinate system

Returns
QgsCoordinateReferenceSystem of the map canvas coordinate system

Definition at line 125 of file qgscoordinatetransform.h.

◆ destinationDatumTransform()

int QgsCoordinateTransform::destinationDatumTransform ( ) const
inline

Definition at line 233 of file qgscoordinatetransform.h.

◆ initialise

void QgsCoordinateTransform::initialise ( )
slot

initialize is used to actually create the Transformer instance

Definition at line 145 of file qgscoordinatetransform.cpp.

◆ invalidTransformInput

void QgsCoordinateTransform::invalidTransformInput ( ) const
signal

Signal when an invalid pj_transform() has occurred.

◆ isInitialised()

bool QgsCoordinateTransform::isInitialised ( ) const
inline

Flag to indicate whether the coordinate systems have been initialized

Returns
true if initialized, otherwise false

Definition at line 204 of file qgscoordinatetransform.h.

◆ isShortCircuited()

bool QgsCoordinateTransform::isShortCircuited ( ) const
inline

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

Returns
bool True if it short circuits

Definition at line 209 of file qgscoordinatetransform.h.

◆ readXML

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

◆ setDestCRS()

void QgsCoordinateTransform::setDestCRS ( const QgsCoordinateReferenceSystem theCRS)

Mutator for dest QgsCoordinateReferenceSystem

Parameters
theCRSof the destination coordinate system

Definition at line 130 of file qgscoordinatetransform.cpp.

◆ setDestCRSID()

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

◆ setDestinationDatumTransform()

void QgsCoordinateTransform::setDestinationDatumTransform ( int  dt)
inline

Definition at line 234 of file qgscoordinatetransform.h.

◆ setSourceCrs()

void QgsCoordinateTransform::setSourceCrs ( const QgsCoordinateReferenceSystem theCRS)

Set the source (layer) QgsCoordinateReferenceSystem

Parameters
theCRSQgsCoordinateReferenceSystem representation of the layer's coordinate system

Definition at line 125 of file qgscoordinatetransform.cpp.

◆ setSourceDatumTransform()

void QgsCoordinateTransform::setSourceDatumTransform ( int  dt)
inline

Definition at line 232 of file qgscoordinatetransform.h.

◆ sourceCrs()

const QgsCoordinateReferenceSystem& QgsCoordinateTransform::sourceCrs ( ) const
inline

Get the QgsCoordinateReferenceSystem representation of the layer's coordinate system

Returns
QgsCoordinateReferenceSystem of the layer's coordinate system

Definition at line 119 of file qgscoordinatetransform.h.

◆ sourceDatumTransform()

int QgsCoordinateTransform::sourceDatumTransform ( ) const
inline

Definition at line 231 of file qgscoordinatetransform.h.

◆ transform() [1/3]

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

Transform the point 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
pPoint to transform
directionTransformDirection (defaults to ForwardTransform)
Returns
QgsPoint in Destination Coordinate System

Definition at line 260 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 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 283 of file qgscoordinatetransform.cpp.

◆ transform() [3/3]

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

◆ transformBoundingBox()

QgsRectangle QgsCoordinateTransform::transformBoundingBox ( const QgsRectangle theRect,
TransformDirection  direction = ForwardTransform,
const bool  handle180Crossover = false 
) 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)
handle180Crossoverset to true if destination crs is geographic and handling of extents crossing the 180 degree longitude line is required
Returns
QgsRectangle in Destination Coordinate System

Definition at line 503 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 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 617 of file qgscoordinatetransform.cpp.

◆ transformInPlace() [1/5]

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

Definition at line 333 of file qgscoordinatetransform.cpp.

◆ transformInPlace() [2/5]

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

Definition at line 354 of file qgscoordinatetransform.cpp.

◆ transformInPlace() [3/5]

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

Definition at line 363 of file qgscoordinatetransform.cpp.

◆ transformInPlace() [4/5]

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

Definition at line 458 of file qgscoordinatetransform.cpp.

◆ transformInPlace() [5/5]

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

◆ transformPolygon()

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

Definition at line 390 of file qgscoordinatetransform.cpp.

◆ writeXML

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


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