PostGIS  3.3.9dev-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 2729 of file lwgeodetic.c.

2730 {
2731  uint32_t i;
2732  int first = LW_TRUE;
2733  const POINT2D *p;
2734  POINT3D A1, A2;
2735  GBOX edge_gbox;
2736 
2737  assert(gbox);
2738  assert(pa);
2739 
2740  gbox_init(&edge_gbox);
2741  edge_gbox.flags = gbox->flags;
2742 
2743  if ( pa->npoints == 0 ) return LW_FAILURE;
2744 
2745  if ( pa->npoints == 1 )
2746  {
2747  p = getPoint2d_cp(pa, 0);
2748  ll2cart(p, &A1);
2749  gbox->xmin = gbox->xmax = A1.x;
2750  gbox->ymin = gbox->ymax = A1.y;
2751  gbox->zmin = gbox->zmax = A1.z;
2752  return LW_SUCCESS;
2753  }
2754 
2755  p = getPoint2d_cp(pa, 0);
2756  ll2cart(p, &A1);
2757 
2758  for ( i = 1; i < pa->npoints; i++ )
2759  {
2760 
2761  p = getPoint2d_cp(pa, i);
2762  ll2cart(p, &A2);
2763 
2764  edge_calculate_gbox(&A1, &A2, &edge_gbox);
2765 
2766  /* Initialize the box */
2767  if ( first )
2768  {
2769  gbox_duplicate(&edge_gbox, gbox);
2770  first = LW_FALSE;
2771  }
2772  /* Expand the box where necessary */
2773  else
2774  {
2775  gbox_merge(&edge_gbox, gbox);
2776  }
2777 
2778  A1 = A2;
2779  }
2780 
2781  return LW_SUCCESS;
2782 }
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: gbox.c:257
void gbox_duplicate(const GBOX *original, GBOX *duplicate)
Copy the values of original GBOX into duplicate.
Definition: gbox.c:433
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: gbox.c:40
#define LW_FALSE
Definition: liblwgeom.h:109
#define LW_FAILURE
Definition: liblwgeom.h:111
#define LW_SUCCESS
Definition: liblwgeom.h:112
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:108
void ll2cart(const POINT2D *g, POINT3D *p)
Convert lon/lat coordinates to cartesian coordinates on unit sphere.
Definition: lwgeodetic.c:423
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:1362
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:101
double ymax
Definition: liblwgeom.h:372
double zmax
Definition: liblwgeom.h:374
double xmax
Definition: liblwgeom.h:370
double zmin
Definition: liblwgeom.h:373
double ymin
Definition: liblwgeom.h:371
double xmin
Definition: liblwgeom.h:369
lwflags_t flags
Definition: liblwgeom.h:368
double z
Definition: liblwgeom.h:417
double x
Definition: liblwgeom.h:417
double y
Definition: liblwgeom.h:417
uint32_t npoints
Definition: liblwgeom.h:442

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().

Here is the call graph for this function:
Here is the caller graph for this function: