Made convexhull use input bbox cache if any for output geom.
authorSandro Santilli <strk@keybit.net>
Fri, 31 Dec 2004 10:28:29 +0000 (10:28 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 31 Dec 2004 10:28:29 +0000 (10:28 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1203 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_geos.c

index 14275afdb6b3cd47f285ca2c8df53705bc5c0e8d..3a625aa1d51242995457999847d76275a9e7474e 100644 (file)
@@ -540,6 +540,7 @@ Datum convexhull(PG_FUNCTION_ARGS)
        PG_LWGEOM *geom1;
        Geometry *g1, *g3;
        PG_LWGEOM *result;
+       LWGEOM *lwout;
        int SRID;
 
 #ifdef PROFILE
@@ -577,7 +578,22 @@ Datum convexhull(PG_FUNCTION_ARGS)
 
        //elog(NOTICE,"result: %s", GEOSasText(g3) ) ;
        GEOSSetSRID(g3, SRID);
-       result = GEOS2POSTGIS(g3, TYPE_NDIMS(geom1->type) > 2);
+
+       lwout = lwgeom_from_geometry(g3, TYPE_NDIMS(geom1->type) > 2);
+       if (result == NULL)
+       {
+               GEOSdeleteGeometry(g1);
+               GEOSdeleteGeometry(g3);
+               elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
+               PG_RETURN_NULL(); //never get here
+       }
+
+       /* Have lwgeom bbox point to input one (if any) */
+       lwout->bbox = getbox2d_internal(SERIALIZED_FORM(geom1));
+       /* Mark lwgeom bbox to be externally owned */
+       TYPE_SETHASBBOX(lwout->type, 1);
+
+       result = pglwgeom_serialize(lwout);
        if (result == NULL)
        {
                GEOSdeleteGeometry(g1);
@@ -585,6 +601,7 @@ Datum convexhull(PG_FUNCTION_ARGS)
                elog(ERROR,"GEOS convexhull() threw an error (result postgis geometry formation)!");
                PG_RETURN_NULL(); //never get here
        }
+       lwgeom_release(lwout);
        GEOSdeleteGeometry(g1);
        GEOSdeleteGeometry(g3);