PostGIS  2.3.7dev-r@@SVN_REVISION@@
void gbox_pt_outside ( const GBOX gbox,
POINT2D pt_outside 
)

Calculate a spherical point that falls outside the geocentric gbox.

Calculate a spherical point that falls outside the geocentric gbox.

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

1462 {
1463  double grow = M_PI / 180.0 / 60.0; /* one arc-minute */
1464  int i;
1465  GBOX ge;
1466  POINT3D corners[8];
1467  POINT3D pt;
1468  GEOGRAPHIC_POINT g;
1469 
1470  while ( grow < M_PI )
1471  {
1472  /* Assign our box and expand it slightly. */
1473  ge = *gbox;
1474  if ( ge.xmin > -1 ) ge.xmin -= grow;
1475  if ( ge.ymin > -1 ) ge.ymin -= grow;
1476  if ( ge.zmin > -1 ) ge.zmin -= grow;
1477  if ( ge.xmax < 1 ) ge.xmax += grow;
1478  if ( ge.ymax < 1 ) ge.ymax += grow;
1479  if ( ge.zmax < 1 ) ge.zmax += grow;
1480 
1481  /* Build our eight corner points */
1482  corners[0].x = ge.xmin;
1483  corners[0].y = ge.ymin;
1484  corners[0].z = ge.zmin;
1485 
1486  corners[1].x = ge.xmin;
1487  corners[1].y = ge.ymax;
1488  corners[1].z = ge.zmin;
1489 
1490  corners[2].x = ge.xmin;
1491  corners[2].y = ge.ymin;
1492  corners[2].z = ge.zmax;
1493 
1494  corners[3].x = ge.xmax;
1495  corners[3].y = ge.ymin;
1496  corners[3].z = ge.zmin;
1497 
1498  corners[4].x = ge.xmax;
1499  corners[4].y = ge.ymax;
1500  corners[4].z = ge.zmin;
1501 
1502  corners[5].x = ge.xmax;
1503  corners[5].y = ge.ymin;
1504  corners[5].z = ge.zmax;
1505 
1506  corners[6].x = ge.xmin;
1507  corners[6].y = ge.ymax;
1508  corners[6].z = ge.zmax;
1509 
1510  corners[7].x = ge.xmax;
1511  corners[7].y = ge.ymax;
1512  corners[7].z = ge.zmax;
1513 
1514  LWDEBUG(4, "trying to use a box corner point...");
1515  for ( i = 0; i < 8; i++ )
1516  {
1517  normalize(&(corners[i]));
1518  LWDEBUGF(4, "testing corner %d: POINT(%.8g %.8g %.8g)", i, corners[i].x, corners[i].y, corners[i].z);
1519  if ( ! gbox_contains_point3d(gbox, &(corners[i])) )
1520  {
1521  LWDEBUGF(4, "corner %d is outside our gbox", i);
1522  pt = corners[i];
1523  normalize(&pt);
1524  cart2geog(&pt, &g);
1525  pt_outside->x = rad2deg(g.lon);
1526  pt_outside->y = rad2deg(g.lat);
1527  LWDEBUGF(4, "returning POINT(%.8g %.8g) as outside point", pt_outside->x, pt_outside->y);
1528  return;
1529  }
1530  }
1531 
1532  /* Try a wider growth to push the corners outside the original box. */
1533  grow *= 2.0;
1534  }
1535 
1536  /* This should never happen! */
1537  lwerror("BOOM! Could not generate outside point!");
1538  return;
1539 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:580
double y
Definition: liblwgeom.h:339
double xmax
Definition: liblwgeom.h:292
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: g_box.c:259
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesion coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:379
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
double x
Definition: liblwgeom.h:339
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
double z
Definition: liblwgeom.h:339
double x
Definition: liblwgeom.h:327
double zmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:293
double xmin
Definition: liblwgeom.h:291
#define rad2deg(r)
Definition: lwgeodetic.h:75
double ymax
Definition: liblwgeom.h:294
double y
Definition: liblwgeom.h:327
tuple x
Definition: pixval.py:53
double zmin
Definition: liblwgeom.h:295
#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:102
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: