PostGIS  2.5.0dev-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 441 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().

442 {
443  double poly_area = 0.0;
444  uint32_t i;
445 
446  if ( ! poly )
447  lwerror("lwpoly_area called with null polygon pointer!");
448 
449  for ( i=0; i < poly->nrings; i++ )
450  {
451  POINTARRAY *ring = poly->rings[i];
452  double ringarea = 0.0;
453 
454  /* Empty or messed-up ring. */
455  if ( ring->npoints < 3 )
456  continue;
457 
458  ringarea = fabs(ptarray_signed_area(ring));
459  if ( i == 0 ) /* Outer ring, positive area! */
460  poly_area += ringarea;
461  else /* Inner ring, negative area! */
462  poly_area -= ringarea;
463  }
464 
465  return poly_area;
466 }
double ptarray_signed_area(const POINTARRAY *pa)
Returns the area in cartesian units.
Definition: ptarray.c:990
uint32_t nrings
Definition: liblwgeom.h:457
unsigned int uint32_t
Definition: uthash.h:78
POINTARRAY ** rings
Definition: liblwgeom.h:459
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: