geodesic_waypoints_between#

rojak.core.geometric.geodesic_waypoints_between(start: Coordinate, end: Coordinate, grid_size: float, n_points_safety_factor: float = 2, n_points: int | None = None) ndarray[source]#

Find the coordinates (i.e. waypoints) on the great circle between the two points.

Parameters:
  • start (Coordinate) – Starting coordinate

  • end (Coordinate) – Ending coordinate

  • grid_size (float) – Grid spacing in degrees. For Era5, this is 0.25

  • n_points_safety_factor (float) – Safety factor applied for the estimation of number of waypoints. Larger => more points.

  • specified (If n_points is)

  • ignored. (this value is)

  • n_points (int | None) – If None, then number of points is estimated. Else, this value is used to compute the waypoints

Returns:

2D numpy array of points with shape (num_waypoints, 2). The first column is the longitude and the second column is the latitude.

Return type:

ndarray

Examples

>>> lhr = Coordinate(51.47138888, -0.45277777)
>>> jfk = Coordinate(40.641766, -73.780968)
>>> way_points_lhr_jfk = geodesic_waypoints_between(lhr, jfk, 0.25)
>>> way_points_lhr_jfk.shape
(330, 2)

The first and last rows correspond to the longitude and latitude of the starting and end point, respectively.

>>> way_points_lhr_jfk[0, :]
array([-0.45277777, 51.47138888])
>>> way_points_lhr_jfk[-1, :]
array([-73.780968,  40.641766])

Flipping the star and end points reverses the order of the array of way points.

>>> way_points_jfk_lhr = geodesic_waypoints_between(jfk, lhr, 0.25)
>>> np.testing.assert_array_almost_equal(way_points_lhr_jfk, np.flipud(way_points_jfk_lhr))

Specifying the number of points

>>> min_points = geodesic_waypoints_between(lhr, jfk, 0.25, n_points=2)
>>> min_points.shape
(2, 2)
>>> min_points
array([[ -0.45277777,  51.47138888],
       [-73.780968  ,  40.641766  ]])
>>> geodesic_waypoints_between(lhr, jfk, 0.25, n_points=1)
Traceback (most recent call last):
ValueError: Number of points cannot be less than 2 as it must include start and end points.