diff --git a/python/core/qgsrectangle.sip b/python/core/qgsrectangle.sip index 7f784fe3ea9..0a08aeda3c7 100644 --- a/python/core/qgsrectangle.sip +++ b/python/core/qgsrectangle.sip @@ -76,6 +76,9 @@ class QgsRectangle bool isEmpty() const; //! returns string representation in Wkt form QString asWktCoordinates() const; + //! returns string representation as WKT Polygon + //@note added om 2.0 + QString asWktPolygon() const; //! returns string representation of form xmin,ymin xmax,ymax QString toString(bool automaticPrecision = false) const; //! overloaded toString that allows precision of numbers to be set diff --git a/src/core/qgsrectangle.cpp b/src/core/qgsrectangle.cpp index 3dfdfda2f64..72316f7f1a3 100644 --- a/src/core/qgsrectangle.cpp +++ b/src/core/qgsrectangle.cpp @@ -184,6 +184,25 @@ QString QgsRectangle::asWktCoordinates() const return rep; } +QString QgsRectangle::asWktPolygon() const +{ + QString rep = + QString("POLYGON((") + + QString::number( xmin, 'f', 16 ) + " " + + QString::number( ymin, 'f', 16 ) + ", " + + QString::number( xmax, 'f', 16 ) + " " + + QString::number( ymin, 'f', 16 ) + ", " + + QString::number( xmax, 'f', 16 ) + " " + + QString::number( ymax, 'f', 16 ) + ", " + + QString::number( xmin, 'f', 16 ) + " " + + QString::number( ymax, 'f', 16 ) + ", " + + QString::number( xmin, 'f', 16 ) + " " + + QString::number( ymin, 'f', 16 ) + + QString("))"); + + return rep; +} + // Return a string representation of the rectangle with automatic or high precision QString QgsRectangle::toString( bool automaticPrecision ) const { diff --git a/src/core/qgsrectangle.h b/src/core/qgsrectangle.h index 50e06bc9aa8..ce5b5605182 100644 --- a/src/core/qgsrectangle.h +++ b/src/core/qgsrectangle.h @@ -97,6 +97,9 @@ class CORE_EXPORT QgsRectangle bool isEmpty() const; //! returns string representation in Wkt form QString asWktCoordinates() const; + //! returns string representation as WKT Polygon + //@note added om 2.0 + QString asWktPolygon() const; //! returns string representation of form xmin,ymin xmax,ymax QString toString( bool automaticPrecision = false ) const; //! overloaded toString that allows precision of numbers to be set diff --git a/tests/src/python/test_qgsrectangle.py b/tests/src/python/test_qgsrectangle.py index 928f2adafd1..06e0df5780a 100644 --- a/tests/src/python/test_qgsrectangle.py +++ b/tests/src/python/test_qgsrectangle.py @@ -10,9 +10,12 @@ QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() class TestQgsRectangle(unittest.TestCase): def testCtor(self): - rect = QgsRectangle( 5.0, 5.0, 10.0, 10.0) + rect = QgsRectangle(5.0, 5.0, 10.0, 10.0) - assert rect.isEmpty(), "Empty rectangle constructed" + myExpectedResult = True + myResult = rect.isEmpty() + myMessage = ('Expected: %s Got: %s' % (myExpectedResult, myResult)) + assert rect.isEmpty(), myMessage myMessage = ('Expected: %s\nGot: %s\n' % (5.0, rect.xMinimum())) @@ -65,15 +68,15 @@ class TestQgsRectangle(unittest.TestCase): assert rect1.intersects(rect2), myMessage rect3 = rect1.intersect(rect2) - assert rect3.isEmpty(), "Empty rectangle returned" + self.assertFalse(rect3.isEmpty(), "Empty rectangle returned") myMessage = ('Expected: %s\nGot: %s\n' % - (3.0, rect.width())) - assert rect.width() == 3.0, myMessage + (3.0, rect3.width())) + assert rect3.width() == 3.0, myMessage myMessage = ('Expected: %s\nGot: %s\n' % - (3.0, rect.height())) - assert rect.height() == 3.0, myMessage + (3.0, rect3.height())) + assert rect3.height() == 3.0, myMessage def testContains(self): rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0) @@ -106,15 +109,19 @@ class TestQgsRectangle(unittest.TestCase): myMessage = ('Expected: %s\nGot: %s\n' % (False, rect1.contains(pnt2))) - assert rect1.contains(pnt2), myMessage + self.assertFalse(rect1.contains(pnt2), myMessage) myMessage = ('Expected: %s\nGot: %s\n' % (True, rect2.contains(pnt2))) assert rect2.contains(pnt2), myMessage myMessage = ('Expected: %s\nGot: %s\n' % - (True, rect3.contains(pnt2))) - assert rect3.contains(pnt2), myMessage + (False, rect3.contains(pnt2))) + self.assertFalse(rect3.contains(pnt2), myMessage) + + myMessage = ('Expected: %s\nGot: %s\n' % + (True, rect3.contains(pnt1))) + self.assertTrue(rect3.contains(pnt1), myMessage) def testUnion(self): rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0) @@ -135,8 +142,11 @@ class TestQgsRectangle(unittest.TestCase): (True, rect1.contains(pnt1))) assert rect1.contains(pnt1), myMessage - print rect1.toString() - assert rect1 == QgsRectangle(0.0, 0.0, 6.0, 6.0), "Wrong combine with point result" + myExpectedResult = QgsRectangle(0.0, 0.0, 6.0, 5.0).toString() + myResult = rect1.toString() + myMessage = ('Expected: %s\nGot: %s\n' % + (myExpectedResult, myResult)) + self.assertEquals(myResult, myExpectedResult, myMessage) rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0) rect1.unionRect(rect2) @@ -145,3 +155,29 @@ class TestQgsRectangle(unittest.TestCase): assert rect1.contains(rect2), myMessage assert rect1 == QgsRectangle(0.0, 0.0, 7.0, 7.0), "Wrong union result" + + def testAsWktCoordinates(self): + """Test that we can get a proper wkt representation fo the rect""" + rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0) + myExpectedWkt = '0.0000000000000000 0.0000000000000000, 5.0000000000000000 5.0000000000000000' + myWkt = rect1.asWktCoordinates() + myMessage = ('Expected: %s\nGot: %s\n' % + (myExpectedWkt, myWkt)) + self.assertEquals(myWkt, myExpectedWkt, myMessage) + + def testAsWktPolygon(self): + """Test that we can get a proper wkt polygon representation fo the rect""" + rect1 = QgsRectangle( 0.0, 0.0, 5.0, 5.0) + myExpectedWkt = ('POLYGON((0.0000000000000000 0.0000000000000000, ' + '5.0000000000000000 0.0000000000000000, ' + '5.0000000000000000 5.0000000000000000, ' + '0.0000000000000000 5.0000000000000000, ' + '0.0000000000000000 0.0000000000000000))') + myWkt = rect1.asWktPolygon() + myMessage = ('Expected: %s\nGot: %s\n' % + (myExpectedWkt, myWkt)) + self.assertEquals(myWkt, myExpectedWkt, myMessage) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/testdata/raster/band1_byte_noct_epsg4326.tif.aux.xml b/tests/testdata/raster/band1_byte_noct_epsg4326.tif.aux.xml index 17baac178ae..8d316725af9 100644 --- a/tests/testdata/raster/band1_byte_noct_epsg4326.tif.aux.xml +++ b/tests/testdata/raster/band1_byte_noct_epsg4326.tif.aux.xml @@ -1,5 +1,15 @@ + + + -0.498046875 + 255.498046875 + 256 + 0 + 0 + 0|0|1|0|0|1|0|0|0|0|1|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|0|0|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|1|0|0|0|0|1|0|1|0|0|1|0|1|0|0|1|0|0|1|0|1|0|0|1|0|1|0|0|0|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|0|1|0|1|0|0|1|0|0|0|0|1|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|0|0|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|1|0|0|0|0|1|0|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|0|0|0|1|0|1|0|0|1|0|1|0|0|1|0|0|1|0|1|0|0|1|0|1|0|0|0|0|1|0|0|1|0|1|0|0|1|0|1|0|0|1|0|0|1|19 + + 2.000000e+00 1.280000e+02 0 255 0 255 255 0 1.280000e+02 2.540000e+02 255 255 0 255 0 0 diff --git a/tests/testdata/raster/band1_int16_noct_epsg4326.tif.aux.xml b/tests/testdata/raster/band1_int16_noct_epsg4326.tif.aux.xml index f5853a6bb7d..53e23a52c2e 100644 --- a/tests/testdata/raster/band1_int16_noct_epsg4326.tif.aux.xml +++ b/tests/testdata/raster/band1_int16_noct_epsg4326.tif.aux.xml @@ -1,5 +1,15 @@ + + + -32435.39 + 33091.39 + 100 + 0 + 0 + 1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1 + + -3.211166e+04 3.276700e+02 0 255 0 255 255 0 3.276700e+02 3.276700e+04 255 255 0 255 0 0 diff --git a/tests/testdata/raster/band3_float32_noct_epsg4326.tif.aux.xml b/tests/testdata/raster/band3_float32_noct_epsg4326.tif.aux.xml index 1510a2a22dc..14a99c52934 100644 --- a/tests/testdata/raster/band3_float32_noct_epsg4326.tif.aux.xml +++ b/tests/testdata/raster/band3_float32_noct_epsg4326.tif.aux.xml @@ -1,5 +1,15 @@ + + + -3.365659928167135e+38 + 3.433659951548935e+38 + 100 + 0 + 0 + 1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1 + + 0.000000e+00 0.000000e+00 255 127 0 255 127 0 1 @@ -10,6 +20,16 @@ + + + -3.365659928167135e+38 + 3.433659951548935e+38 + 100 + 0 + 0 + 1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1 + + 0.000000e+00 0.000000e+00 255 127 0 255 127 0 1 @@ -20,6 +40,16 @@ + + + -3.365659928167135e+38 + 3.433659951548935e+38 + 100 + 0 + 0 + 1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1 + + 0.000000e+00 0.000000e+00 255 127 0 255 127 0 1 diff --git a/tests/testdata/raster/band3_int16_noct_epsg4326.tif.aux.xml b/tests/testdata/raster/band3_int16_noct_epsg4326.tif.aux.xml index 98e30a7dc86..07afa9c3d80 100644 --- a/tests/testdata/raster/band3_int16_noct_epsg4326.tif.aux.xml +++ b/tests/testdata/raster/band3_int16_noct_epsg4326.tif.aux.xml @@ -1,5 +1,15 @@ + + + -32435.39 + 33091.39 + 100 + 0 + 0 + 1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1 + + -3.211166e+04 3.276700e+02 0 255 0 255 255 0 3.276700e+02 3.276700e+04 255 255 0 255 0 0 @@ -11,6 +21,16 @@ + + + -32435.39 + 33091.39 + 100 + 0 + 0 + 1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1 + + -3.211166e+04 3.276700e+02 0 255 0 255 255 0 3.276700e+02 3.276700e+04 255 255 0 255 0 0 @@ -22,6 +42,16 @@ + + + -32435.39 + 33091.39 + 100 + 0 + 0 + 1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1|1|1|0|1|1|1|1|1|1|1 + + -3.211166e+04 3.276700e+02 0 255 0 255 255 0 3.276700e+02 3.276700e+04 255 255 0 255 0 0