Subgroup: Coordinate
Class: QgsCoordinateTransformContext¶
-
class
qgis.core.
QgsCoordinateTransformContext
¶ Bases:
sip.wrapper
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().
Note
QgsCoordinateTransformContext objects are thread safe for read and write.
Note
QgsCoordinateTransformContext objects are implicitly shared.
See also
See also
New in version 3.0: Methods
addSourceDestinationDatumTransform
Adds a new sourceTransform
anddestinationTransform
to use when projecting coordinates from the the specifiedsourceCrs
to the specifieddestinationCrs
.calculateDatumTransforms
Returns the pair of source and destination datum transforms to use for a transform from the specified source
CRS todestination
CRS.clear
Clears all stored transform information from the context. hasTransform
Returns true if the context has a valid datum transform to use when transforming from the specified source
CRS todestination
CRS.readSettings
Reads the context’s state from application settings. readXml
Reads the context’s state from a DOM element
.removeSourceDestinationDatumTransform
Removes the source to destination datum transform pair for the specified sourceCrs
anddestinationCrs
.sourceDestinationDatumTransforms
Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use. writeSettings
Write the context’s state to application settings. writeXml
Writes the context’s state to a DOM element
.Attributes
-
addSourceDestinationDatumTransform
(self, sourceCrs: QgsCoordinateReferenceSystem, destinationCrs: QgsCoordinateReferenceSystem, sourceTransformId: int, destinationTransformId: int) → bool¶ Adds a new
sourceTransform
anddestinationTransform
to use when projecting coordinates from the the specifiedsourceCrs
to the specifieddestinationCrs
.If either
sourceTransformId
ordestinationTransformId
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.
Note
Transforms set using this method will override any specific source or destination transforms set by addSourceDatumTransform() or addDestinationDatumTransform().
See also
-
calculateDatumTransforms
(self, source: QgsCoordinateReferenceSystem, destination: QgsCoordinateReferenceSystem) → QgsDatumTransform.TransformPair¶ Returns the pair of source and destination datum transforms to use for a transform from the specified
source
CRS todestination
CRS.Returns an ID of -1 if a datum transform should not be used for the source or destination.
Note
source and destination are reversible.
-
clear
(self)¶ Clears all stored transform information from the context.
-
hasTransform
(self, source: QgsCoordinateReferenceSystem, destination: QgsCoordinateReferenceSystem) → bool¶ Returns true if the context has a valid datum transform to use when transforming from the specified
source
CRS todestination
CRS.Note
source and destination are reversible.
-
readSettings
(self)¶ Reads the context’s state from application settings.
See also
-
readXml
(self, element: QDomElement, context: QgsReadWriteContext) → Tuple[bool, List[str]]¶ 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.See also
-
removeSourceDestinationDatumTransform
(self, sourceCrs: QgsCoordinateReferenceSystem, destinationCrs: QgsCoordinateReferenceSystem)¶ Removes the source to destination datum transform pair for the specified
sourceCrs
anddestinationCrs
.See also
-
sourceDestinationDatumTransforms
(self) → object¶ Returns the stored mapping for source to destination CRS pairs to associated datum transforms to use. The map keys will be :py:func:`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.
Warning
This method should not be used to calculate the corresponding datum transforms to use for a coordinate transform. Instead, always use calculateDatumTransforms() to determine this.
See also
-
writeSettings
(self)¶ Write the context’s state to application settings.
See also
-