PostGIS  2.1.10dev-r@@SVN_REVISION@@
 int gbox_centroid ( const GBOX * gbox, POINT2D * out )

Computes the average(ish) center of the box and returns success.

Definition at line 244 of file lwgeodetic.c.

Referenced by geography_bestsrid(), and test_gbox_utils().

245 {
246  double d[6];
248  POINT3D pt;
249  int i;
250
251  /* Take a copy of the box corners so we can treat them as a list */
252  /* Elements are xmin, xmax, ymin, ymax, zmin, zmax */
253  memcpy(d, &(gbox->xmin), 6*sizeof(double));
254
255  /* Zero out our return vector */
256  pt.x = pt.y = pt.z = 0.0;
257
258  for ( i = 0; i < 8; i++ )
259  {
260  POINT3D pt_n;
261
262  pt_n.x = d[i / 4];
263  pt_n.y = d[2 + ((i % 4) / 2)];
264  pt_n.z = d[4 + (i % 2)];
265  normalize(&pt_n);
266
267  pt.x += pt_n.x;
268  pt.y += pt_n.y;
269  pt.z += pt_n.z;
270  }
271
272  pt.x /= 8.0;
273  pt.y /= 8.0;
274  pt.z /= 8.0;
275  normalize(&pt);
276
277  cart2geog(&pt, &g);
280
281  return LW_SUCCESS;
282 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:564
double y
Definition: liblwgeom.h:296
#define LW_SUCCESS
Definition: liblwgeom.h:55
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:365
double x
Definition: liblwgeom.h:296
double longitude_degrees_normalize(double lon)
Convert a longitude to the range of -180,180.
Definition: lwgeodetic.c:83
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:33
double latitude_degrees_normalize(double lat)
Convert a latitude to the range of -90,90.
Definition: lwgeodetic.c:110
double z
Definition: liblwgeom.h:296
double x
Definition: liblwgeom.h:284
double xmin
Definition: liblwgeom.h:248