]> granicus.if.org Git - postgis/commitdiff
added extent(lwgeom) and support functions.
authorSandro Santilli <strk@keybit.net>
Tue, 17 Aug 2004 15:27:47 +0000 (15:27 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 17 Aug 2004 15:27:47 +0000 (15:27 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@682 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom.sql.in
lwgeom/lwgeom_functions_basic.c

index 8bd98ef21c0450f79e57d808fbea67d2c3534a8b..5ce39f61e084e6e0a72db3aa764e513dc6bccbfc 100644 (file)
@@ -394,6 +394,20 @@ CREATE CAST (lwgeom as box2d) WITH FUNCTION box2d(lwgeom)  AS IMPLICIT ;
 CREATE CAST (lwgeom as wkb) WITH FUNCTION wkb(lwgeom)  AS IMPLICIT ;
 CREATE CAST (wkb as lwgeom) WITH FUNCTION lwgeom(wkb)  AS IMPLICIT ;
        
+--
+-- Aggregate functions
+--
+
+CREATEFUNCTION combine_bbox(box2d,lwgeom)
+       RETURNS box2d
+       AS '@MODULE_FILENAME@', 'combine_box2d'
+       LANGUAGE 'C';
+
+CREATE AGGREGATE extent(
+       sfunc = combine_bbox,
+       basetype = lwgeom,
+       stype = box2d
+       );
 
 COMMIT;
 
index 88ae6ae9833a4922af1e779fab5bab8f7e90f08b..10b2dc7a686ff94d1c807c1db00cc875bd846ff4 100644 (file)
@@ -27,6 +27,7 @@
 Datum LWGEOM_getSRID(PG_FUNCTION_ARGS);
 Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS);
 Datum LWGEOM_setSRID(PG_FUNCTION_ARGS);
+Datum combine_box2d(PG_FUNCTION_ARGS);
 
 
 // getSRID(lwgeom) :: int4
@@ -140,3 +141,51 @@ Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS)
 
        PG_RETURN_POINTER(text_ob);
 }
+
+PG_FUNCTION_INFO_V1(combine_box2d);
+Datum combine_box2d(PG_FUNCTION_ARGS)
+{
+       Pointer box2d_ptr = PG_GETARG_POINTER(0);
+       Pointer geom_ptr = PG_GETARG_POINTER(1);
+       BOX2DFLOAT4 *a,*b;
+       char *lwgeom;
+       BOX2DFLOAT4 box, *result;
+
+       if  ( (box2d_ptr == NULL) && (geom_ptr == NULL) )
+       {
+               PG_RETURN_NULL(); // combine_box2d(null,null) => null
+       }
+
+       result = (BOX2DFLOAT4 *)palloc(sizeof(BOX2DFLOAT4));
+
+       if (box2d_ptr == NULL)
+       {
+               lwgeom = (char *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+
+               box = getbox2d(lwgeom+4);
+               memcpy(result, &box, sizeof(BOX2DFLOAT4));
+               PG_RETURN_POINTER(result);
+       }
+
+       // combine_bbox(BOX3D, null) => BOX3D
+       if (geom_ptr == NULL)
+       {
+               memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(BOX2DFLOAT4));
+               PG_RETURN_POINTER(result);
+       }
+
+       //combine_bbox(BOX3D, geometry) => union(BOX3D, geometry->bvol)
+
+       lwgeom = (char *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+       box = getbox2d(lwgeom+4);
+
+       a = (BOX2DFLOAT4 *)PG_GETARG_DATUM(0);
+       b = &box;
+
+       result->xmax = LWGEOM_Maxf(a->xmax, b->xmax);
+       result->ymax = LWGEOM_Maxf(a->ymax, b->ymax);
+       result->xmin = LWGEOM_Minf(a->xmin, b->xmin);
+       result->ymin = LWGEOM_Minf(a->ymin, b->ymin);
+
+       PG_RETURN_POINTER(result);
+}