PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwpoly_area()

double lwpoly_area ( const LWPOLY poly)

Find the area of the outer ring - sum (area of inner rings).

Definition at line 411 of file lwpoly.c.

References lwerror(), POINTARRAY::npoints, LWPOLY::nrings, ptarray_signed_area(), and LWPOLY::rings.

Referenced by lwcurvepoly_area(), and lwgeom_area().

412 {
413  double poly_area = 0.0;
414  int i;
415 
416  if ( ! poly )
417  lwerror("lwpoly_area called with null polygon pointer!");
418 
419  for ( i=0; i < poly->nrings; i++ )
420  {
421  POINTARRAY *ring = poly->rings[i];
422  double ringarea = 0.0;
423 
424  /* Empty or messed-up ring. */
425  if ( ring->npoints < 3 )
426  continue;
427 
428  ringarea = fabs(ptarray_signed_area(ring));
429  if ( i == 0 ) /* Outer ring, positive area! */
430  poly_area += ringarea;
431  else /* Inner ring, negative area! */
432  poly_area -= ringarea;
433  }
434 
435  return poly_area;
436 }
int npoints
Definition: liblwgeom.h:355
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
Definition: ptarray.c:995
POINTARRAY ** rings
Definition: liblwgeom.h:441
int nrings
Definition: liblwgeom.h:439
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: