PostGIS  3.2.2dev-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 1283 of file ptarray.c.

1284 {
1285  const POINT2D *P1;
1286  const POINT2D *P2;
1287  const POINT2D *P3;
1288  double sum = 0.0;
1289  double x0, x, y1, y2;
1290  uint32_t i;
1291 
1292  if (! pa || pa->npoints < 3 )
1293  return 0.0;
1294 
1295  P1 = getPoint2d_cp(pa, 0);
1296  P2 = getPoint2d_cp(pa, 1);
1297  x0 = P1->x;
1298  for ( i = 2; i < pa->npoints; i++ )
1299  {
1300  P3 = getPoint2d_cp(pa, i);
1301  x = P2->x - x0;
1302  y1 = P3->y;
1303  y2 = P1->y;
1304  sum += x * (y2-y1);
1305 
1306  /* Move forwards! */
1307  P1 = P2;
1308  P2 = P3;
1309  }
1310  return sum / 2.0;
1311 }
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
double y
Definition: liblwgeom.h:404
double x
Definition: liblwgeom.h:404
uint32_t npoints
Definition: liblwgeom.h:441

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: