def test_radius_for_circle(self): """ Test case for a circle. """ circle = Location.objects.get(pk=2) actual = circle.radius_km expected = units.meters_to_km(circle.radius_km) self.assertTrue(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
def _process_parameters(self, coord, radius_m): """ Helper function to process test parameters through the factor_polygon_into_circles function. """ radius_km = units.meters_to_km(radius_m) polygon = Polygon(coord) points = shapes.factor_polygon_into_circles(polygon, radius_km) # take the generated points and turn them into "circles" (polygons) radius_in_deg = units.convert_meters_to_degrees(radius_m) circles = [Point(point).buffer(radius_in_deg) for point in points] # convert the list of circles into a multipolyon and merge them merged_circles = MultiPolygon(circles).cascaded_union # make sure the merged circles have no holes and completely cover # the original polygon self.assertTrue(merged_circles.num_interior_rings == 0, 'The merged circles had %s holes but should have none' % merged_circles.num_interior_rings) self.assertTrue(merged_circles.prepared.covers(polygon), 'The merged circles do not cover the polygon')
def test_float_input(self): """ Test case for floating point input. """ self.assertEqual(units.meters_to_km(0.5), 0.0005)
def test_10_meters(self): """ Test case for 10 meters. """ self.assertEqual(units.meters_to_km(10), 0.01)
def test_0_meters(self): """ Test case for 0 meters. """ self.assertEqual(units.meters_to_km(0), 0)