/**
* Pull a #GBOX from the header of a #GSERIALIZED, if one is available. If
-* it is not, return LW_FAILURE.
+* it is not, calculate it from the geometry. If that doesn't work (null
+* or empty) return LW_FAILURE.
*/
extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox);
{
Datum datum;
GSERIALIZED *serialized;
-
+
/* Fetch the datum and cast it into a geography */
datum = fetchfunc(stats, i, &isnull);
+ serialized = (GSERIALIZED*)PG_DETOAST_DATUM(datum);
/* Skip nulls */
if (isnull)
continue;
/* Convert coordinates to 3D geodesic */
- if ( ! gserialized_datum_get_gbox_p(datum, &gbox) )
+ if ( ! gserialized_get_gbox_p(serialized, &gbox) )
{
/* Unable to obtain or calculate a bounding box */
POSTGIS_DEBUGF(3, "skipping geometry at position %d", i);