Skip to content

Commit 61db97f

Browse files
authored
Merge pull request #5843 from elpaso/bugfix-17600-coordinatetransform-rectangle
[bugfix] Restore binding for QgsCoordinateTransform
2 parents 8302fc3 + bfa857b commit 61db97f

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

python/core/qgscoordinatetransform.sip

+10
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ Default constructor, creates an invalid QgsCoordinateTransform.
169169
\param direction transform direction (defaults to forward transformation)
170170
%End
171171

172+
QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const;
173+
%Docstring
174+
Transforms a rectangle to the destination CRS.
175+
If the direction is ForwardTransform then coordinates are transformed from source to destination,
176+
otherwise points are transformed from destination to source CRS.
177+
\param rectangle rectangle to transform
178+
\param direction transform direction (defaults to ForwardTransform)
179+
:return: transformed rectangle
180+
:rtype: QgsRectangle
181+
%End
172182

173183
void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
174184
%Docstring

src/core/qgscoordinatetransform.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class CORE_EXPORT QgsCoordinateTransform
239239
* \param direction transform direction (defaults to ForwardTransform)
240240
* \returns transformed rectangle
241241
*/
242-
QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
242+
QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const;
243243

244244
/**
245245
* Transform an array of coordinates to the destination CRS.

tests/src/python/test_qgscoordinatetransform.py

+24
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ def testTransformBoundingBox(self):
4747
self.assertAlmostEqual(myExpectedValues[2], myProjectedExtent.xMaximum(), msg=myMessage)
4848
self.assertAlmostEqual(myExpectedValues[3], myProjectedExtent.yMaximum(), msg=myMessage)
4949

50+
def testTransformQgsRectangle_Regression17600(self):
51+
"""Test that rectangle transform is in the bindings"""
52+
myExtent = QgsRectangle(-1797107, 4392148, 6025926, 6616304)
53+
myGeoCrs = QgsCoordinateReferenceSystem()
54+
myGeoCrs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
55+
myUtmCrs = QgsCoordinateReferenceSystem()
56+
myUtmCrs.createFromId(3857, QgsCoordinateReferenceSystem.EpsgCrsId)
57+
myXForm = QgsCoordinateTransform(myUtmCrs, myGeoCrs)
58+
myTransformedExtent = myXForm.transform(myExtent)
59+
myTransformedExtentForward = myXForm.transform(myExtent, QgsCoordinateTransform.ForwardTransform)
60+
self.assertAlmostEquals(myTransformedExtentForward.xMaximum(), myTransformedExtent.xMaximum())
61+
self.assertAlmostEquals(myTransformedExtentForward.xMinimum(), myTransformedExtent.xMinimum())
62+
self.assertAlmostEquals(myTransformedExtentForward.yMaximum(), myTransformedExtent.yMaximum())
63+
self.assertAlmostEquals(myTransformedExtentForward.yMinimum(), myTransformedExtent.yMinimum())
64+
self.assertAlmostEquals(myTransformedExtentForward.xMaximum(), 54.13181426773211)
65+
self.assertAlmostEquals(myTransformedExtentForward.xMinimum(), -16.14368685298181)
66+
self.assertAlmostEquals(myTransformedExtentForward.yMaximum(), 50.971783118386895)
67+
self.assertAlmostEquals(myTransformedExtentForward.yMinimum(), 36.66235970825241)
68+
myTransformedExtentReverse = myXForm.transform(myTransformedExtent, QgsCoordinateTransform.ReverseTransform)
69+
self.assertAlmostEquals(myTransformedExtentReverse.xMaximum(), myExtent.xMaximum())
70+
self.assertAlmostEquals(myTransformedExtentReverse.xMinimum(), myExtent.xMinimum())
71+
self.assertAlmostEquals(myTransformedExtentReverse.yMaximum(), myExtent.yMaximum())
72+
self.assertAlmostEquals(myTransformedExtentReverse.yMinimum(), myExtent.yMinimum())
73+
5074

5175
if __name__ == '__main__':
5276
unittest.main()

0 commit comments

Comments
 (0)