Skip to content

Commit

Permalink
[bugfix] Restore binding for QgsCoordinateTransform
Browse files Browse the repository at this point in the history
Fixes #17600

Binding was lost in commit 10d34ec
  • Loading branch information
elpaso committed Dec 11, 2017
1 parent 8302fc3 commit bfa857b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 10 additions & 0 deletions python/core/qgscoordinatetransform.sip
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ Default constructor, creates an invalid QgsCoordinateTransform.
\param direction transform direction (defaults to forward transformation)
%End

QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const;
%Docstring
Transforms a rectangle to the destination CRS.
If the direction is ForwardTransform then coordinates are transformed from source to destination,
otherwise points are transformed from destination to source CRS.
\param rectangle rectangle to transform
\param direction transform direction (defaults to ForwardTransform)
:return: transformed rectangle
:rtype: QgsRectangle
%End

void transformCoords( int numPoint, double *x, double *y, double *z, TransformDirection direction = ForwardTransform ) const;
%Docstring
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgscoordinatetransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class CORE_EXPORT QgsCoordinateTransform
* \param direction transform direction (defaults to ForwardTransform)
* \returns transformed rectangle
*/
QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const SIP_SKIP;
QgsRectangle transform( const QgsRectangle &rectangle, TransformDirection direction = ForwardTransform ) const;

/**
* Transform an array of coordinates to the destination CRS.
Expand Down
24 changes: 24 additions & 0 deletions tests/src/python/test_qgscoordinatetransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ def testTransformBoundingBox(self):
self.assertAlmostEqual(myExpectedValues[2], myProjectedExtent.xMaximum(), msg=myMessage)
self.assertAlmostEqual(myExpectedValues[3], myProjectedExtent.yMaximum(), msg=myMessage)

def testTransformQgsRectangle_Regression17600(self):
"""Test that rectangle transform is in the bindings"""
myExtent = QgsRectangle(-1797107, 4392148, 6025926, 6616304)
myGeoCrs = QgsCoordinateReferenceSystem()
myGeoCrs.createFromId(4326, QgsCoordinateReferenceSystem.EpsgCrsId)
myUtmCrs = QgsCoordinateReferenceSystem()
myUtmCrs.createFromId(3857, QgsCoordinateReferenceSystem.EpsgCrsId)
myXForm = QgsCoordinateTransform(myUtmCrs, myGeoCrs)
myTransformedExtent = myXForm.transform(myExtent)
myTransformedExtentForward = myXForm.transform(myExtent, QgsCoordinateTransform.ForwardTransform)
self.assertAlmostEquals(myTransformedExtentForward.xMaximum(), myTransformedExtent.xMaximum())
self.assertAlmostEquals(myTransformedExtentForward.xMinimum(), myTransformedExtent.xMinimum())
self.assertAlmostEquals(myTransformedExtentForward.yMaximum(), myTransformedExtent.yMaximum())
self.assertAlmostEquals(myTransformedExtentForward.yMinimum(), myTransformedExtent.yMinimum())
self.assertAlmostEquals(myTransformedExtentForward.xMaximum(), 54.13181426773211)
self.assertAlmostEquals(myTransformedExtentForward.xMinimum(), -16.14368685298181)
self.assertAlmostEquals(myTransformedExtentForward.yMaximum(), 50.971783118386895)
self.assertAlmostEquals(myTransformedExtentForward.yMinimum(), 36.66235970825241)
myTransformedExtentReverse = myXForm.transform(myTransformedExtent, QgsCoordinateTransform.ReverseTransform)
self.assertAlmostEquals(myTransformedExtentReverse.xMaximum(), myExtent.xMaximum())
self.assertAlmostEquals(myTransformedExtentReverse.xMinimum(), myExtent.xMinimum())
self.assertAlmostEquals(myTransformedExtentReverse.yMaximum(), myExtent.yMaximum())
self.assertAlmostEquals(myTransformedExtentReverse.yMinimum(), myExtent.yMinimum())


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

0 comments on commit bfa857b

Please sign in to comment.