PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ ptarray_area_sphere()

double ptarray_area_sphere ( const POINTARRAY pa)

Returns the area of the ring (ring must be closed) in square radians (surface of the sphere is 4*PI).

Definition at line 1714 of file lwgeodetic.c.

References area(), geographic_point_init(), getPoint2d_cp(), POINTARRAY::npoints, sphere_signed_area(), POINT2D::x, and POINT2D::y.

Referenced by lwgeom_area_sphere().

1715 {
1716  int i;
1717  const POINT2D *p;
1718  GEOGRAPHIC_POINT a, b, c;
1719  double area = 0.0;
1720 
1721  /* Return zero on nonsensical inputs */
1722  if ( ! pa || pa->npoints < 4 )
1723  return 0.0;
1724 
1725  p = getPoint2d_cp(pa, 0);
1726  geographic_point_init(p->x, p->y, &a);
1727  p = getPoint2d_cp(pa, 1);
1728  geographic_point_init(p->x, p->y, &b);
1729 
1730  for ( i = 2; i < pa->npoints-1; i++ )
1731  {
1732  p = getPoint2d_cp(pa, i);
1733  geographic_point_init(p->x, p->y, &c);
1734  area += sphere_signed_area(&a, &b, &c);
1735  b = c;
1736  }
1737 
1738  return fabs(area);
1739 }
int npoints
Definition: liblwgeom.h:370
Datum area(PG_FUNCTION_ARGS)
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
double x
Definition: liblwgeom.h:327
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:485
double y
Definition: liblwgeom.h:327
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:171
static double sphere_signed_area(const GEOGRAPHIC_POINT *a, const GEOGRAPHIC_POINT *b, const GEOGRAPHIC_POINT *c)
Computes the spherical area of a triangle.
Definition: lwgeodetic.c:706
Here is the call graph for this function:
Here is the caller graph for this function: