Beispiel #1
0
 def _create_polygon(coordinates):
     """Create a polygon from the provided coordinates."""
     if coordinates:
         if len(coordinates) % 2 != 0:
             # Not even number of coordinates - chop last entry.
             coordinates = coordinates[0:len(coordinates) - 1]
         points = []
         for i in range(0, len(coordinates), 2):
             points.append(Point(coordinates[i], coordinates[i + 1]))
         return Polygon(points)
     return None
Beispiel #2
0
 def test_distance_to_polygon(self):
     """Test calculating distance to point."""
     home_coordinates = [-31.0, 150.0]
     mock_polygon = Polygon([
         Point(-30.0, 151.0),
         Point(-30.0, 151.5),
         Point(-30.5, 151.5),
         Point(-30.5, 151.0),
         Point(-30.0, 151.0)
     ])
     distance = GeoRssDistanceHelper.\
         distance_to_geometry(home_coordinates, mock_polygon)
     self.assertAlmostEqual(distance, 110.6, 1)
Beispiel #3
0
 def test_extract_coordinates_from_polygon(self):
     """Test extracting coordinates from polygon."""
     mock_polygon = Polygon([
         Point(-30.0, 151.0),
         Point(-30.0, 151.5),
         Point(-30.5, 151.5),
         Point(-30.5, 151.0),
         Point(-30.0, 151.0)
     ])
     latitude, longitude = GeoRssDistanceHelper.\
         extract_coordinates(mock_polygon)
     self.assertAlmostEqual(latitude, -30.2, 1)
     self.assertAlmostEqual(longitude, 151.2, 1)
Beispiel #4
0
 def test_polygon(self):
     """Test polygon."""
     polygon = Polygon([
         Point(-30.1, 150.1),
         Point(-30.2, 150.2),
         Point(-30.4, 150.4),
         Point(-30.8, 150.8),
         Point(-30.1, 150.1)
     ])
     assert len(polygon.points) == 5
     assert polygon.centroid.latitude == -30.32
     assert polygon.centroid.longitude == 150.32
     assert repr(polygon) == "<Polygon(centroid=" \
                             "<Point(latitude=-30.32, longitude=150.32)>)>"