PostGIS  2.2.7dev-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 243 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: