PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ ptarray_signed_area()

double ptarray_signed_area ( const POINTARRAY *  pa)

Returns the area in cartesian units.

Area is negative if ring is oriented CCW, positive if it is oriented CW and zero if the ring is degenerate or flat. http://en.wikipedia.org/wiki/Shoelace_formula

Definition at line 1020 of file ptarray.c.

1021 {
1022  const POINT2D *P1;
1023  const POINT2D *P2;
1024  const POINT2D *P3;
1025  double sum = 0.0;
1026  double x0, x, y1, y2;
1027  uint32_t i;
1028 
1029  if (! pa || pa->npoints < 3 )
1030  return 0.0;
1031 
1032  P1 = getPoint2d_cp(pa, 0);
1033  P2 = getPoint2d_cp(pa, 1);
1034  x0 = P1->x;
1035  for ( i = 2; i < pa->npoints; i++ )
1036  {
1037  P3 = getPoint2d_cp(pa, i);
1038  x = P2->x - x0;
1039  y1 = P3->y;
1040  y2 = P1->y;
1041  sum += x * (y2-y1);
1042 
1043  /* Move forwards! */
1044  P1 = P2;
1045  P2 = P3;
1046  }
1047  return sum / 2.0;
1048 }
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:97
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
uint32_t npoints
Definition: liblwgeom.h:427

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

Referenced by lwgeom_subdivide_recursive(), lwpoly_area(), ptarray_isccw(), and test_ptarray_signed_area().

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