PostGIS  2.5.0dev-r@@SVN_REVISION@@
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 2788 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().

2789 {
2790  uint32_t i;
2791  int first = LW_TRUE;
2792  const POINT2D *p;
2793  POINT3D A1, A2;
2794  GBOX edge_gbox;
2795 
2796  assert(gbox);
2797  assert(pa);
2798 
2799  gbox_init(&edge_gbox);
2800  edge_gbox.flags = gbox->flags;
2801 
2802  if ( pa->npoints == 0 ) return LW_FAILURE;
2803 
2804  if ( pa->npoints == 1 )
2805  {
2806  p = getPoint2d_cp(pa, 0);
2807  ll2cart(p, &A1);
2808  gbox->xmin = gbox->xmax = A1.x;
2809  gbox->ymin = gbox->ymax = A1.y;
2810  gbox->zmin = gbox->zmax = A1.z;
2811  return LW_SUCCESS;
2812  }
2813 
2814  p = getPoint2d_cp(pa, 0);
2815  ll2cart(p, &A1);
2816 
2817  for ( i = 1; i < pa->npoints; i++ )
2818  {
2819 
2820  p = getPoint2d_cp(pa, i);
2821  ll2cart(p, &A2);
2822 
2823  edge_calculate_gbox(&A1, &A2, &edge_gbox);
2824 
2825  /* Initialize the box */
2826  if ( first )
2827  {
2828  gbox_duplicate(&edge_gbox, gbox);
2829  first = LW_FALSE;
2830  }
2831  /* Expand the box where necessary */
2832  else
2833  {
2834  gbox_merge(&edge_gbox, gbox);
2835  }
2836 
2837  A1 = A2;
2838  }
2839 
2840  return LW_SUCCESS;
2841 }
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: g_box.c:440
double y
Definition: liblwgeom.h:339
double xmax
Definition: liblwgeom.h:292
#define LW_SUCCESS
Definition: liblwgeom.h:79
double x
Definition: liblwgeom.h:339
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:264
#define LW_FAILURE
Definition: liblwgeom.h:78
double z
Definition: liblwgeom.h:339
unsigned int uint32_t
Definition: uthash.h:78
double zmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:293
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:47
double xmin
Definition: liblwgeom.h:291
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
void ll2cart(const POINT2D *g, POINT3D *p)
Convert lon/lat coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:388
double ymax
Definition: liblwgeom.h:294
uint8_t flags
Definition: liblwgeom.h:290
double zmin
Definition: liblwgeom.h:295
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:1373
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function:

Here is the caller graph for this function: