QgsCoordinateTransformContext class

Contains information about the context in which a coordinate transform is executed.

The context stores various information regarding which coordinate transforms should be used when transforming points from a source to destination coordinate reference system.

The highest priority transforms are those set using addSourceDestinationDatumTransform() and which the transform has a matching source to destination CRS pair.

Failing this, if the source CRS has a matching transform specified by addSourceDatumTransform() then this datum transform will be used. The same logic applies for destination CRS transforms set using addDestinationDatumTransform().

Constructors, destructors, conversion operators

QgsCoordinateTransformContext()
Constructor for QgsCoordinateTransformContext.
QgsCoordinateTransformContext(const QgsCoordinateTransformContext& rhs)
Copy constructor.

Public functions

auto addSourceDestinationDatumTransform(const QgsCoordinateReferenceSystem& sourceCrs, const QgsCoordinateReferenceSystem& destinationCrs, int sourceTransformId, int destinationTransformId) -> bool
Adds a new sourceTransform and destinationTransform to use when projecting coordinates from the specified sourceCrs to the specified destinationCrs.
auto calculateDatumTransforms(const QgsCoordinateReferenceSystem& source, const QgsCoordinateReferenceSystem& destination) const -> QgsDatumTransform::TransformPair
Returns the pair of source and destination datum transforms to use for a transform from the specified source CRS to destination CRS.
void clear()
Clears all stored transform information from the context.
auto hasTransform(const QgsCoordinateReferenceSystem& source, const QgsCoordinateReferenceSystem& destination) const -> bool
Returns true if the context has a valid datum transform to use when transforming from the specified source CRS to destination CRS.
auto operator=(const QgsCoordinateTransformContext& rhs) -> QgsCoordinateTransformContext&
Assignment operator.
void readSettings()
Reads the context's state from application settings.
auto readXml(const QDomElement& element, const QgsReadWriteContext& context, QStringList& missingTransforms) -> bool
Reads the context's state from a DOM element.
void removeSourceDestinationDatumTransform(const QgsCoordinateReferenceSystem& sourceCrs, const QgsCoordinateReferenceSystem& destinationCrs)
Removes the source to destination datum transform pair for the specified sourceCrs and destinationCrs.
auto sourceDestinationDatumTransforms() const -> QMap<QPair<QString, QString>, QgsDatumTransform::TransformPair>
Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use.
void writeSettings()
Write the context's state to application settings.
void writeXml(QDomElement& element, const QgsReadWriteContext& context) const
Writes the context's state to a DOM element.

Function documentation

bool QgsCoordinateTransformContext::addSourceDestinationDatumTransform(const QgsCoordinateReferenceSystem& sourceCrs, const QgsCoordinateReferenceSystem& destinationCrs, int sourceTransformId, int destinationTransformId)

Adds a new sourceTransform and destinationTransform to use when projecting coordinates from the specified sourceCrs to the specified destinationCrs.

If either sourceTransformId or destinationTransformId is -1, then no datum transform is required for transformations for that source or destination.

Returns true if the new transform pair was added successfully.

QgsDatumTransform::TransformPair QgsCoordinateTransformContext::calculateDatumTransforms(const QgsCoordinateReferenceSystem& source, const QgsCoordinateReferenceSystem& destination) const

Returns the pair of source and destination datum transforms to use for a transform from the specified source CRS to destination CRS.

Returns an ID of -1 if a datum transform should not be used for the source or destination.

bool QgsCoordinateTransformContext::hasTransform(const QgsCoordinateReferenceSystem& source, const QgsCoordinateReferenceSystem& destination) const

Returns true if the context has a valid datum transform to use when transforming from the specified source CRS to destination CRS.

void QgsCoordinateTransformContext::readSettings()

Reads the context's state from application settings.

bool QgsCoordinateTransformContext::readXml(const QDomElement& element, const QgsReadWriteContext& context, QStringList& missingTransforms)

Reads the context's state from a DOM element.

Returns false if transforms stored in the XML are not available. In this case missingTransforms will be filled with missing datum transform strings.

void QgsCoordinateTransformContext::removeSourceDestinationDatumTransform(const QgsCoordinateReferenceSystem& sourceCrs, const QgsCoordinateReferenceSystem& destinationCrs)

Removes the source to destination datum transform pair for the specified sourceCrs and destinationCrs.

QMap<QPair<QString, QString>, QgsDatumTransform::TransformPair> QgsCoordinateTransformContext::sourceDestinationDatumTransforms() const

Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use.

The map keys will be QgsCoordinateReferenceSystems::authid()s.

If either the source transform ID or destination transform ID is -1, then no datum transform is required for transformations for that source or destination.

void QgsCoordinateTransformContext::writeSettings()

Write the context's state to application settings.

void QgsCoordinateTransformContext::writeXml(QDomElement& element, const QgsReadWriteContext& context) const

Writes the context's state to a DOM element.