PostGIS  2.2.7dev-r@@SVN_REVISION@@
double ptarray_length_spheroid ( const POINTARRAY pa,
const SPHEROID s 
)

Definition at line 2831 of file lwgeodetic.c.

References SPHEROID::a, SPHEROID::b, POINTARRAY::flags, FLAGS_GET_Z, geographic_point_init(), getPoint4d_p(), LW_FALSE, POINTARRAY::npoints, SPHEROID::radius, sphere_distance(), spheroid_distance(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by lwgeom_length_spheroid().

2832 {
2833  GEOGRAPHIC_POINT a, b;
2834  double za = 0.0, zb = 0.0;
2835  POINT4D p;
2836  int i;
2837  int hasz = LW_FALSE;
2838  double length = 0.0;
2839  double seglength = 0.0;
2840 
2841  /* Return zero on non-sensical inputs */
2842  if ( ! pa || pa->npoints < 2 )
2843  return 0.0;
2844 
2845  /* See if we have a third dimension */
2846  hasz = FLAGS_GET_Z(pa->flags);
2847 
2848  /* Initialize first point */
2849  getPoint4d_p(pa, 0, &p);
2850  geographic_point_init(p.x, p.y, &a);
2851  if ( hasz )
2852  za = p.z;
2853 
2854  /* Loop and sum the length for each segment */
2855  for ( i = 1; i < pa->npoints; i++ )
2856  {
2857  seglength = 0.0;
2858  getPoint4d_p(pa, i, &p);
2859  geographic_point_init(p.x, p.y, &b);
2860  if ( hasz )
2861  zb = p.z;
2862 
2863  /* Special sphere case */
2864  if ( s->a == s->b )
2865  seglength = s->radius * sphere_distance(&a, &b);
2866  /* Spheroid case */
2867  else
2868  seglength = spheroid_distance(&a, &b, s);
2869 
2870  /* Add in the vertical displacement if we're in 3D */
2871  if ( hasz )
2872  seglength = sqrt( (zb-za)*(zb-za) + seglength*seglength );
2873 
2874  /* Add this segment length to the total */
2875  length += seglength;
2876 
2877  /* B gets incremented in the next loop, so we save the value here */
2878  a = b;
2879  za = zb;
2880  }
2881  return length;
2882 }
double x
Definition: liblwgeom.h:336
double sphere_distance(const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
Given two points on a unit sphere, calculate their distance apart in radians.
Definition: lwgeodetic.c:898
int npoints
Definition: liblwgeom.h:355
double b
Definition: liblwgeom.h:298
double radius
Definition: liblwgeom.h:302
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:32
#define LW_FALSE
Definition: liblwgeom.h:62
uint8_t flags
Definition: liblwgeom.h:353
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
double z
Definition: liblwgeom.h:336
double a
Definition: liblwgeom.h:297
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:156
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.
Definition: lwspheroid.c:172
double y
Definition: liblwgeom.h:336
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231

Here is the call graph for this function:

Here is the caller graph for this function: