def test_multipolygon_as_dict(self): expected = {"coordinates": [ [[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]], [[[6.3, 77.32], [13.19, -30.2], [-110.4, 17.15], [6.3, 77.32]]] ], "type": "MultiPolygon"} mp = geo.MultiPolygon([ [[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]], [[[6.3, 77.32], [13.19, -30.2], [-110.4, 17.15], [6.3, 77.32]]] ]) self.assertEqual(expected, mp.as_dict())
def test_multipolygon_geojson(self): expected = {"coordinates": [ [[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]], [[[6.3, 77.32], [13.19, -30.2], [-110.4, 17.15], [6.3, 77.32]]] ], "type": "MultiPolygon"} mp = geo.MultiPolygon([ [[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]], [[[6.3, 77.32], [13.19, -30.2], [-110.4, 17.15], [6.3, 77.32]]] ]) self.assertEqual(sorted(json.dumps(expected)), sorted(mp.geojson()))
def test_from_polygons(self): expected = geo.MultiPolygon([ [[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]], [[[6.3, 77.32], [13.19, -30.2], [-110.4, 17.15], [6.3, 77.32]]] ]) iterable_of_polygons = [ geo.Polygon([[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]]), geo.Polygon([[[6.3, 77.32], [13.19, -30.2], [-110.4, 17.15], [6.3, 77.32]]]) ] result = geo.MultiPolygon.from_polygons(iterable_of_polygons) self.assertIsInstance(result, geo.MultiPolygon) self.assertEqual(expected.as_dict(), result.as_dict())