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

Definition at line 103 of file lwgeom_box.c.

References GBOX::flags, FLAGS_SET_M, FLAGS_SET_Z, gbox_copy(), LW_FAILURE, lwgeom_calculate_gbox(), lwgeom_from_gserialized(), and lwgeom_is_empty().

104 {
105  GSERIALIZED *geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
106  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
107  GBOX gbox;
108 
109  /* Cannot box empty! */
110  if ( lwgeom_is_empty(lwgeom) )
111  PG_RETURN_NULL();
112 
113  /* Cannot calculate box? */
114  if ( lwgeom_calculate_gbox(lwgeom, &gbox) == LW_FAILURE )
115  PG_RETURN_NULL();
116 
117  /* Strip out higher dimensions */
118  FLAGS_SET_Z(gbox.flags, 0);
119  FLAGS_SET_M(gbox.flags, 0);
120 
121  PG_RETURN_POINTER(gbox_copy(&gbox));
122 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:362
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define LW_FAILURE
Definition: liblwgeom.h:54
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
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:112
uint8_t flags
Definition: liblwgeom.h:247
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1229
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:113

Here is the call graph for this function: