PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ gbox_pt_outside()

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

References cart2geog(), gbox_contains_point3d(), GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LW_FAILURE, LW_SUCCESS, LWDEBUG, LWDEBUGF, 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_pt_outside(), and test_tree_circ_pip2().

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