PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ gbox_centroid()

int gbox_centroid ( const GBOX gbox,
POINT2D out 
)

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

Definition at line 258 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().

259 {
260  double d[6];
262  POINT3D pt;
263  int i;
264 
265  /* Take a copy of the box corners so we can treat them as a list */
266  /* Elements are xmin, xmax, ymin, ymax, zmin, zmax */
267  memcpy(d, &(gbox->xmin), 6*sizeof(double));
268 
269  /* Zero out our return vector */
270  pt.x = pt.y = pt.z = 0.0;
271 
272  for ( i = 0; i < 8; i++ )
273  {
274  POINT3D pt_n;
275 
276  pt_n.x = d[i / 4];
277  pt_n.y = d[2 + ((i % 4) / 2)];
278  pt_n.z = d[4 + (i % 2)];
279  normalize(&pt_n);
280 
281  pt.x += pt_n.x;
282  pt.y += pt_n.y;
283  pt.z += pt_n.z;
284  }
285 
286  pt.x /= 8.0;
287  pt.y /= 8.0;
288  pt.z /= 8.0;
289  normalize(&pt);
290 
291  cart2geog(&pt, &g);
294 
295  return LW_SUCCESS;
296 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:584
double y
Definition: liblwgeom.h:342
#define LW_SUCCESS
Definition: liblwgeom.h:79
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:383
double x
Definition: liblwgeom.h:342
double longitude_degrees_normalize(double lon)
Convert a longitude to the range of -180,180.
Definition: lwgeodetic.c:97
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
double latitude_degrees_normalize(double lat)
Convert a latitude to the range of -90,90.
Definition: lwgeodetic.c:124
double z
Definition: liblwgeom.h:342
double x
Definition: liblwgeom.h:330
double xmin
Definition: liblwgeom.h:294
#define rad2deg(r)
Definition: lwgeodetic.h:75
double y
Definition: liblwgeom.h:330
Here is the call graph for this function:
Here is the caller graph for this function: