]> granicus.if.org Git - postgis/commitdiff
Move box-reading code in geography stats to use serialized box.
authorPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 19 Nov 2012 23:04:21 +0000 (23:04 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 19 Nov 2012 23:04:21 +0000 (23:04 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10707 b70326c6-7e19-0410-871a-916f4a2858ee

libpgcommon/gserialized_gist.h
libpgcommon/lwgeom_pg.h
postgis/geography_estimate.c
postgis/geometry_estimate.c

index 72b73d3237d4b830b7b4d5703aba59126e50dedf..4f44f373c997b39c5adba390b8b3c78ea45b2df9 100644 (file)
@@ -92,8 +92,6 @@ int gserialized_get_gidx_p(GSERIALIZED *g, GIDX *gidx);
 /* 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 */
index 4dcef332d89af92eecf73b33327c331c6d1ed0f7..ab3d3ce09f4efac00c6c9983f79256eb76052763 100644 (file)
@@ -101,6 +101,14 @@ GSERIALIZED *geometry_serialize(LWGEOM *lwgeom);
 */
 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).
index 6e7854bed62c2bcbff9c2d84b554e0aef8294a1a..fcae2bb8dc305c5ab5521750af9f93330c3666d7 100644 (file)
@@ -453,8 +453,6 @@ Datum geography_gist_selectivity(PG_FUNCTION_ARGS)
        int geogstats_nvalues = 0;
        Node *other;
        Var *self;
-       GSERIALIZED *serialized;
-       LWGEOM *geometry;
        GBOX search_box;
        float8 selectivity = 0;
 
@@ -509,15 +507,12 @@ Datum geography_gist_selectivity(PG_FUNCTION_ARGS)
        /*
         * 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);
        }
 
@@ -863,11 +858,11 @@ compute_geography_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
                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);
@@ -912,7 +907,7 @@ compute_geography_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
                }
 
                /** TODO: ask if we need geom or bvol size for stawidth */
-               total_width += serialized->size;
+               total_width += VARSIZE(serialized);
 
 #if USE_STANDARD_DEVIATION
                /*
index c1ef09dc90f37be5c4c83bc692a6b9b7ded83838..9ba5954da4da8b5bb69bf22de2a3cbd0eb2e6159 100644 (file)
@@ -905,7 +905,7 @@ compute_geometry_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
                }
 
                /** 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