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

Definition at line 1699 of file lwgeom_functions_basic.c.

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

1700 {
1701  GSERIALIZED *pg_lwgeom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1702  LWGEOM *lwgeom = lwgeom_from_gserialized(pg_lwgeom);
1703  GBOX gbox;
1704  int result;
1705  BOX *out = NULL;
1706 
1707  /* Zero out flags */
1708  gbox_init(&gbox);
1709 
1710  /* Calculate the GBOX of the geometry */
1711  result = lwgeom_calculate_gbox(lwgeom, &gbox);
1712 
1713  /* Clean up memory */
1714  lwfree(lwgeom);
1715  PG_FREE_IF_COPY(pg_lwgeom, 0);
1716 
1717  /* Null on failure */
1718  if ( ! result )
1719  PG_RETURN_NULL();
1720 
1721  out = lwalloc(sizeof(BOX));
1722  out->low.x = gbox.xmin;
1723  out->low.y = gbox.ymin;
1724  out->high.x = gbox.xmax;
1725  out->high.y = gbox.ymax;
1726  PG_RETURN_POINTER(out);
1727 }
void lwfree(void *mem)
Definition: lwutil.c:190
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
double xmax
Definition: liblwgeom.h:249
char ** result
Definition: liblwgeom.h:218
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:608
double ymin
Definition: liblwgeom.h:250
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:34
double xmin
Definition: liblwgeom.h:248
double ymax
Definition: liblwgeom.h:251
void * lwalloc(size_t size)
Definition: lwutil.c:175

Here is the call graph for this function: