PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ ptarray_area_spheroid()

static double ptarray_area_spheroid ( const POINTARRAY pa,
const SPHEROID spheroid 
)
static

Definition at line 142 of file lwspheroid.c.

143 {
144  /* Return zero on non-sensical inputs */
145  if ( ! pa || pa->npoints < 4 )
146  return 0.0;
147 
148  struct geod_geodesic gd;
149  geod_init(&gd, spheroid->a, spheroid->f);
150  struct geod_polygon poly;
151  geod_polygon_init(&poly, 0);
152  uint32_t i;
153  double area; /* returned polygon area */
154  POINT2D p; /* long/lat units are degrees */
155 
156  /* Pass points from point array; don't close the linearring */
157  for ( i = 0; i < pa->npoints - 1; i++ )
158  {
159  getPoint2d_p(pa, i, &p);
160  geod_polygon_addpoint(&gd, &poly, p.y, p.x);
161  LWDEBUGF(4, "geod_polygon_addpoint %d: %.12g %.12g", i, p.y, p.x);
162  }
163  i = geod_polygon_compute(&gd, &poly, 0, 1, &area, 0);
164  if ( i != pa->npoints - 1 )
165  {
166  lwerror("ptarray_area_spheroid: different number of points %d vs %d",
167  i, pa->npoints - 1);
168  }
169  LWDEBUGF(4, "geod_polygon_compute area: %.12g", area);
170  return fabs(area);
171 }
int getPoint2d_p(const POINTARRAY *pa, uint32_t n, POINT2D *point)
Definition: lwgeom_api.c:349
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376
uint32_t npoints
Definition: liblwgeom.h:413
double a
Definition: liblwgeom.h:361
double f
Definition: liblwgeom.h:363

References SPHEROID::a, SPHEROID::f, getPoint2d_p(), LWDEBUGF, lwerror(), POINTARRAY::npoints, POINT2D::x, and POINT2D::y.

Referenced by lwgeom_area_spheroid().

Here is the call graph for this function:
Here is the caller graph for this function: