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())
def test_polygon_geojson(self): expected = {"coordinates": [ [[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]] ], "type": "Polygon"} polygon = geo.Polygon([ [[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]] ]) self.assertEqual(sorted(json.dumps(expected)), sorted(polygon.geojson()))
def test_polygon_from_points(self): expected = geo.Polygon([[[2.3, 57.32], [23.19, -20.2], [2.3, 57.32]]]) list_of_lists = [[ geo.Point(2.3, 57.32), geo.Point(23.19, -20.2), geo.Point(2.3, 57.32) ]] result = geo.Polygon.from_points(list_of_lists) self.assertIsInstance(result, geo.Polygon) self.assertEqual(expected.to_dict(), result.to_dict())
def test_polygon_to_dict(self): expected = { "coordinates": [[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]], "type": "Polygon" } p = geo.Polygon([[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]]) self.assertEqual(expected, p.to_dict())
def test_polygon_points(self): p = geo.Polygon([[[2.3, 57.32], [23.19, -20.2], [-120.4, 19.15], [2.3, 57.32]]]) result = p.points self.assertTrue(result) self.assertTrue(all([isinstance(p, geo.Point) for p in result]))