def test_merge_polygons(self): pg1 = Polygon([[(3, 4), (6, 4), (7, 6), (2, 5)]]) pg2 = Polygon([[(2, 4), (5, 4), (6, 6), (0, 5)]]) mp1 = Multipolygon([[[(0, 0), (9, 1), (5, 8)], [(1, 1), (6, 2), (3, 3)]], [[(3, 3), (4, 3), (4, 5), (4, 3)]]]) mp2 = Multipolygon([[[(1, 9), (6, 0), (9, 8)], [(4, 3), (4, 4), (5, 4)]], [[(6, 2), (7, 3), (8, 4), (7, 5)]]]) merged = Multipolygon.merge(pg1, mp1, pg2, mp2) self.assertEqual(len(merged), 6)
def test_multipolygon_empty_data(self): vertices = [] for i in range(5): sub = [] for j in range(5): sub.append((2 * j + i, -1.5 * j + 2 * i)) vertices.append([sub]) mp = Multipolygon(vertices, data={}) # constructor should override empty data dictionary to allow indexing [mp[i] for i in range(len(mp))]
def test_multipolygon(self): vertices = [] data = {"a": []} for i in range(5): sub = [] for j in range(5): sub.append((2 * j + i, -1.5 * j + 2 * i)) vertices.append([sub]) data["a"].append(i * j) Multipolygon(vertices, data=data)
def test_multipolygon_from_polygons(self): polys = [] for i in range(5): sub = [] for j in range(5): sub.append((2 * j + i, -1.5 * j + 2 * i)) polys.append(Polygon(sub, properties={"d": i * j}, crs=LonLatWGS84)) g = Multipolygon(polys) self.assertEqual(g.d["d"], [0, 4, 8, 12, 16]) self.assertEqual(g.crs, LonLatWGS84)
def test_multipolygon_from_polygons_constructor(self): polys = [] for i in range(5): sub = [] for j in range(5): sub.append((2 * j + i, -1.5 * j + 2 * i)) polys.append(Polygon(sub, crs=LonLatWGS84)) g = Multipolygon(polys) for p, p_ in zip(g, polys): self.assertEqual(p.vertices(), p_.vertices()) self.assertEqual(g.crs, LonLatWGS84)
def test_empty_multipolygon(self): mp = Multipolygon([]) self.assertEqual(len(mp), 0) return