PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ ptarray_calculate_gbox_geodetic()

int ptarray_calculate_gbox_geodetic ( const POINTARRAY pa,
GBOX gbox 
)

Calculate geodetic (x/y/z) box and add values to gbox.

Return LW_SUCCESS on success.

Definition at line 2476 of file lwgeodetic.c.

References edge_calculate_gbox(), GBOX::flags, gbox_duplicate(), gbox_init(), gbox_merge(), getPoint2d_cp(), ll2cart(), LW_FAILURE, LW_FALSE, LW_SUCCESS, LW_TRUE, POINTARRAY::npoints, POINT3D::x, GBOX::xmax, GBOX::xmin, POINT3D::y, GBOX::ymax, GBOX::ymin, POINT3D::z, GBOX::zmax, and GBOX::zmin.

Referenced by lwline_calculate_gbox_geodetic(), lwpoint_calculate_gbox_geodetic(), lwpolygon_calculate_gbox_geodetic(), and lwtriangle_calculate_gbox_geodetic().

2477 {
2478  int i;
2479  int first = LW_TRUE;
2480  const POINT2D *p;
2481  POINT3D A1, A2;
2482  GBOX edge_gbox;
2483 
2484  assert(gbox);
2485  assert(pa);
2486 
2487  gbox_init(&edge_gbox);
2488  edge_gbox.flags = gbox->flags;
2489 
2490  if ( pa->npoints == 0 ) return LW_FAILURE;
2491 
2492  if ( pa->npoints == 1 )
2493  {
2494  p = getPoint2d_cp(pa, 0);
2495  ll2cart(p, &A1);
2496  gbox->xmin = gbox->xmax = A1.x;
2497  gbox->ymin = gbox->ymax = A1.y;
2498  gbox->zmin = gbox->zmax = A1.z;
2499  return LW_SUCCESS;
2500  }
2501 
2502  p = getPoint2d_cp(pa, 0);
2503  ll2cart(p, &A1);
2504 
2505  for ( i = 1; i < pa->npoints; i++ )
2506  {
2507 
2508  p = getPoint2d_cp(pa, i);
2509  ll2cart(p, &A2);
2510 
2511  edge_calculate_gbox(&A1, &A2, &edge_gbox);
2512 
2513  /* Initialize the box */
2514  if ( first )
2515  {
2516  gbox_duplicate(&edge_gbox, gbox);
2517  first = LW_FALSE;
2518  }
2519  /* Expand the box where necessary */
2520  else
2521  {
2522  gbox_merge(&edge_gbox, gbox);
2523  }
2524 
2525  A1 = A2;
2526  }
2527 
2528  return LW_SUCCESS;
2529 }
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: g_box.c:410
double y
Definition: liblwgeom.h:324
int npoints
Definition: liblwgeom.h:355
double xmax
Definition: liblwgeom.h:277
#define LW_SUCCESS
Definition: liblwgeom.h:65
double x
Definition: liblwgeom.h:324
int gbox_merge(const GBOX *new_box, GBOX *merge_box)
Update the merged GBOX to be large enough to include itself and the new box.
Definition: g_box.c:234
#define LW_FAILURE
Definition: liblwgeom.h:64
double z
Definition: liblwgeom.h:324
double zmax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:278
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:36
double xmin
Definition: liblwgeom.h:276
#define LW_FALSE
Definition: liblwgeom.h:62
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:472
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
void ll2cart(const POINT2D *g, POINT3D *p)
Convert lon/lat coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:373
double ymax
Definition: liblwgeom.h:279
uint8_t flags
Definition: liblwgeom.h:275
double zmin
Definition: liblwgeom.h:280
int edge_calculate_gbox(const POINT3D *A1, const POINT3D *A2, GBOX *gbox)
The magic function, given an edge in spherical coordinates, calculate a 3D bounding box that fully co...
Definition: lwgeodetic.c:1356
Here is the call graph for this function:
Here is the caller graph for this function: