Ejemplo n.º 1
0
    def test_radius_too_small(self):
        """
        Tests the function factor_polygon_into_circles for a radius of 10 m.
        """
        coord = ((0.0, -0.01), (0.0, 0.01),
                 (0.025, 0.01), (0.05, -0.01), (0.0, -0.01))
        radius_km = 0.01

        with self.assertRaises(ValueError):
            polygon = Polygon(coord)
            shapes.factor_polygon_into_circles(polygon, radius_km)
Ejemplo n.º 2
0
 def factor_by_radius_km(self, radius_km):
     """
     Takes a Location and a radius in kilometers. Returns a list of Locations
     representing circles of the specified radius that together cover the
     area of the original Location.
     """
     assert self.shape != 'Other', 'Shape must be Point, Polygon, or ' + \
                                   'Muiltpolygon'
     polygon = self.bbox
     points = shapes.factor_polygon_into_circles(polygon, radius_km)
     radius = units.km_to_meters(radius_km)
     return [self._create_radius(point, radius) for point in points]
Ejemplo n.º 3
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')