QGIS API Documentation
2.2.0-Valmiera
|
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 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. |
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. | |
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) |
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. |
Static Private Member Functions | |
static QString | stripDatumTransform (const QString &proj4) |
Removes +nadgrids and +towgs84 from proj4 string. | |
static void | searchDatumTransform (const QString &sql, QList< int > &transforms) |
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.
Enum used to indicate the direction (forward or inverse) of the transform.
ForwardTransform |
Transform from source to destination CRS. |
ReverseTransform |
Transform from destination to source CRS. |
Definition at line 94 of file qgscoordinatetransform.h.
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.
theSource | CRS, typically of the layer's coordinate system |
theDest | CRS, 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
theSourceWkt | Wkt, typically of the layer's coordinate system |
theDestWkt | Wkt, 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
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 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.
|
private |
In certain situations, null grid shifts have to be added to src / dst proj string.
Definition at line 987 of file qgscoordinatetransform.cpp.
References QgsCoordinateReferenceSystem::authid(), mDestCRS, mDestinationDatumTransform, mSourceCRS, and mSourceDatumTransform.
Referenced by initialise().
QgsCoordinateTransform * QgsCoordinateTransform::clone | ( | ) | const |
Definition at line 130 of file qgscoordinatetransform.cpp.
References destCRS(), destinationDatumTransform(), initialise(), QgsCoordinateTransform(), setDestinationDatumTransform(), setSourceDatumTransform(), sourceCrs(), sourceDatumTransform(), and tr.
Referenced by QgsPalLabeling::addDiagramLayer(), and QgsPalLabeling::prepareLayer().
|
static |
Returns list of datum transformations for the given src and dest CRS.
Definition at line 771 of file qgscoordinatetransform.cpp.
References QgsCoordinateReferenceSystem::geographicCRSAuthId(), and searchDatumTransform().
Referenced by QgsMapCanvas::getDatumTransformInfo().
|
static |
Gets name of source and dest geographical CRS (to show in a tooltip)
Definition at line 940 of file qgscoordinatetransform.cpp.
References QgsCoordinateReferenceSystem::createFromOgcWmsCrs(), QgsCoordinateReferenceSystem::description(), and QgsApplication::srsDbFilePath().
Referenced by QgsDatumTransformDialog::load().
|
static |
Definition at line 886 of file qgscoordinatetransform.cpp.
References QgsApplication::srsDbFilePath().
Referenced by initialise(), and QgsDatumTransformDialog::load().
|
inline |
Get the QgsCoordinateReferenceSystem representation of the map canvas coordinate system
Definition at line 122 of file qgscoordinatetransform.h.
Referenced by QgsDistanceArea::_copy(), clone(), QgsVectorFileWriter::createSymbolLayerTable(), QgsRasterLayer::draw(), QgsVectorFileWriter::exportFeaturesSymbolLevels(), QgsDistanceArea::measureLine(), operator<<(), QgsMapRenderer::outputExtentToLayerExtent(), and QgsVectorFileWriter::writeAsVectorFormat().
|
inline |
Definition at line 227 of file qgscoordinatetransform.h.
Referenced by clone(), and QgsRasterLayer::draw().
|
slot |
initialise is used to actually create the Transformer instance
Definition at line 159 of file qgscoordinatetransform.cpp.
References addNullGridShifts(), QgsCoordinateReferenceSystem::authid(), QgsCRSCache::crsByAuthId(), datumTransformString(), QgsCRSCache::instance(), QgsCoordinateReferenceSystem::isValid(), mDestCRS, mDestinationDatumTransform, mDestinationProjection, mInitialisedFlag, mShortCircuit, mSourceCRS, mSourceDatumTransform, mSourceProjection, QgsDebugMsg, QgsDebugMsgLevel, stripDatumTransform(), and QgsCoordinateReferenceSystem::toProj4().
Referenced by clone(), QgsCoordinateTransform(), readXML(), setDestCRS(), setDestCRSID(), setSourceCrs(), and QgsCoordinateTransformCache::transform().
|
signal |
Signal when an invalid pj_transform() has occured.
Referenced by transformCoords().
|
inline |
Flag to indicate whether the coordinate systems have been initialised
Definition at line 198 of file qgscoordinatetransform.h.
Referenced by operator<<().
|
inline |
See if the transform short circuits because src and dest are equivalent
Definition at line 203 of file qgscoordinatetransform.h.
Referenced by operator<<().
|
slot |
Restores state from the given Dom node.
theNode | The node from which state will be restored |
Definition at line 704 of file qgscoordinatetransform.cpp.
References initialise(), mDestCRS, mDestinationDatumTransform, mSourceCRS, mSourceDatumTransform, QgsDebugMsg, and QgsCoordinateReferenceSystem::readXML().
|
staticprivate |
Definition at line 859 of file qgscoordinatetransform.cpp.
References QgsApplication::srsDbFilePath().
Referenced by datumTransformations().
void QgsCoordinateTransform::setDestCRS | ( | const QgsCoordinateReferenceSystem & | theCRS | ) |
Mutator for dest QgsCoordinateReferenceSystem
theCRS | of the destination coordinate system |
Definition at line 144 of file qgscoordinatetransform.cpp.
References initialise(), and mDestCRS.
Referenced by QgsAtlasComposition::computeExtent(), 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.
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.
|
inline |
Definition at line 228 of file qgscoordinatetransform.h.
Referenced by clone(), and QgsCoordinateTransformCache::transform().
|
private |
Finder for PROJ grid files.
Definition at line 755 of file qgscoordinatetransform.cpp.
References finder().
Referenced by QgsCoordinateTransform().
void QgsCoordinateTransform::setSourceCrs | ( | const QgsCoordinateReferenceSystem & | theCRS | ) |
Set the source (layer) QgsCoordinateReferenceSystem
theCRS | QgsCoordinateReferenceSystem representation of the layer's coordinate system |
Definition at line 139 of file qgscoordinatetransform.cpp.
References initialise(), and mSourceCRS.
Referenced by QgsAtlasComposition::computeExtent(), QgsDistanceArea::setSourceAuthId(), and QgsDistanceArea::setSourceCrs().
|
inline |
Definition at line 226 of file qgscoordinatetransform.h.
Referenced by clone(), and QgsCoordinateTransformCache::transform().
|
inline |
Get the QgsCoordinateReferenceSystem representation of the layer's coordinate system
Definition at line 116 of file qgscoordinatetransform.h.
Referenced by QgsDistanceArea::_copy(), clone(), QgsDistanceArea::convertMeasurement(), QgsVectorLayer::draw(), QgsDistanceArea::measureLine(), operator<<(), and QgsMapRenderer::outputExtentToLayerExtent().
|
inline |
Definition at line 225 of file qgscoordinatetransform.h.
Referenced by clone(), and QgsRasterLayer::draw().
|
staticprivate |
Removes +nadgrids and +towgs84 from proj4 string.
Definition at line 839 of file qgscoordinatetransform.cpp.
Referenced by initialise().
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.
p | Point to transform |
direction | TransformDirection (defaults to ForwardTransform) |
Definition at line 276 of file qgscoordinatetransform.cpp.
References mInitialisedFlag, mShortCircuit, QgsDebugMsg, transformCoords(), QgsPoint::x(), and QgsPoint::y().
Referenced by QgsDistanceArea::bearing(), QgsRasterProjector::calcCP(), QgsRasterProjector::checkCols(), QgsRasterProjector::checkRows(), QgsVectorLayer::draw(), QgsMapRenderer::layerToMapCoordinates(), QgsMapRenderer::mapToLayerCoordinates(), QgsDistanceArea::measureLine(), QgsDistanceArea::measurePolygon(), QgsLabel::renderLabel(), QgsRasterLayerSaveAsDialog::setResolution(), QgsMapRenderer::splitLayersExtent(), transform(), and transformBoundingBox().
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.
x | x cordinate of point to transform |
y | y coordinate of point to transform |
direction | TransformDirection (defaults to ForwardTransform) |
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.
theRect | rect to transform |
direction | TransformDirection (defaults to ForwardTransform) |
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.
theRect | rect to transform |
direction | TransformDirection (defaults to ForwardTransform) |
Definition at line 512 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 QgsRasterLayer::draw(), QgsMapRenderer::layerExtentToOutputExtent(), QgsMapRenderer::outputExtentToLayerExtent(), QgsMapRenderer::setDestinationCrs(), QgsRasterLayerSaveAsDialog::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.
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) |
Definition at line 598 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 |
Definition at line 349 of file qgscoordinatetransform.cpp.
References mInitialisedFlag, mShortCircuit, QgsDebugMsg, and transformCoords().
Referenced by QgsFeatureRendererV2::_getPoint(), QgsRasterProjector::preciseSrcRowCol(), QgsPalLabeling::registerDiagramFeature(), QgsPalLayerSettings::registerFeature(), and QgsGeometry::transformVertex().
void QgsCoordinateTransform::transformInPlace | ( | QVector< double > & | x, |
QVector< double > & | y, | ||
QVector< double > & | z, | ||
TransformDirection | direction = ForwardTransform |
||
) | const |
Definition at line 411 of file qgscoordinatetransform.cpp.
References mInitialisedFlag, mShortCircuit, QgsDebugMsg, and transformCoords().
void QgsCoordinateTransform::transformPolygon | ( | QPolygonF & | poly, |
TransformDirection | direction = ForwardTransform |
||
) | const |
Definition at line 370 of file qgscoordinatetransform.cpp.
References mInitialisedFlag, mShortCircuit, QgsDebugMsg, and transformCoords().
Referenced by QgsFeatureRendererV2::_getLineString(), and QgsFeatureRendererV2::_getPolygon().
|
slot |
Stores state to the given Dom node in the given document
theNode | The node in which state will be restored |
theDoc | The document in which state will be stored |
Definition at line 723 of file qgscoordinatetransform.cpp.
References mDestCRS, mDestinationDatumTransform, mSourceCRS, mSourceDatumTransform, and QgsCoordinateReferenceSystem::writeXML().
|
private |
QgsCoordinateReferenceSystem of the destination (map canvas) coordinate system
Definition at line 272 of file qgscoordinatetransform.h.
Referenced by addNullGridShifts(), initialise(), QgsCoordinateTransform(), readXML(), setDestCRS(), setDestCRSID(), transformCoords(), and writeXML().
|
private |
Definition at line 285 of file qgscoordinatetransform.h.
Referenced by addNullGridShifts(), initialise(), readXML(), and writeXML().
|
private |
Proj4 data structure of the destination projection (map canvas coordinate system)
Definition at line 282 of file qgscoordinatetransform.h.
Referenced by initialise(), transformCoords(), and ~QgsCoordinateTransform().
|
private |
flag to show whether the transform is properly initialised or not
Definition at line 262 of file qgscoordinatetransform.h.
Referenced by initialise(), transform(), transformBoundingBox(), transformInPlace(), and transformPolygon().
|
private |
Flag to indicate that the source and destination coordinate systems are equal and not transformation needs to be done
Definition at line 257 of file qgscoordinatetransform.h.
Referenced by initialise(), transform(), transformBoundingBox(), transformInPlace(), and transformPolygon().
|
private |
QgsCoordinateReferenceSystem of the source (layer) coordinate system
Definition at line 267 of file qgscoordinatetransform.h.
Referenced by addNullGridShifts(), initialise(), QgsCoordinateTransform(), readXML(), setSourceCrs(), transformCoords(), and writeXML().
|
private |
Definition at line 284 of file qgscoordinatetransform.h.
Referenced by addNullGridShifts(), initialise(), readXML(), and writeXML().
|
private |
Proj4 data structure of the source projection (layer coordinate system)
Definition at line 277 of file qgscoordinatetransform.h.
Referenced by initialise(), transformCoords(), and ~QgsCoordinateTransform().