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

Definition at line 116 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().

117 {
118  GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
119  LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
120  GBOX gbox;
121 
122  /* Cannot box empty! */
123  if ( lwgeom_is_empty(lwgeom) )
124  PG_RETURN_NULL();
125 
126  /* Cannot calculate box? */
127  if ( lwgeom_calculate_gbox(lwgeom, &gbox) == LW_FAILURE )
128  PG_RETURN_NULL();
129 
130  /* Strip out higher dimensions */
131  FLAGS_SET_Z(gbox.flags, 0);
132  FLAGS_SET_M(gbox.flags, 0);
133 
134  PG_FREE_IF_COPY(geom, 0);
135  PG_RETURN_POINTER(gbox_copy(&gbox));
136 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:433
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define LW_FAILURE
Definition: liblwgeom.h:78
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:739
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:145
uint8_t flags
Definition: liblwgeom.h:290
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:1386
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:146

Here is the call graph for this function: