Ejemplo n.º 1
0
    def test_at_equator(self):
        """
        Tests the function convert_circle_to_rectangle at the Equator.
        This makes it easier to calculate expected values.
        """
        coord = (-78.0, 0)
        radius_m = 10000
        square = shapes.convert_circle_to_rectangle(coord, radius_m)

        # check that the shape is correct
        self.assertEqual(shapes.is_rectangle(square[0]), True,
                         'Shape is not a rectangle')

        # check that the rectangle center is at the original point
        bounds = Bounds(*square.extent)
        self.assertAlmostEqual(square.centroid[0], coord[0], places=6,
                               msg='The center longitude is incorrect')
        self.assertAlmostEqual(square.centroid[1], coord[1], places=6,
                               msg='The center latitude is incorrect')

        # check that rectangle has the correct area
        area_in_sq_m = bounds.center_width_m * bounds.height_m
        actual_sq_km = units.sq_meters_to_sq_km(area_in_sq_m)
        expected_sq_km = (2 * radius_m / 1000)**2
        self.assertAlmostEqual(actual_sq_km, expected_sq_km, delta=0.001)

        # check that the rectangle contains the circle
        radius_in_degrees = units.convert_meters_to_degrees(radius_m, 'down')
        point = Point(coord)
        circle = point.buffer(radius_in_degrees)
        self.assertTrue(square.contains(circle))
Ejemplo n.º 2
0
 def test_1000_sq_meters(self):
     """
     Test case for 1000 square meters.
     """
     self.assertEqual(units.sq_meters_to_sq_km(1000), 0.001)
Ejemplo n.º 3
0
 def test_float_input(self):
     """
     Test case for floating point input.
     """
     self.assertEqual(units.sq_meters_to_sq_km(0.5), 0.0000005)
Ejemplo n.º 4
0
 def test_0_sq_meters(self):
     """
     Test case for 0 square meters.
     """
     self.assertEqual(units.sq_meters_to_sq_km(0), 0)