PostGIS  2.3.8dev-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 1002 of file ptarray.c.

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

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

1003 {
1004  const POINT2D *P1;
1005  const POINT2D *P2;
1006  const POINT2D *P3;
1007  double sum = 0.0;
1008  double x0, x, y1, y2;
1009  int i;
1010 
1011  if (! pa || pa->npoints < 3 )
1012  return 0.0;
1013 
1014  P1 = getPoint2d_cp(pa, 0);
1015  P2 = getPoint2d_cp(pa, 1);
1016  x0 = P1->x;
1017  for ( i = 2; i < pa->npoints; i++ )
1018  {
1019  P3 = getPoint2d_cp(pa, i);
1020  x = P2->x - x0;
1021  y1 = P3->y;
1022  y2 = P1->y;
1023  sum += x * (y2-y1);
1024 
1025  /* Move forwards! */
1026  P1 = P2;
1027  P2 = P3;
1028  }
1029  return sum / 2.0;
1030 }
int npoints
Definition: liblwgeom.h:370
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
Here is the call graph for this function:
Here is the caller graph for this function: