PostGIS  2.4.9dev-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 524 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().

525 {
526  double poly_area = 0.0;
527  int i;
528 
529  if ( ! poly )
530  lwerror("lwpoly_area called with null polygon pointer!");
531 
532  for ( i=0; i < poly->nrings; i++ )
533  {
534  POINTARRAY *ring = poly->rings[i];
535  double ringarea = 0.0;
536 
537  /* Empty or messed-up ring. */
538  if ( ring->npoints < 3 )
539  continue;
540 
541  ringarea = fabs(ptarray_signed_area(ring));
542  if ( i == 0 ) /* Outer ring, positive area! */
543  poly_area += ringarea;
544  else /* Inner ring, negative area! */
545  poly_area -= ringarea;
546  }
547 
548  return poly_area;
549 }
int npoints
Definition: liblwgeom.h:371
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
Definition: ptarray.c:998
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: