PostGIS  3.4.0dev-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 1813 of file lwgeodetic.c.

1814 {
1815  uint32_t i;
1816  const POINT2D *p;
1817  GEOGRAPHIC_POINT a, b, c;
1818  double area = 0.0;
1819 
1820  /* Return zero on nonsensical inputs */
1821  if ( ! pa || pa->npoints < 4 )
1822  return 0.0;
1823 
1824  p = getPoint2d_cp(pa, 0);
1825  geographic_point_init(p->x, p->y, &a);
1826  p = getPoint2d_cp(pa, 1);
1827  geographic_point_init(p->x, p->y, &b);
1828 
1829  for ( i = 2; i < pa->npoints-1; i++ )
1830  {
1831  p = getPoint2d_cp(pa, i);
1832  geographic_point_init(p->x, p->y, &c);
1833  area += sphere_signed_area(&a, &b, &c);
1834  b = c;
1835  }
1836 
1837  return fabs(area);
1838 }
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:180
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:741
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:101
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:54
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
uint32_t npoints
Definition: liblwgeom.h:427

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

Referenced by lwgeom_area_sphere().

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