QgsCoordinateTransform Class Reference
[QGIS core library]

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

#include <qgscoordinatetransform.h>

Collaboration diagram for QgsCoordinateTransform:

Collaboration graph
[legend]

List of all members.

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
bool readXML (QDomNode &theNode)
bool writeXML (QDomNode &theNode, QDomDocument &theDoc)

Signals

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

Public Member Functions

 QgsCoordinateTransform ()
 QgsCoordinateTransform (const QgsCoordinateReferenceSystem &theSource, const QgsCoordinateReferenceSystem &theDest)
 Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects.
 QgsCoordinateTransform (long theSourceSrsId, long theDestSrsId)
 Constructs a QgsCoordinateTransform using CRS ID of source and destination CRS.
 QgsCoordinateTransform (QString theSourceWkt, QString theDestWkt)
 QgsCoordinateTransform (long theSourceSrid, QString theDestWkt, QgsCoordinateReferenceSystem::CrsType theSourceCRSType=QgsCoordinateReferenceSystem::PostgisCrsId)
 ~QgsCoordinateTransform ()
 destructor
void setSourceCrs (const QgsCoordinateReferenceSystem &theCRS)
void setDestCRS (const QgsCoordinateReferenceSystem &theCRS)
QgsCoordinateReferenceSystemsourceCrs ()
QgsCoordinateReferenceSystemdestCRS ()
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 (std::vector< double > &x, std::vector< double > &y, std::vector< double > &z, 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)

Private Member Functions

void setFinder ()

Private Attributes

bool mShortCircuit
bool mInitialisedFlag
QgsCoordinateReferenceSystem mSourceCRS
QgsCoordinateReferenceSystem mDestCRS
projPJ mSourceProjection
projPJ mDestinationProjection


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.


Member Enumeration Documentation

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

References setFinder().

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

Constructs a QgsCoordinateTransform using QgsCoordinateReferenceSystem objects.

Parameters:
theSource CRS, typically of the layer's coordinate system
theDest CRS, typically of the map canvas coordinate system

Definition at line 41 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 51 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:
theSourceWkt Wkt, typically of the layer's coordinate system
theDestWkt Wkt, typically of the map canvas coordinate system

Definition at line 58 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:
theSourceSrid Spatial Ref Id of the layer's coordinate system
theDestWkt Wkt of the map canvas coordinate system
theSourceCRSType On of the enum members defined in QgsCoordinateReferenceSystem::CrsType

Definition at line 71 of file qgscoordinatetransform.cpp.

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

QgsCoordinateTransform::~QgsCoordinateTransform (  ) 

destructor

Definition at line 86 of file qgscoordinatetransform.cpp.

References mDestinationProjection, and mSourceProjection.


Member Function Documentation

void QgsCoordinateTransform::setSourceCrs ( const QgsCoordinateReferenceSystem theCRS  ) 

Set the source (layer) QgsCoordinateReferenceSystem

Parameters:
theCRS QgsCoordinateReferenceSystem representation of the layer's coordinate system

Definition at line 99 of file qgscoordinatetransform.cpp.

References initialise(), and mSourceCRS.

Referenced by QgsDistanceArea::setSourceCrs(), and QgsDistanceArea::setSourceEpsgCrsId().

void QgsCoordinateTransform::setDestCRS ( const QgsCoordinateReferenceSystem theCRS  ) 

Mutator for dest QgsCoordinateReferenceSystem

Parameters:
theCRS of the destination coordinate system

Definition at line 104 of file qgscoordinatetransform.cpp.

References initialise(), and mDestCRS.

Referenced by QgsDistanceArea::setEllipsoid().

QgsCoordinateReferenceSystem& QgsCoordinateTransform::sourceCrs (  )  [inline]

Get the QgsCoordinateReferenceSystem representation of the layer's coordinate system

Returns:
QgsCoordinateReferenceSystem of the layer's coordinate system

Definition at line 114 of file qgscoordinatetransform.h.

Referenced by operator<<(), and QgsLabel::renderLabel().

QgsCoordinateReferenceSystem& QgsCoordinateTransform::destCRS (  )  [inline]

Get the QgsCoordinateReferenceSystem representation of the map canvas coordinate system

Returns:
QgsCoordinateReferenceSystem of the map canvas coordinate system

Definition at line 120 of file qgscoordinatetransform.h.

Referenced by operator<<(), and QgsLabel::renderLabel().

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:
p Point to transform
direction TransformDirection (defaults to ForwardTransform)
Returns:
QgsPoint in Destination Coordinate System

Definition at line 213 of file qgscoordinatetransform.cpp.

References mInitialisedFlag, mShortCircuit, QgsDebugMsg, transformCoords(), QgsPoint::x(), and QgsPoint::y().

Referenced by QgsDistanceArea::bearing(), QgsDistanceArea::measureLine(), QgsDistanceArea::measurePolygon(), QgsLabel::renderLabel(), and transform().

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:
x x cordinate of point to transform
y y coordinate of point to transform
direction TransformDirection (defaults to ForwardTransform)
Returns:
QgsPoint in Destination Coordinate System

Definition at line 235 of file qgscoordinatetransform.cpp.

References QgsDebugMsg, and transform().

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:
theRect rect to transform
direction TransformDirection (defaults to ForwardTransform)
Returns:
QgsRectangle in Destination Coordinate System

Definition at line 336 of file qgscoordinatetransform.cpp.

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

Referenced by QgsPALObjectPositionManager::findObjectPositions().

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

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

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:
theRect rect to transform
direction TransformDirection (defaults to ForwardTransform)
Returns:
QgsRectangle in Destination Coordinate System

Definition at line 249 of file qgscoordinatetransform.cpp.

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

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:
numPoint number of coordinates in arrays
x array of x coordinates to transform
y array of y coordinates to transform
z array of z coordinates to transform
direction TransformDirection (defaults to ForwardTransform)
Returns:
QgsRectangle in Destination Coordinate System

Definition at line 410 of file qgscoordinatetransform.cpp.

References QgsLogger::critical(), ForwardTransform, invalidTransformInput(), QgsCoordinateReferenceSystem::isValid(), mDestCRS, mDestinationProjection, mSourceCRS, mSourceProjection, QgsDebugMsg, ReverseTransform, and QgsCoordinateReferenceSystem::toProj4().

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

bool QgsCoordinateTransform::isInitialised (  )  const [inline]

Flag to indicate whether the coordinate systems have been initialised

Returns:
true if initialised, otherwise false

Definition at line 186 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 191 of file qgscoordinatetransform.h.

Referenced by operator<<().

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

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

void QgsCoordinateTransform::initialise (  )  [slot]

bool QgsCoordinateTransform::readXML ( QDomNode &  theNode  )  [slot]

Restores state from the given Dom node.

Parameters:
theNode The node from which state will be restored
Returns:
bool True on success, False on failure

Definition at line 514 of file qgscoordinatetransform.cpp.

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

bool QgsCoordinateTransform::writeXML ( QDomNode &  theNode,
QDomDocument &  theDoc 
) [slot]

Stores state to the given Dom node in the given document

Parameters:
theNode The node in which state will be restored
theDoc The document in which state will be stored
Returns:
bool True on success, False on failure

Definition at line 530 of file qgscoordinatetransform.cpp.

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

void QgsCoordinateTransform::invalidTransformInput (  )  const [signal]

Signal when an invalid pj_transform() has occured.

Referenced by transformCoords().

void QgsCoordinateTransform::setFinder (  )  [private]

Finder for PROJ grid files.

Definition at line 558 of file qgscoordinatetransform.cpp.

References finder().

Referenced by QgsCoordinateTransform().


Member Data Documentation

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

Definition at line 231 of file qgscoordinatetransform.h.

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

flag to show whether the transform is properly initialised or not

Definition at line 236 of file qgscoordinatetransform.h.

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

QgsCoordinateReferenceSystem of the source (layer) coordinate system

Definition at line 241 of file qgscoordinatetransform.h.

Referenced by initialise(), QgsCoordinateTransform(), readXML(), setSourceCrs(), transformCoords(), and writeXML().

QgsCoordinateReferenceSystem of the destination (map canvas) coordinate system

Definition at line 246 of file qgscoordinatetransform.h.

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

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

Definition at line 251 of file qgscoordinatetransform.h.

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

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

Definition at line 256 of file qgscoordinatetransform.h.

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


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

Generated on Sat Feb 4 19:17:31 2012 for Quantum GIS API Documentation by  doxygen 1.5.6