diff options
| author | Stanislav Karpov <stkrp@yandex.ru> | 2018-01-09 19:15:04 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-02-10 19:45:58 -0500 |
| commit | 6d794fb76212bb8a62fe2cd97cff173054e1c626 (patch) | |
| tree | a947f691b5c831f64b2759a46100c7e046df88dd /tests | |
| parent | 2162f0983de0dfe2178531638ce7ea56f54dd4e7 (diff) | |
Fixed #28960 -- Added GEOSGeometry.buffer_with_style().
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gis_tests/data/geometries.json | 18 | ||||
| -rw-r--r-- | tests/gis_tests/geos_tests/test_geos.py | 54 |
2 files changed, 63 insertions, 9 deletions
diff --git a/tests/gis_tests/data/geometries.json b/tests/gis_tests/data/geometries.json index b8b1c3eab3..7786f26e9b 100644 --- a/tests/gis_tests/data/geometries.json +++ b/tests/gis_tests/data/geometries.json @@ -78,6 +78,24 @@ "width": 2.0, "quadsegs": 8 } ], + "buffer_with_style_geoms": [ + {"wkt": "POINT (0 0)", + "buffer_wkt": "POLYGON EMPTY", + "width": 5.0, "end_cap_style": 2, "join_style": 2 + }, + {"wkt": "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "buffer_wkt": "POLYGON ((-2 -2, -2 12, 12 12, 12 -2, -2 -2))", + "width": 2.0, "end_cap_style": 2, "join_style": 2 + }, + {"wkt": "LINESTRING (0 0, 10 0)", + "buffer_wkt": "POLYGON ((10 2, 10 -2, 0 -2, 0 2, 10 2))", + "width": 2.0, "end_cap_style": 2, "join_style": 2 + }, + {"wkt": "LINESTRING (0 0, 10 0, 10 10, 0 10)", + "buffer_wkt": "POLYGON ((8 2, 8 8, 0 8, 0 12, 12 12, 12 -2, 0 -2, 0 2, 8 2))", + "width": 2.0, "end_cap_style": 2, "join_style": 2 + } + ], "relate_geoms": [ {"wkt_a": "MULTIPOINT(80 70, 20 20, 200 170, 140 120)", "wkt_b": "MULTIPOINT(80 170, 140 120, 200 80, 80 70)", diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 7488acbb3e..5f8d1c84b1 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -1,4 +1,5 @@ import ctypes +import itertools import json import pickle import random @@ -650,21 +651,56 @@ class GEOSTest(SimpleTestCase, TestDataMixin): self.assertEqual(d1, a) def test_buffer(self): - "Testing buffer()." - for bg in self.geometries.buffer_geoms: + bg = self.geometries.buffer_geoms[0] + g = fromstr(bg.wkt) + + # Can't use a floating-point for the number of quadsegs. + with self.assertRaises(ctypes.ArgumentError): + g.buffer(bg.width, quadsegs=1.1) + + self._test_buffer(self.geometries.buffer_geoms, 'buffer') + + def test_buffer_with_style(self): + bg = self.geometries.buffer_with_style_geoms[0] + g = fromstr(bg.wkt) + + # Can't use a floating-point for the number of quadsegs. + with self.assertRaises(ctypes.ArgumentError): + g.buffer_with_style(bg.width, quadsegs=1.1) + + # Can't use a floating-point for the end cap style. + with self.assertRaises(ctypes.ArgumentError): + g.buffer_with_style(bg.width, end_cap_style=1.2) + # Can't use a end cap style that is not in the enum. + with self.assertRaises(GEOSException): + g.buffer_with_style(bg.width, end_cap_style=55) + + # Can't use a floating-point for the join style. + with self.assertRaises(ctypes.ArgumentError): + g.buffer_with_style(bg.width, join_style=1.3) + # Can't use a join style that is not in the enum. + with self.assertRaises(GEOSException): + g.buffer_with_style(bg.width, join_style=66) + + self._test_buffer( + itertools.chain(self.geometries.buffer_geoms, self.geometries.buffer_with_style_geoms), + 'buffer_with_style', + ) + + def _test_buffer(self, geometries, buffer_method_name): + for bg in geometries: g = fromstr(bg.wkt) # The buffer we expect exp_buf = fromstr(bg.buffer_wkt) - quadsegs = bg.quadsegs - width = bg.width - - # Can't use a floating-point for the number of quadsegs. - with self.assertRaises(ctypes.ArgumentError): - g.buffer(width, float(quadsegs)) # Constructing our buffer - buf = g.buffer(width, quadsegs) + buf_kwargs = { + kwarg_name: getattr(bg, kwarg_name) + for kwarg_name in ('width', 'quadsegs', 'end_cap_style', 'join_style', 'mitre_limit') + if hasattr(bg, kwarg_name) + } + buf = getattr(g, buffer_method_name)(**buf_kwargs) self.assertEqual(exp_buf.num_coords, buf.num_coords) self.assertEqual(len(exp_buf), len(buf)) |
