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.

References cart2geog(), GEOGRAPHIC_POINT::lat, latitude_degrees_normalize(), GEOGRAPHIC_POINT::lon, longitude_degrees_normalize(), LW_SUCCESS, normalize(), rad2deg, POINT2D::x, POINT3D::x, GBOX::xmin, POINT2D::y, POINT3D::y, and POINT3D::z.

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
#define rad2deg(r)
Definition: lwgeodetic.h:61
double y
Definition: liblwgeom.h:284

Here is the call graph for this function:

Here is the caller graph for this function: