PostGIS  2.1.10dev-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 1443 of file lwgeodetic.c.

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

Here is the call graph for this function:

Here is the caller graph for this function: