/* Copy a new bounding box into an existing gserialized */
GSERIALIZED* gserialized_set_gidx(GSERIALIZED *g, GIDX *gidx);
-/* Pull out a gbox bounding box as fast as possible. */
-int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox);
/* Given two datums, do they overlap? Computed very fast using embedded boxes. */
/* int gserialized_datum_overlaps(Datum gs1, Datum gs2); */
/* Remove the box from a disk serialization */
*/
GSERIALIZED* geography_serialize(LWGEOM *lwgeom);
+/**
+* Pull out a gbox bounding box as fast as possible.
+* Tries to read cached box from front of serialized vardata.
+* If no cached box, calculates box from scratch.
+* Fails on empty.
+*/
+int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox);
+
/**
* Convert cstrings (null-terminated byte array) to textp pointers
* (PgSQL varlena structure with VARSIZE header).
int geogstats_nvalues = 0;
Node *other;
Var *self;
- GSERIALIZED *serialized;
- LWGEOM *geometry;
GBOX search_box;
float8 selectivity = 0;
/*
* Convert the constant to a GBOX
*/
- serialized = (GSERIALIZED *)PG_DETOAST_DATUM( ((Const*)other)->constvalue );
- geometry = lwgeom_from_gserialized(serialized);
/* Convert coordinates to 3D geodesic */
FLAGS_SET_GEODETIC(search_box.flags, 1);
- if (!lwgeom_calculate_gbox_geodetic(geometry, &search_box))
+ if ( ! gserialized_datum_get_gbox_p(((Const*)other)->constvalue, &search_box) )
{
POSTGIS_DEBUG(3, " search box cannot be calculated");
-
PG_RETURN_FLOAT8(0.0);
}
if (isnull)
continue;
- serialized = (GSERIALIZED *)PG_DETOAST_DATUM(datum);
- geometry = lwgeom_from_gserialized(serialized);
+// serialized = (GSERIALIZED *)PG_DETOAST_DATUM(datum);
+// geometry = lwgeom_from_gserialized(serialized);
/* Convert coordinates to 3D geodesic */
- if (!lwgeom_calculate_gbox_geodetic(geometry, &gbox))
+ if ( ! gserialized_datum_get_gbox_p(datum, &gbox) )
{
/* Unable to obtain or calculate a bounding box */
POSTGIS_DEBUGF(3, "skipping geometry at position %d", i);
}
/** TODO: ask if we need geom or bvol size for stawidth */
- total_width += serialized->size;
+ total_width += VARSIZE(serialized);
#if USE_STANDARD_DEVIATION
/*
}
/** TODO: ask if we need geom or bvol size for stawidth */
- total_width += geom->size;
+ total_width += VARSIZE(geom);
total_boxes_area += (box.xmax-box.xmin)*(box.ymax-box.ymin);
#if USE_STANDARD_DEVIATION