Testing Polygon objects.
(self)
| 213 | prev = lr |
| 214 | |
| 215 | def test_polygons(self): |
| 216 | "Testing Polygon objects." |
| 217 | |
| 218 | # Testing `from_bbox` class method |
| 219 | bbox = (-180, -90, 180, 90) |
| 220 | p = OGRGeometry.from_bbox(bbox) |
| 221 | self.assertEqual(bbox, p.extent) |
| 222 | |
| 223 | prev = OGRGeometry("POINT(0 0)") |
| 224 | for p in self.geometries.polygons: |
| 225 | poly = OGRGeometry(p.wkt) |
| 226 | self.assertEqual(3, poly.geom_type) |
| 227 | self.assertEqual("POLYGON", poly.geom_name) |
| 228 | self.assertEqual(p.n_p, poly.point_count) |
| 229 | self.assertEqual(p.n_i + 1, len(poly)) |
| 230 | msg = "Index out of range when accessing rings of a polygon: %s." |
| 231 | with self.assertRaisesMessage(IndexError, msg % len(poly)): |
| 232 | poly.__getitem__(len(poly)) |
| 233 | |
| 234 | # Testing area & centroid. |
| 235 | self.assertAlmostEqual(p.area, poly.area, 9) |
| 236 | x, y = poly.centroid.tuple |
| 237 | self.assertAlmostEqual(p.centroid[0], x, 9) |
| 238 | self.assertAlmostEqual(p.centroid[1], y, 9) |
| 239 | |
| 240 | # Testing equivalence |
| 241 | self.assertEqual(poly, OGRGeometry(p.wkt)) |
| 242 | self.assertNotEqual(poly, prev) |
| 243 | |
| 244 | if p.ext_ring_cs: |
| 245 | ring = poly[0] |
| 246 | self.assertEqual(p.ext_ring_cs, ring.tuple) |
| 247 | self.assertEqual(p.ext_ring_cs, poly[0].tuple) |
| 248 | self.assertEqual(len(p.ext_ring_cs), ring.point_count) |
| 249 | |
| 250 | for r in poly: |
| 251 | self.assertEqual("LINEARRING", r.geom_name) |
| 252 | |
| 253 | def test_polygons_templates(self): |
| 254 | # Accessing Polygon attributes in templates should work. |
nothing calls this directly
no test coverage detected