예제 #1
0
    def test_rotation(self):
        "Check rotation works ok"
        # Generate some data to play with
        centre = Point([116.35, -42.01])
        box = make_box(centre, distance=10)
        theta = 34.  # degrees

        # Convert centre to a cartesian vector
        pole = geographic_to_cartesian(np.asarray(centre.coords))[0]
        pole /= norm(pole)

        # Get a rotation matrix - check that we actually have one
        M = rotation_matrix(pole, np.radians(theta))
        self.assertTrue(np.allclose(np.identity(3), M @ M.T))
        self.assertTrue(np.allclose(1, np.linalg.det(M)))

        # Rotate the box to get what we want
        exterior = np.asarray(box.exterior.coords)
        v = geographic_to_cartesian(exterior)
        v_rot = (M @ v.T).T
        box_rot = Polygon(cartesian_to_geographic(v_rot))

        # Check that we've still got the same centre (shouldn't change
        # under SO(3))
        self.assertTrue(
            np.allclose(np.asarray(box.centroid.coords),
                        np.asarray(box_rot.centroid.coords)))
예제 #2
0
 def test_rotate_function(self):
     "Check rotation about pole doesn't change location"
     centre = Point([116.35, -42.01])
     box = make_box(centre, distance=10)
     for angle in np.random.uniform(0, 2 * np.pi, 10):
         rbox = rotate(box, box.centroid, angle)
         self.assertTrue(
             np.allclose(np.asarray(rbox.centroid.coords),
                         np.asarray(box.centroid.coords)))
예제 #3
0
 def test_make_box_no_proj(self):
     """
     Check that points with no projection are just WGS84
     """
     # Loop over input data
     for distance, nsquares in self.inputs:
         with self.subTest(d=distance, n=nsquares):
             # Generate random points converted to WGS84
             transform = lambda p: pyproj.transform(self.inproj, self.wgs84,
                                                    *p)
             pts = [Point(*transform(p)) for p in random_points(nsquares)]
             polys = MultiPolygon([
                 make_box(p,
                          distance=distance,
                          npoints=150,
                          projection=None) for p in pts
             ])
             self.assertEqual(len(polys), nsquares)
예제 #4
0
    def test_make_box(self):
        """
        Check that n boxes with half-width d come out with approximately the correct area
        """
        # Loop over input data
        for distance, nsquares in self.inputs:
            with self.subTest(d=distance, n=nsquares):
                # Generate random points
                pts = [Point(*p) for p in random_points(nsquares)]
                polys = MultiPolygon([
                    make_box(p,
                             distance=distance,
                             npoints=150,
                             projection='epsg:3112') for p in pts
                ])

                # Check total areas - should be roughly size of squares
                expected = (distance * 1000)**2 * nsquares  # in m^2
                self.assertTrue(np.isclose(polys.area, expected, rtol=1e-1))
예제 #5
0
    def test_make_box_output_proj(self):
        """
        Check that output conversion works ok
        """
        # Loop over input data
        for distance, nsquares in self.inputs:
            with self.subTest(d=distance, n=nsquares):
                # Generate random points
                transform = lambda p: pyproj.transform(self.inproj, self.wgs84,
                                                       *p)
                pts = [Point(*transform(p)) for p in random_points(nsquares)]
                polys = MultiPolygon([
                    make_box(p,
                             distance=distance,
                             npoints=150,
                             output_projection='epsg:3112') for p in pts
                ])

                # Check total areas - should be roughly size of squares
                expected = (distance * 1000)**2 * nsquares  # in m^2
                self.assertTrue(np.isclose(polys.area, expected, rtol=1e-1))