]> granicus.if.org Git - postgis/commitdiff
collect(geom, geom) and collect_garray(geom[]) use WHEN_SIMPLE strategy
authorSandro Santilli <strk@keybit.net>
Wed, 5 Jan 2005 09:47:58 +0000 (09:47 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 5 Jan 2005 09:47:58 +0000 (09:47 +0000)
for bbox computation. pglwgeom_serialize() honour user's AUTOCACHE_BBOX
define. BBOXCACHE_BEHAVIOURS updated.

git-svn-id: http://svn.osgeo.org/postgis/trunk@1217 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/BBOXCACHE_BEHAVIOURS
lwgeom/lwgeom_functions_basic.c
lwgeom/lwgeom_pg.c

index eaf1ca499447256dac0e443c802f733c701953d9..ae51929919af2ad53e26f29aa95e4b005385d13b 100644 (file)
@@ -36,6 +36,11 @@ points where some BBOX caching strategies could be enforced).
        *EXP*   Uses deprecated LWEXPLODED, and LWEXPLODED_serialize()
 
        *LWG*   Uses LWGEOM, pglwgeom_serialize()
+
+
+AUTOCACHE_BBOX is currently used by all functions using *LWG* 
+(pglwgeom_serialize entry point). Other functions explicitly
+listed in the AUTOCACHE_BBOX section also use it.
        
 
 [ explicit control ]
@@ -90,6 +95,12 @@ points where some BBOX caching strategies could be enforced).
        multi(geometry) **SRL**
        envelope(geometry) *SRL*
 
+       ### computes union of
+       ### input bbox (if all available)
+       collect(geometry, geometry) *LWG*
+       collect_garray (geometry[]) *LWG*
+       
+
        ## These use LWGEOM as a mean to access and modigy SERIALIZED form
        reverse(geometry) *LWG* **SRL**
        ForceRHR(geometry) *LWG* **SRL**
@@ -104,11 +115,6 @@ points where some BBOX caching strategies could be enforced).
        StartPoint(geometry) *SRL*
        EndPoint(geometry) *SRL*
 
-       ### could use WHEN_SIMPLE computing union of
-       ### input bbox (if available or SIMPLE to compute: points)
-       collect(geometry, geometry) *LWG*
-       collect_garray (geometry[]) *LWG*
-       
        makePoint(float8, float8, [float8], [float8]) *LWG*
        makePointM(float8, float8, float8) *LWG*
        makeline_garray (geometry[]) *LWG*
index 9304a8f147c778fd4b6ff481b204226594b3eca9..643a299d4f035e62d4d97636d3bae704ecf58cf4 100644 (file)
@@ -1572,6 +1572,7 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
        PG_LWGEOM *pglwgeom1, *pglwgeom2, *result;
        LWGEOM *lwgeoms[2], *outlwg;
        unsigned int type1, type2, outtype;
+       BOX2DFLOAT4 *box=NULL;
 
        // return null if both geoms are null
        if ( (geom1_ptr == NULL) && (geom2_ptr == NULL) )
@@ -1619,9 +1620,25 @@ Datum LWGEOM_collect(PG_FUNCTION_ARGS)
        elog(NOTICE, " outtype = %d", outtype);
 #endif
 
+       /* COMPUTE_BBOX WHEN_SIMPLE */
+       if ( lwgeoms[0]->bbox && lwgeoms[1]->bbox )
+       {
+               box = palloc(sizeof(BOX2DFLOAT4));
+               box->xmin = LW_MIN(lwgeoms[0]->bbox->xmin, lwgeoms[1]->bbox->xmin);
+               box->ymin = LW_MIN(lwgeoms[0]->bbox->ymin, lwgeoms[1]->bbox->ymin);
+               box->xmax = LW_MAX(lwgeoms[0]->bbox->xmax, lwgeoms[1]->bbox->xmax);
+               box->ymax = LW_MAX(lwgeoms[0]->bbox->ymax, lwgeoms[1]->bbox->ymax);
+       }
+
+       /* Drop input geometries bbox and SRID */
+       lwgeom_dropBBOX(lwgeoms[0]);
+       lwgeom_dropSRID(lwgeoms[0]);
+       lwgeom_dropBBOX(lwgeoms[1]);
+       lwgeom_dropSRID(lwgeoms[1]);
+
        outlwg = (LWGEOM *)lwcollection_construct(
                outtype, lwgeoms[0]->SRID,
-               NULL, 2, lwgeoms);
+               box, 2, lwgeoms);
 
        result = pglwgeom_serialize(outlwg);
 
@@ -1773,6 +1790,7 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
        int i;
        int SRID=-1;
        size_t offset;
+       BOX2DFLOAT4 *box=NULL;
 
 #ifdef DEBUG
        elog(NOTICE, "LWGEOM_collect_garray called");
@@ -1829,19 +1847,46 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
        elog(NOTICE, "LWGEOM_collect_garray: geom %d deserialized", i);
 #endif
 
-               // Check SRID homogeneity
-               if ( ! i ) {
+               if ( ! i )
+               {
                        /* Get first geometry SRID */
                        SRID = lwgeoms[i]->SRID; 
-               } else {
+
+                       /* COMPUTE_BBOX WHEN_SIMPLE */
+                       if ( lwgeoms[i]->bbox ) {
+                               box = palloc(sizeof(BOX2DFLOAT4));
+                               memcpy(box, lwgeoms[i]->bbox, sizeof(BOX2DFLOAT4));
+                       }
+               }
+               else
+               {
+                       // Check SRID homogeneity
                        if ( lwgeoms[i]->SRID != SRID )
                        {
                                elog(ERROR,
                                        "Operation on mixed SRID geometries");
                                PG_RETURN_NULL();
                        }
+
+                       /* COMPUTE_BBOX WHEN_SIMPLE */
+                       if ( box )
+                       {
+                               if ( lwgeoms[i]->bbox )
+                               {
+                                       box->xmin = LW_MIN(box->xmin, lwgeoms[i]->bbox->xmin);
+                                       box->ymin = LW_MIN(box->ymin, lwgeoms[i]->bbox->ymin);
+                                       box->xmax = LW_MAX(box->xmax, lwgeoms[i]->bbox->xmax);
+                                       box->ymax = LW_MAX(box->ymax, lwgeoms[i]->bbox->ymax);
+                               }
+                               else
+                               {
+                                       pfree(box);
+                                       box = NULL;
+                               }
+                       }
                }
 
+
                lwgeom_dropSRID(lwgeoms[i]);
                lwgeom_dropBBOX(lwgeoms[i]);
 
@@ -1868,7 +1913,7 @@ Datum LWGEOM_collect_garray(PG_FUNCTION_ARGS)
 
        outlwg = (LWGEOM *)lwcollection_construct(
                outtype, SRID,
-               NULL, nelems, lwgeoms);
+               box, nelems, lwgeoms);
 
        result = pglwgeom_serialize(outlwg);
 
index f5339f48b78ba57f33f7f6887b6a8187a5003d7e..411d06d517f0e046a00d5e165ce09f53a7e26cc9 100644 (file)
@@ -106,6 +106,13 @@ pglwgeom_serialize(LWGEOM *in)
        size_t size;
        PG_LWGEOM *result;
 
+#if AUTOCACHE_BBOX
+       if ( ! in->bbox && is_worth_caching_lwgeom_bbox(in) )
+       {
+               lwgeom_addBBOX(in);
+       }
+#endif
+
        size = lwgeom_serialize_size(in) + VARHDRSZ;
        //lwnotice("lwgeom_serialize_size returned %d", size-VARHDRSZ);
        result = palloc(size);