def test_radius_for_multipolygon(self): """ Test case for a rectangle. """ multipolygon = Location.objects.get(pk=8) actual = shapes.calculate_multipoly_radius_km(multipolygon.geom) point = shapes.reverse_coordinate_order(multipolygon.geom.centroid) expected = vincenty(point, (20, 50)).kilometers self.assertEqual(actual, expected)
def radius_km(self): """ If the Location is a Circle, Rectangle, Polygon, or Multipolygon, returns the distance in kilometers between the geometry's centroid and the point on the geometry farthest from the centroid. Otherwise returns None. """ if self.shape is 'Circle': return units.meters_to_km(self.buffer_m) elif self.shape is 'Rectangle' or self.shape is 'Polygon': return shapes.calculate_polygon_radius_km(self.geom) elif self.shape is 'MultiPolygon': return shapes.calculate_multipoly_radius_km(self.geom) else: return None