PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ gbox_pt_outside()

int 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 1554 of file lwgeodetic.c.

1555 {
1556  double grow = M_PI / 180.0 / 60.0; /* one arc-minute */
1557  int i;
1558  GBOX ge;
1559  POINT3D corners[8];
1560  POINT3D pt;
1561  GEOGRAPHIC_POINT g;
1562 
1563  while ( grow < M_PI )
1564  {
1565  /* Assign our box and expand it slightly. */
1566  ge = *gbox;
1567  if ( ge.xmin > -1 ) ge.xmin -= grow;
1568  if ( ge.ymin > -1 ) ge.ymin -= grow;
1569  if ( ge.zmin > -1 ) ge.zmin -= grow;
1570  if ( ge.xmax < 1 ) ge.xmax += grow;
1571  if ( ge.ymax < 1 ) ge.ymax += grow;
1572  if ( ge.zmax < 1 ) ge.zmax += grow;
1573 
1574  /* Build our eight corner points */
1575  corners[0].x = ge.xmin;
1576  corners[0].y = ge.ymin;
1577  corners[0].z = ge.zmin;
1578 
1579  corners[1].x = ge.xmin;
1580  corners[1].y = ge.ymax;
1581  corners[1].z = ge.zmin;
1582 
1583  corners[2].x = ge.xmin;
1584  corners[2].y = ge.ymin;
1585  corners[2].z = ge.zmax;
1586 
1587  corners[3].x = ge.xmax;
1588  corners[3].y = ge.ymin;
1589  corners[3].z = ge.zmin;
1590 
1591  corners[4].x = ge.xmax;
1592  corners[4].y = ge.ymax;
1593  corners[4].z = ge.zmin;
1594 
1595  corners[5].x = ge.xmax;
1596  corners[5].y = ge.ymin;
1597  corners[5].z = ge.zmax;
1598 
1599  corners[6].x = ge.xmin;
1600  corners[6].y = ge.ymax;
1601  corners[6].z = ge.zmax;
1602 
1603  corners[7].x = ge.xmax;
1604  corners[7].y = ge.ymax;
1605  corners[7].z = ge.zmax;
1606 
1607  LWDEBUG(4, "trying to use a box corner point...");
1608  for ( i = 0; i < 8; i++ )
1609  {
1610  normalize(&(corners[i]));
1611  LWDEBUGF(4, "testing corner %d: POINT(%.8g %.8g %.8g)", i, corners[i].x, corners[i].y, corners[i].z);
1612  if ( ! gbox_contains_point3d(gbox, &(corners[i])) )
1613  {
1614  LWDEBUGF(4, "corner %d is outside our gbox", i);
1615  pt = corners[i];
1616  normalize(&pt);
1617  cart2geog(&pt, &g);
1618  pt_outside->x = rad2deg(g.lon);
1619  pt_outside->y = rad2deg(g.lat);
1620  LWDEBUGF(4, "returning POINT(%.8g %.8g) as outside point", pt_outside->x, pt_outside->y);
1621  return LW_SUCCESS;
1622  }
1623  }
1624 
1625  /* Try a wider growth to push the corners outside the original box. */
1626  grow *= 2.0;
1627  }
1628 
1629  /* This should never happen! */
1630  // lwerror("BOOM! Could not generate outside point!");
1631  return LW_FAILURE;
1632 }
int gbox_contains_point3d(const GBOX *gbox, const POINT3D *pt)
Return true if the point is inside the gbox.
Definition: gbox.c:247
#define LW_FAILURE
Definition: liblwgeom.h:110
#define LW_SUCCESS
Definition: liblwgeom.h:111
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:615
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:414
#define rad2deg(r)
Definition: lwgeodetic.h:81
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
double ymax
Definition: liblwgeom.h:371
double zmax
Definition: liblwgeom.h:373
double xmax
Definition: liblwgeom.h:369
double zmin
Definition: liblwgeom.h:372
double ymin
Definition: liblwgeom.h:370
double xmin
Definition: liblwgeom.h:368
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:54
double y
Definition: liblwgeom.h:404
double x
Definition: liblwgeom.h:404
double z
Definition: liblwgeom.h:416
double x
Definition: liblwgeom.h:416
double y
Definition: liblwgeom.h:416

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

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

Here is the call graph for this function:
Here is the caller graph for this function: