diff options
| author | enprava <epradavazquez@gmail.com> | 2024-09-08 20:32:13 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2025-02-23 16:20:57 +0100 |
| commit | 51cab4ad51616f8fdb050631be5c710b93685ec3 (patch) | |
| tree | f4168e005509a61a5bba0bbd66991df6a309ece3 /tests/gis_tests | |
| parent | f7017db92cee1536c014710f475a613792c1e4b5 (diff) | |
Fixed #35705 -- Added Rotate GIS database function to rotate geometries.
Diffstat (limited to 'tests/gis_tests')
| -rw-r--r-- | tests/gis_tests/geoapp/test_functions.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index 80b08f8d39..3e881b41dc 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -612,6 +612,41 @@ class GISFunctionsTests(FuncTestMixin, TestCase): coords.reverse() self.assertEqual(tuple(coords), track.reverse_geom.coords) + @skipUnlessDBFeature("has_Rotate_function") + def test_rotate(self): + angle = math.pi + tests = [ + {"angle": angle}, + {"angle": angle, "origin": Point(0, 0)}, + {"angle": angle, "origin": Point(1, 1)}, + ] + for params in tests: + with self.subTest(params=params): + qs = Country.objects.annotate( + rotated=functions.Rotate("mpoly", **params) + ) + for country in qs: + for p1, p2 in zip(country.mpoly, country.rotated): + for r1, r2 in zip(p1, p2): + for c1, c2 in zip(r1.coords, r2.coords): + origin = params.get("origin") + if origin is None: + origin = Point(0, 0) + self.assertAlmostEqual(-c1[0] + 2 * origin.x, c2[0], 5) + self.assertAlmostEqual(-c1[1] + 2 * origin.y, c2[1], 5) + + @skipUnlessDBFeature("has_Rotate_function") + def test_rotate_invalid_params(self): + angle = math.pi + bad_params_tests = [ + {"angle": angle, "origin": 0}, + {"angle": angle, "origin": [0, 0]}, + ] + msg = "origin argument must be a Point" + for params in bad_params_tests: + with self.subTest(params=params), self.assertRaisesMessage(TypeError, msg): + functions.Rotate("mpoly", **params) + @skipUnlessDBFeature("has_Scale_function") def test_scale(self): xfac, yfac = 2, 3 |
