PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 1003 of file ptarray.c.

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

References getPoint2d_cp(), POINTARRAY::npoints, POINT2D::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: