PostGIS  3.7.0dev-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 1506 of file lwgeodetic.c.

1507 {
1508  double grow = M_PI / 180.0 / 60.0; /* one arc-minute */
1509  int i;
1510  GBOX ge;
1511  POINT3D corners[8];
1512  POINT3D pt;
1513  GEOGRAPHIC_POINT g;
1514 
1515  while ( grow < M_PI )
1516  {
1517  /* Assign our box and expand it slightly. */
1518  ge = *gbox;
1519  if ( ge.xmin > -1 ) ge.xmin -= grow;
1520  if ( ge.ymin > -1 ) ge.ymin -= grow;
1521  if ( ge.zmin > -1 ) ge.zmin -= grow;
1522  if ( ge.xmax < 1 ) ge.xmax += grow;
1523  if ( ge.ymax < 1 ) ge.ymax += grow;
1524  if ( ge.zmax < 1 ) ge.zmax += grow;
1525 
1526  /* Build our eight corner points */
1527  corners[0].x = ge.xmin;
1528  corners[0].y = ge.ymin;
1529  corners[0].z = ge.zmin;
1530 
1531  corners[1].x = ge.xmin;
1532  corners[1].y = ge.ymax;
1533  corners[1].z = ge.zmin;
1534 
1535  corners[2].x = ge.xmin;
1536  corners[2].y = ge.ymin;
1537  corners[2].z = ge.zmax;
1538 
1539  corners[3].x = ge.xmax;
1540  corners[3].y = ge.ymin;
1541  corners[3].z = ge.zmin;
1542 
1543  corners[4].x = ge.xmax;
1544  corners[4].y = ge.ymax;
1545  corners[4].z = ge.zmin;
1546 
1547  corners[5].x = ge.xmax;
1548  corners[5].y = ge.ymin;
1549  corners[5].z = ge.zmax;
1550 
1551  corners[6].x = ge.xmin;
1552  corners[6].y = ge.ymax;
1553  corners[6].z = ge.zmax;
1554 
1555  corners[7].x = ge.xmax;
1556  corners[7].y = ge.ymax;
1557  corners[7].z = ge.zmax;
1558 
1559  LWDEBUG(4, "trying to use a box corner point...");
1560  for ( i = 0; i < 8; i++ )
1561  {
1562  normalize(&(corners[i]));
1563  LWDEBUGF(4, "testing corner %d: POINT(%.8g %.8g %.8g)", i, corners[i].x, corners[i].y, corners[i].z);
1564  if ( ! gbox_contains_point3d(gbox, &(corners[i])) )
1565  {
1566  LWDEBUGF(4, "corner %d is outside our gbox", i);
1567  pt = corners[i];
1568  normalize(&pt);
1569  cart2geog(&pt, &g);
1570  pt_outside->x = rad2deg(g.lon);
1571  pt_outside->y = rad2deg(g.lat);
1572  LWDEBUGF(4, "returning POINT(%.8g %.8g) as outside point", pt_outside->x, pt_outside->y);
1573  return LW_SUCCESS;
1574  }
1575  }
1576 
1577  /* Try a wider growth to push the corners outside the original box. */
1578  grow *= 2.0;
1579  }
1580 
1581  /* This should never happen! */
1582  // lwerror("BOOM! Could not generate outside point!");
1583  return LW_FAILURE;
1584 }
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:96
#define LW_SUCCESS
Definition: liblwgeom.h:97
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:101
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:106
double ymax
Definition: liblwgeom.h:357
double zmax
Definition: liblwgeom.h:359
double xmax
Definition: liblwgeom.h:355
double zmin
Definition: liblwgeom.h:358
double ymin
Definition: liblwgeom.h:356
double xmin
Definition: liblwgeom.h:354
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:54
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
double z
Definition: liblwgeom.h:402
double x
Definition: liblwgeom.h:402
double y
Definition: liblwgeom.h:402

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: