Skip to content

Commit 87b8a37

Browse files
committed
Expand QgsCoordinateTransform docs
1 parent 1e06abb commit 87b8a37

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

python/core/qgscoordinatetransform.sip

+20
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ The ``context`` argument specifies the context under which the transform
6262
will be applied, and is used for calculating necessary datum transforms
6363
to utilize.
6464

65+
Python scripts should generally use the constructor variant which accepts
66+
a QgsProject instance instead of this constructor.
67+
68+
\warning Do NOT use an empty/default constructed QgsCoordinateTransformContext()
69+
object when creating QgsCoordinateTransform objects. This prevents correct
70+
datum transform handling and may result in inaccurate transformations. Always
71+
ensure that the QgsCoordinateTransformContext object is correctly retrieved
72+
based on the current code context, or use the constructor variant which
73+
accepts a QgsProject argument instead.
74+
6575
.. versionadded:: 3.0
6676
%End
6777

@@ -76,6 +86,16 @@ given ``project``.
7686
No reference to ``project`` is stored or utilized outside of the constructor,
7787
and it is used to retrieve the project's transform context only.
7888

89+
Python scripts should utilise the QgsProject.instance() project
90+
instance when creating QgsCoordinateTransform. This will ensure
91+
that any datum transforms defined in the project will be
92+
correctly respected during coordinate transforms. E.g.
93+
94+
.. code-block:: python
95+
96+
transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem("EPSG:3111"),
97+
QgsCoordinateReferenceSystem("EPSG:4326"), QgsProject.instance())
98+
7999
.. versionadded:: 3.0
80100
%End
81101

src/core/qgscoordinatetransform.h

+20
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ class CORE_EXPORT QgsCoordinateTransform
8484
* will be applied, and is used for calculating necessary datum transforms
8585
* to utilize.
8686
*
87+
* Python scripts should generally use the constructor variant which accepts
88+
* a QgsProject instance instead of this constructor.
89+
*
90+
* \warning Do NOT use an empty/default constructed QgsCoordinateTransformContext()
91+
* object when creating QgsCoordinateTransform objects. This prevents correct
92+
* datum transform handling and may result in inaccurate transformations. Always
93+
* ensure that the QgsCoordinateTransformContext object is correctly retrieved
94+
* based on the current code context, or use the constructor variant which
95+
* accepts a QgsProject argument instead.
96+
*
8797
* \since QGIS 3.0
8898
*/
8999
explicit QgsCoordinateTransform( const QgsCoordinateReferenceSystem &source,
@@ -98,6 +108,16 @@ class CORE_EXPORT QgsCoordinateTransform
98108
* No reference to \a project is stored or utilized outside of the constructor,
99109
* and it is used to retrieve the project's transform context only.
100110
*
111+
* Python scripts should utilise the QgsProject.instance() project
112+
* instance when creating QgsCoordinateTransform. This will ensure
113+
* that any datum transforms defined in the project will be
114+
* correctly respected during coordinate transforms. E.g.
115+
*
116+
* \code{.py}
117+
* transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem("EPSG:3111"),
118+
* QgsCoordinateReferenceSystem("EPSG:4326"), QgsProject.instance())
119+
* \endcode
120+
*
101121
* \since QGIS 3.0
102122
*/
103123
explicit QgsCoordinateTransform( const QgsCoordinateReferenceSystem &source,

0 commit comments

Comments
 (0)