PostGIS  3.2.2dev-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 1809 of file lwgeodetic.c.

1810 {
1811  uint32_t i;
1812  const POINT2D *p;
1813  GEOGRAPHIC_POINT a, b, c;
1814  double area = 0.0;
1815 
1816  /* Return zero on nonsensical inputs */
1817  if ( ! pa || pa->npoints < 4 )
1818  return 0.0;
1819 
1820  p = getPoint2d_cp(pa, 0);
1821  geographic_point_init(p->x, p->y, &a);
1822  p = getPoint2d_cp(pa, 1);
1823  geographic_point_init(p->x, p->y, &b);
1824 
1825  for ( i = 2; i < pa->npoints-1; i++ )
1826  {
1827  p = getPoint2d_cp(pa, i);
1828  geographic_point_init(p->x, p->y, &c);
1829  area += sphere_signed_area(&a, &b, &c);
1830  b = c;
1831  }
1832 
1833  return fabs(area);
1834 }
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:404
double x
Definition: liblwgeom.h:404
uint32_t npoints
Definition: liblwgeom.h:441

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: