mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Improved iteration of geometries in GEOS tests.
This commit is contained in:
parent
a902233d8b
commit
8f01de7c83
@ -760,22 +760,18 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
|||||||
) # Making sure __len__ works
|
) # Making sure __len__ works
|
||||||
|
|
||||||
# Checks __getitem__ and __setitem__
|
# Checks __getitem__ and __setitem__
|
||||||
for i in range(len(p.ext_ring_cs)):
|
for expected_value, coord_sequence in zip(p.ext_ring_cs, cs):
|
||||||
c1 = p.ext_ring_cs[i] # Expected value
|
self.assertEqual(expected_value, coord_sequence)
|
||||||
c2 = cs[i] # Value from coordseq
|
|
||||||
self.assertEqual(c1, c2)
|
|
||||||
|
|
||||||
# Construct the test value to set the coordinate sequence with
|
# Construct the test value to set the coordinate sequence with
|
||||||
if len(c1) == 2:
|
if len(expected_value) == 2:
|
||||||
tset = (5, 23)
|
tset = (5, 23)
|
||||||
else:
|
else:
|
||||||
tset = (5, 23, 8)
|
tset = (5, 23, 8)
|
||||||
cs[i] = tset
|
coord_sequence = tset
|
||||||
|
|
||||||
# Making sure every set point matches what we expect
|
# Making sure every set point matches what we expect
|
||||||
for j in range(len(tset)):
|
self.assertEqual(tset, coord_sequence)
|
||||||
cs[i] = tset
|
|
||||||
self.assertEqual(tset[j], cs[i][j])
|
|
||||||
|
|
||||||
def test_relate_pattern(self):
|
def test_relate_pattern(self):
|
||||||
"Testing relate() and relate_pattern()."
|
"Testing relate() and relate_pattern()."
|
||||||
@ -792,11 +788,13 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
|||||||
|
|
||||||
def test_intersection(self):
|
def test_intersection(self):
|
||||||
"Testing intersects() and intersection()."
|
"Testing intersects() and intersection()."
|
||||||
for i in range(len(self.geometries.topology_geoms)):
|
for topology_geom, intersect_geom in zip(
|
||||||
with self.subTest(i=i):
|
self.geometries.topology_geoms, self.geometries.intersect_geoms
|
||||||
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
):
|
||||||
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
with self.subTest(topology_geom=topology_geom):
|
||||||
i1 = fromstr(self.geometries.intersect_geoms[i].wkt)
|
a = fromstr(topology_geom.wkt_a)
|
||||||
|
b = fromstr(topology_geom.wkt_b)
|
||||||
|
i1 = fromstr(intersect_geom.wkt)
|
||||||
self.assertIs(a.intersects(b), True)
|
self.assertIs(a.intersects(b), True)
|
||||||
i2 = a.intersection(b)
|
i2 = a.intersection(b)
|
||||||
self.assertTrue(i1.equals(i2))
|
self.assertTrue(i1.equals(i2))
|
||||||
@ -806,11 +804,13 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
|||||||
|
|
||||||
def test_union(self):
|
def test_union(self):
|
||||||
"Testing union()."
|
"Testing union()."
|
||||||
for i in range(len(self.geometries.topology_geoms)):
|
for topology_geom, union_geom in zip(
|
||||||
with self.subTest(i=i):
|
self.geometries.topology_geoms, self.geometries.union_geoms
|
||||||
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
):
|
||||||
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
with self.subTest(topology_geom=topology_geom):
|
||||||
u1 = fromstr(self.geometries.union_geoms[i].wkt)
|
a = fromstr(topology_geom.wkt_a)
|
||||||
|
b = fromstr(topology_geom.wkt_b)
|
||||||
|
u1 = fromstr(union_geom.wkt)
|
||||||
u2 = a.union(b)
|
u2 = a.union(b)
|
||||||
self.assertTrue(u1.equals(u2))
|
self.assertTrue(u1.equals(u2))
|
||||||
self.assertTrue(u1.equals(a | b)) # __or__ is union operator
|
self.assertTrue(u1.equals(a | b)) # __or__ is union operator
|
||||||
@ -819,21 +819,25 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
|||||||
|
|
||||||
def test_unary_union(self):
|
def test_unary_union(self):
|
||||||
"Testing unary_union."
|
"Testing unary_union."
|
||||||
for i in range(len(self.geometries.topology_geoms)):
|
for topology_geom, union_geom in zip(
|
||||||
with self.subTest(i=i):
|
self.geometries.topology_geoms, self.geometries.union_geoms
|
||||||
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
):
|
||||||
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
with self.subTest(topology_geom=topology_geom):
|
||||||
u1 = fromstr(self.geometries.union_geoms[i].wkt)
|
a = fromstr(topology_geom.wkt_a)
|
||||||
|
b = fromstr(topology_geom.wkt_b)
|
||||||
|
u1 = fromstr(union_geom.wkt)
|
||||||
u2 = GeometryCollection(a, b).unary_union
|
u2 = GeometryCollection(a, b).unary_union
|
||||||
self.assertTrue(u1.equals(u2))
|
self.assertTrue(u1.equals(u2))
|
||||||
|
|
||||||
def test_difference(self):
|
def test_difference(self):
|
||||||
"Testing difference()."
|
"Testing difference()."
|
||||||
for i in range(len(self.geometries.topology_geoms)):
|
for topology_geom, union_geom in zip(
|
||||||
with self.subTest(i=i):
|
self.geometries.topology_geoms, self.geometries.diff_geoms
|
||||||
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
):
|
||||||
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
with self.subTest(topology_geom=topology_geom):
|
||||||
d1 = fromstr(self.geometries.diff_geoms[i].wkt)
|
a = fromstr(topology_geom.wkt_a)
|
||||||
|
b = fromstr(topology_geom.wkt_b)
|
||||||
|
d1 = fromstr(union_geom.wkt)
|
||||||
d2 = a.difference(b)
|
d2 = a.difference(b)
|
||||||
self.assertTrue(d1.equals(d2))
|
self.assertTrue(d1.equals(d2))
|
||||||
self.assertTrue(d1.equals(a - b)) # __sub__ is difference operator
|
self.assertTrue(d1.equals(a - b)) # __sub__ is difference operator
|
||||||
@ -842,11 +846,13 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
|||||||
|
|
||||||
def test_symdifference(self):
|
def test_symdifference(self):
|
||||||
"Testing sym_difference()."
|
"Testing sym_difference()."
|
||||||
for i in range(len(self.geometries.topology_geoms)):
|
for topology_geom, sdiff_geom in zip(
|
||||||
with self.subTest(i=i):
|
self.geometries.topology_geoms, self.geometries.sdiff_geoms
|
||||||
a = fromstr(self.geometries.topology_geoms[i].wkt_a)
|
):
|
||||||
b = fromstr(self.geometries.topology_geoms[i].wkt_b)
|
with self.subTest(topology_geom=topology_geom):
|
||||||
d1 = fromstr(self.geometries.sdiff_geoms[i].wkt)
|
a = fromstr(topology_geom.wkt_a)
|
||||||
|
b = fromstr(topology_geom.wkt_b)
|
||||||
|
d1 = fromstr(sdiff_geom.wkt)
|
||||||
d2 = a.sym_difference(b)
|
d2 = a.sym_difference(b)
|
||||||
self.assertTrue(d1.equals(d2))
|
self.assertTrue(d1.equals(d2))
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
@ -955,15 +961,12 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
|||||||
self.assertEqual(len(exp_buf), len(buf))
|
self.assertEqual(len(exp_buf), len(buf))
|
||||||
|
|
||||||
# Now assuring that each point in the buffer is almost equal
|
# Now assuring that each point in the buffer is almost equal
|
||||||
for j in range(len(exp_buf)):
|
for exp_ring, buf_ring in zip(exp_buf, buf, strict=True):
|
||||||
exp_ring = exp_buf[j]
|
for exp_point, buf_point in zip(exp_ring, buf_ring, strict=True):
|
||||||
buf_ring = buf[j]
|
|
||||||
self.assertEqual(len(exp_ring), len(buf_ring))
|
|
||||||
for k in range(len(exp_ring)):
|
|
||||||
# Asserting the X, Y of each point are almost equal (due to
|
# Asserting the X, Y of each point are almost equal (due to
|
||||||
# floating point imprecision).
|
# floating point imprecision).
|
||||||
self.assertAlmostEqual(exp_ring[k][0], buf_ring[k][0], 9)
|
self.assertAlmostEqual(exp_point[0], buf_point[0], 9)
|
||||||
self.assertAlmostEqual(exp_ring[k][1], buf_ring[k][1], 9)
|
self.assertAlmostEqual(exp_point[1], buf_point[1], 9)
|
||||||
|
|
||||||
def test_covers(self):
|
def test_covers(self):
|
||||||
poly = Polygon(((0, 0), (0, 10), (10, 10), (10, 0), (0, 0)))
|
poly = Polygon(((0, 0), (0, 10), (10, 10), (10, 0), (0, 0)))
|
||||||
@ -1007,9 +1010,9 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
|||||||
Point(5, 23), LineString((0, 0), (1.5, 1.5), (3, 3)), srid=32021
|
Point(5, 23), LineString((0, 0), (1.5, 1.5), (3, 3)), srid=32021
|
||||||
)
|
)
|
||||||
self.assertEqual(32021, gc.srid)
|
self.assertEqual(32021, gc.srid)
|
||||||
for i in range(len(gc)):
|
for geom in gc:
|
||||||
with self.subTest(i=i):
|
with self.subTest(geom=geom):
|
||||||
self.assertEqual(32021, gc[i].srid)
|
self.assertEqual(32021, geom.srid)
|
||||||
|
|
||||||
# GEOS may get the SRID from HEXEWKB
|
# GEOS may get the SRID from HEXEWKB
|
||||||
# 'POINT(5 23)' at SRID=4326 in hex form -- obtained from PostGIS
|
# 'POINT(5 23)' at SRID=4326 in hex form -- obtained from PostGIS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user