Beispiel #1
0
 def test_radius_for_rectangle(self):
     """
     Tests the function calculate_polygon_radius_km for a rectangle.
     """
     rectangle = Location.objects.get(pk=3)
     actual = shapes.calculate_polygon_radius_km(rectangle.geom)
     point = shapes.reverse_coordinate_order(rectangle.geom.centroid)
     expected = vincenty(point, (0, 1)).kilometers
     self.assertEqual(actual, expected)
Beispiel #2
0
 def test_radius_for_polygon(self):
     """
     Tests the function calculate_polygon_radius_km for a nonrectangular
     polygon.
     """
     polygon = Location.objects.get(pk=7)
     actual = shapes.calculate_polygon_radius_km(polygon.geom)
     point = shapes.reverse_coordinate_order(polygon.geom.centroid)
     expected = vincenty(point, (8, 0)).kilometers
     self.assertEqual(actual, expected)
Beispiel #3
0
    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