PostGIS  2.3.7dev-r@@SVN_REVISION@@
Datum LWGEOM_to_BOX ( PG_FUNCTION_ARGS  )

Definition at line 1660 of file lwgeom_functions_basic.c.

References gbox_init(), lwalloc(), lwfree(), lwgeom_calculate_gbox(), lwgeom_from_gserialized(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

1661 {
1662  GSERIALIZED *pg_lwgeom = PG_GETARG_GSERIALIZED_P(0);
1663  LWGEOM *lwgeom = lwgeom_from_gserialized(pg_lwgeom);
1664  GBOX gbox;
1665  int result;
1666  BOX *out = NULL;
1667 
1668  /* Zero out flags */
1669  gbox_init(&gbox);
1670 
1671  /* Calculate the GBOX of the geometry */
1672  result = lwgeom_calculate_gbox(lwgeom, &gbox);
1673 
1674  /* Clean up memory */
1675  lwfree(lwgeom);
1676  PG_FREE_IF_COPY(pg_lwgeom, 0);
1677 
1678  /* Null on failure */
1679  if ( ! result )
1680  PG_RETURN_NULL();
1681 
1682  out = lwalloc(sizeof(BOX));
1683  out->low.x = gbox.xmin;
1684  out->low.y = gbox.ymin;
1685  out->high.x = gbox.xmax;
1686  out->high.y = gbox.ymax;
1687  PG_RETURN_POINTER(out);
1688 }
void lwfree(void *mem)
Definition: lwutil.c:242
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:292
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:665
double ymin
Definition: liblwgeom.h:293
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:51
double xmin
Definition: liblwgeom.h:291
double ymax
Definition: liblwgeom.h:294
void * lwalloc(size_t size)
Definition: lwutil.c:227

Here is the call graph for this function: