Esempio 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))
Esempio n. 2
0
 def test_round_to_five_places(self):
     """
     Tests the conversion when using default rounding to five places.
     """
     actual = units.convert_meters_to_degrees(10000, places=5)
     expected = 0.08983
     self.assertEqual(actual, expected)
Esempio n. 3
0
 def test_round_up_to_five_places(self):
     """
     Tests the conversion when rounding up.
     """
     actual = units.convert_meters_to_degrees(10000, 'up', 5)
     expected = 0.08984
     self.assertEqual(actual, expected)
Esempio n. 4
0
 def test_round_down(self):
     """
     Tests the conversion when rounding down.
     """
     actual = units.convert_meters_to_degrees(10000, 'down')
     expected = 0.0898315
     self.assertEqual(actual, expected)
Esempio n. 5
0
 def test_round_closest(self):
     """
     Tests the conversion when rounding to the closest value.
     """
     actual = units.convert_meters_to_degrees(10000, 'closest')
     expected = 0.0898316
     self.assertEqual(actual, expected)
Esempio n. 6
0
 def test_default_result(self):
     """
     Tests the conversion using default values for rounding direction
     and decimal places.
     """
     actual = units.convert_meters_to_degrees(10000)
     expected = 0.0898316  # 0.089831566
     self.assertEqual(actual, expected)
Esempio n. 7
0
    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')