PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 1444 of file lwgeodetic.c.

References cart2geog(), gbox_contains_point3d(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LWDEBUG, LWDEBUGF, lwerror(), normalize(), rad2deg, pixval::x, POINT2D::x, POINT3D::x, GBOX::xmax, GBOX::xmin, pixval::y, POINT2D::y, POINT3D::y, GBOX::ymax, GBOX::ymin, POINT3D::z, GBOX::zmax, and GBOX::zmin.

Referenced by CircTreePIP(), geography_point_outside(), lwpoly_covers_point2d(), lwpoly_pt_outside(), and test_tree_circ_pip2().

1445 {
1446  double grow = M_PI / 180.0 / 60.0; /* one arc-minute */
1447  int i;
1448  GBOX ge;
1449  POINT3D corners[8];
1450  POINT3D pt;
1451  GEOGRAPHIC_POINT g;
1452 
1453  while ( grow < M_PI )
1454  {
1455  /* Assign our box and expand it slightly. */
1456  ge = *gbox;
1457  if ( ge.xmin > -1 ) ge.xmin -= grow;
1458  if ( ge.ymin > -1 ) ge.ymin -= grow;
1459  if ( ge.zmin > -1 ) ge.zmin -= grow;
1460  if ( ge.xmax < 1 ) ge.xmax += grow;
1461  if ( ge.ymax < 1 ) ge.ymax += grow;
1462  if ( ge.zmax < 1 ) ge.zmax += grow;
1463 
1464  /* Build our eight corner points */
1465  corners[0].x = ge.xmin;
1466  corners[0].y = ge.ymin;
1467  corners[0].z = ge.zmin;
1468 
1469  corners[1].x = ge.xmin;
1470  corners[1].y = ge.ymax;
1471  corners[1].z = ge.zmin;
1472 
1473  corners[2].x = ge.xmin;
1474  corners[2].y = ge.ymin;
1475  corners[2].z = ge.zmax;
1476 
1477  corners[3].x = ge.xmax;
1478  corners[3].y = ge.ymin;
1479  corners[3].z = ge.zmin;
1480 
1481  corners[4].x = ge.xmax;
1482  corners[4].y = ge.ymax;
1483  corners[4].z = ge.zmin;
1484 
1485  corners[5].x = ge.xmax;
1486  corners[5].y = ge.ymin;
1487  corners[5].z = ge.zmax;
1488 
1489  corners[6].x = ge.xmin;
1490  corners[6].y = ge.ymax;
1491  corners[6].z = ge.zmax;
1492 
1493  corners[7].x = ge.xmax;
1494  corners[7].y = ge.ymax;
1495  corners[7].z = ge.zmax;
1496 
1497  LWDEBUG(4, "trying to use a box corner point...");
1498  for ( i = 0; i < 8; i++ )
1499  {
1500  normalize(&(corners[i]));
1501  LWDEBUGF(4, "testing corner %d: POINT(%.8g %.8g %.8g)", i, corners[i].x, corners[i].y, corners[i].z);
1502  if ( ! gbox_contains_point3d(gbox, &(corners[i])) )
1503  {
1504  LWDEBUGF(4, "corner %d is outside our gbox", i);
1505  pt = corners[i];
1506  normalize(&pt);
1507  cart2geog(&pt, &g);
1508  pt_outside->x = rad2deg(g.lon);
1509  pt_outside->y = rad2deg(g.lat);
1510  LWDEBUGF(4, "returning POINT(%.8g %.8g) as outside point", pt_outside->x, pt_outside->y);
1511  return;
1512  }
1513  }
1514 
1515  /* Try a wider growth to push the corners outside the original box. */
1516  grow *= 2.0;
1517  }
1518 
1519  /* This should never happen! */
1520  lwerror("BOOM! Could not generate outside point!");
1521  return;
1522 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:565
double y
Definition: liblwgeom.h:324
double xmax
Definition: liblwgeom.h:277
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:224
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:364
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
double x
Definition: liblwgeom.h:324
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:32
double z
Definition: liblwgeom.h:324
double x
Definition: liblwgeom.h:312
double zmax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
#define rad2deg(r)
Definition: lwgeodetic.h:60
double ymax
Definition: liblwgeom.h:279
double y
Definition: liblwgeom.h:312
tuple x
Definition: pixval.py:53
double zmin
Definition: liblwgeom.h:280
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: