PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ptarray_length_spheroid()

double ptarray_length_spheroid ( const POINTARRAY pa,
const SPHEROID s 
)

Definition at line 3244 of file lwgeodetic.c.

3245 {
3246  GEOGRAPHIC_POINT a, b;
3247  double za = 0.0, zb = 0.0;
3248  POINT4D p;
3249  uint32_t i;
3250  int hasz = LW_FALSE;
3251  double length = 0.0;
3252  double seglength = 0.0;
3253 
3254  /* Return zero on non-sensical inputs */
3255  if ( ! pa || pa->npoints < 2 )
3256  return 0.0;
3257 
3258  /* See if we have a third dimension */
3259  hasz = FLAGS_GET_Z(pa->flags);
3260 
3261  /* Initialize first point */
3262  getPoint4d_p(pa, 0, &p);
3263  geographic_point_init(p.x, p.y, &a);
3264  if ( hasz )
3265  za = p.z;
3266 
3267  /* Loop and sum the length for each segment */
3268  for ( i = 1; i < pa->npoints; i++ )
3269  {
3270  seglength = 0.0;
3271  getPoint4d_p(pa, i, &p);
3272  geographic_point_init(p.x, p.y, &b);
3273  if ( hasz )
3274  zb = p.z;
3275 
3276  /* Special sphere case */
3277  if ( s->a == s->b )
3278  seglength = s->radius * sphere_distance(&a, &b);
3279  /* Spheroid case */
3280  else
3281  seglength = spheroid_distance(&a, &b, s);
3282 
3283  /* Add in the vertical displacement if we're in 3D */
3284  if ( hasz )
3285  seglength = sqrt( (zb-za)*(zb-za) + seglength*seglength );
3286 
3287  /* Add this segment length to the total */
3288  length += seglength;
3289 
3290  /* B gets incremented in the next loop, so we save the value here */
3291  a = b;
3292  za = zb;
3293  }
3294  return length;
3295 }
char * s
Definition: cu_in_wkt.c:23
#define LW_FALSE
Definition: liblwgeom.h:77
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:123
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:180
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:948
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:191
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:53
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:372
unsigned int uint32_t
Definition: uthash.h:78

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

Referenced by lwgeom_length_spheroid().

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