PostGIS  2.5.2dev-r@@SVN_REVISION@@

## ◆ gbox_pt_outside()

 void gbox_pt_outside ( const GBOX * gbox, POINT2D * pt_outside )

Given a unit geocentric gbox, return a lon/lat (degrees) coordinate point point that is guaranteed to be outside the box (and therefore anything it contains).

Calculate a spherical point that falls outside the geocentric gbox.

Definition at line 1474 of file lwgeodetic.c.

1475 {
1476  double grow = M_PI / 180.0 / 60.0; /* one arc-minute */
1477  int i;
1478  GBOX ge;
1479  POINT3D corners[8];
1480  POINT3D pt;
1481  GEOGRAPHIC_POINT g;
1482
1483  while ( grow < M_PI )
1484  {
1485  /* Assign our box and expand it slightly. */
1486  ge = *gbox;
1487  if ( ge.xmin > -1 ) ge.xmin -= grow;
1488  if ( ge.ymin > -1 ) ge.ymin -= grow;
1489  if ( ge.zmin > -1 ) ge.zmin -= grow;
1490  if ( ge.xmax < 1 ) ge.xmax += grow;
1491  if ( ge.ymax < 1 ) ge.ymax += grow;
1492  if ( ge.zmax < 1 ) ge.zmax += grow;
1493
1494  /* Build our eight corner points */
1495  corners[0].x = ge.xmin;
1496  corners[0].y = ge.ymin;
1497  corners[0].z = ge.zmin;
1498
1499  corners[1].x = ge.xmin;
1500  corners[1].y = ge.ymax;
1501  corners[1].z = ge.zmin;
1502
1503  corners[2].x = ge.xmin;
1504  corners[2].y = ge.ymin;
1505  corners[2].z = ge.zmax;
1506
1507  corners[3].x = ge.xmax;
1508  corners[3].y = ge.ymin;
1509  corners[3].z = ge.zmin;
1510
1511  corners[4].x = ge.xmax;
1512  corners[4].y = ge.ymax;
1513  corners[4].z = ge.zmin;
1514
1515  corners[5].x = ge.xmax;
1516  corners[5].y = ge.ymin;
1517  corners[5].z = ge.zmax;
1518
1519  corners[6].x = ge.xmin;
1520  corners[6].y = ge.ymax;
1521  corners[6].z = ge.zmax;
1522
1523  corners[7].x = ge.xmax;
1524  corners[7].y = ge.ymax;
1525  corners[7].z = ge.zmax;
1526
1527  LWDEBUG(4, "trying to use a box corner point...");
1528  for ( i = 0; i < 8; i++ )
1529  {
1530  normalize(&(corners[i]));
1531  LWDEBUGF(4, "testing corner %d: POINT(%.8g %.8g %.8g)", i, corners[i].x, corners[i].y, corners[i].z);
1532  if ( ! gbox_contains_point3d(gbox, &(corners[i])) )
1533  {
1534  LWDEBUGF(4, "corner %d is outside our gbox", i);
1535  pt = corners[i];
1536  normalize(&pt);
1537  cart2geog(&pt, &g);
1540  LWDEBUGF(4, "returning POINT(%.8g %.8g) as outside point", pt_outside->x, pt_outside->y);
1541  return;
1542  }
1543  }
1544
1545  /* Try a wider growth to push the corners outside the original box. */
1546  grow *= 2.0;
1547  }
1548
1549  /* This should never happen! */
1550  lwerror("BOOM! Could not generate outside point!");
1551  return;
1552 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:593
double y
Definition: liblwgeom.h:343
double xmax
Definition: liblwgeom.h:296
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:254
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:392
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
double x
Definition: liblwgeom.h:343
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:52
double z
Definition: liblwgeom.h:343
double x
Definition: liblwgeom.h:331
double zmax
Definition: liblwgeom.h:300
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
Definition: lwgeodetic.h:80
double ymax
Definition: liblwgeom.h:298
double y
Definition: liblwgeom.h:331
double zmin
Definition: liblwgeom.h:299
#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
Here is the call graph for this function:
Here is the caller graph for this function: