PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 959 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().

960 {
961  const POINT2D *P1;
962  const POINT2D *P2;
963  const POINT2D *P3;
964  double sum = 0.0;
965  double x0, x, y1, y2;
966  int i;
967 
968  if (! pa || pa->npoints < 3 )
969  return 0.0;
970 
971  P1 = getPoint2d_cp(pa, 0);
972  P2 = getPoint2d_cp(pa, 1);
973  x0 = P1->x;
974  for ( i = 1; i < pa->npoints - 1; i++ )
975  {
976  P3 = getPoint2d_cp(pa, i+1);
977  x = P2->x - x0;
978  y1 = P3->y;
979  y2 = P1->y;
980  sum += x * (y2-y1);
981 
982  /* Move forwards! */
983  P1 = P2;
984  P2 = P3;
985  }
986  return sum / 2.0;
987 }
int npoints
Definition: liblwgeom.h:327
double x
Definition: liblwgeom.h:284
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:458
double y
Definition: liblwgeom.h:284
tuple x
Definition: pixval.py:53

Here is the call graph for this function:

Here is the caller graph for this function: