PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ spheroid_distance()

double spheroid_distance ( const GEOGRAPHIC_POINT a,
const GEOGRAPHIC_POINT b,
const SPHEROID spheroid 
)

Computes the shortest distance along the surface of the spheroid between two points, using the inverse geodesic problem from GeographicLib (Karney 2013).

Parameters
a- location of first point
b- location of second point
s- spheroid to calculate on
Returns
spheroidal distance between a and b in spheroid units

Definition at line 79 of file lwspheroid.c.

80 {
81  struct geod_geodesic gd;
82 
83  /* Same point => zero distance */
84  if ( geographic_point_equals(a, b) )
85  return 0.0;
86 
87  geod_init(&gd, spheroid->a, spheroid->f);
88  double lat1 = a->lat * 180.0 / M_PI;
89  double lon1 = a->lon * 180.0 / M_PI;
90  double lat2 = b->lat * 180.0 / M_PI;
91  double lon2 = b->lon * 180.0 / M_PI;
92  double s12 = 0.0; /* return distance */
93  geod_inverse(&gd, lat1, lon1, lat2, lon2, &s12, 0, 0);
94  return s12;
95 }
int geographic_point_equals(const GEOGRAPHIC_POINT *g1, const GEOGRAPHIC_POINT *g2)
Definition: lwgeodetic.c:170
double a
Definition: liblwgeom.h:361
double f
Definition: liblwgeom.h:363

References SPHEROID::a, SPHEROID::f, geographic_point_equals(), GEOGRAPHIC_POINT::lat, and GEOGRAPHIC_POINT::lon.

Referenced by circ_tree_distance_tree(), ptarray_distance_spheroid(), ptarray_length_spheroid(), and test_spheroid_distance().

Here is the call graph for this function:
Here is the caller graph for this function: