PostGIS  2.3.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 484 of file lwpoly.c.

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

Referenced by lwcurvepoly_area(), lwgeom_area(), lwmpoly_to_points(), and lwpoly_to_points().

485 {
486  double poly_area = 0.0;
487  int i;
488 
489  if ( ! poly )
490  lwerror("lwpoly_area called with null polygon pointer!");
491 
492  for ( i=0; i < poly->nrings; i++ )
493  {
494  POINTARRAY *ring = poly->rings[i];
495  double ringarea = 0.0;
496 
497  /* Empty or messed-up ring. */
498  if ( ring->npoints < 3 )
499  continue;
500 
501  ringarea = fabs(ptarray_signed_area(ring));
502  if ( i == 0 ) /* Outer ring, positive area! */
503  poly_area += ringarea;
504  else /* Inner ring, negative area! */
505  poly_area -= ringarea;
506  }
507 
508  return poly_area;
509 }
int npoints
Definition: liblwgeom.h:370
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
Definition: ptarray.c:1002
POINTARRAY ** rings
Definition: liblwgeom.h:456
int nrings
Definition: liblwgeom.h:454
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: