]> granicus.if.org Git - postgis/commitdiff
Fixed a bug in translate() and transform() leaving result geometries with
authorSandro Santilli <strk@keybit.net>
Thu, 30 Dec 2004 15:59:41 +0000 (15:59 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 30 Dec 2004 15:59:41 +0000 (15:59 +0000)
the old bounding box cache.

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

lwgeom/lwgeom_functions_basic.c
lwgeom/lwgeom_transform.c

index a7deced32f4e5885a015f80ae27776738aae5cf8..6860bb8a779d9eaee2386a4291ec4997fafab4ef 100644 (file)
@@ -1479,11 +1479,24 @@ PG_FUNCTION_INFO_V1(LWGEOM_translate);
 Datum LWGEOM_translate(PG_FUNCTION_ARGS)
 {
        PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0));
+       PG_LWGEOM *oldgeom;
+       char *srl = SERIALIZED_FORM(geom);
+
        double xoff =  PG_GETARG_FLOAT8(1);
        double yoff =  PG_GETARG_FLOAT8(2);
        double zoff =  PG_GETARG_FLOAT8(3);
 
-       lwgeom_translate_recursive(SERIALIZED_FORM(geom), xoff, yoff, zoff);
+       lwgeom_translate_recursive(srl, xoff, yoff, zoff);
+
+       if ( TYPE_HASBBOX(geom->type) ) 
+       {
+               if ( ! compute_serialized_bbox_p(srl, getbox2d_internal(srl)) )
+               {
+                       oldgeom = geom;
+                       geom = PG_LWGEOM_construct(srl, lwgeom_getSRID(geom), 0);
+                       lwfree(oldgeom);
+               }
+       }
 
        PG_RETURN_POINTER(geom);
 }
index 49700256a16b305e917a34227a31824626522981..8c3babb6c811fe626f69ae661dda3d41b4e56634 100644 (file)
@@ -240,13 +240,14 @@ lwgeom_transform_recursive(char *geom, PJ *inpj, PJ *outpj)
 PG_FUNCTION_INFO_V1(transform_geom);
 Datum transform_geom(PG_FUNCTION_ARGS)
 {
-       PG_LWGEOM *geom;
+       PG_LWGEOM *geom, *oldgeom;
        PG_LWGEOM *result=NULL;
        PJ *input_pj,*output_pj;
        char *input_proj4, *output_proj4;
        text *input_proj4_text;
        text *output_proj4_text;
        int32 result_srid ;
+       char *srl;
 
        result_srid   = PG_GETARG_INT32(3);
        if (result_srid  == -1)
@@ -310,6 +311,18 @@ Datum transform_geom(PG_FUNCTION_ARGS)
        pj_free(output_pj);
        pfree(input_proj4); pfree(output_proj4);
 
+       // Compute bbox if input had one
+       if ( TYPE_HASBBOX(result->type) ) 
+       {
+               srl = SERIALIZED_FORM(result);
+               if ( ! compute_serialized_bbox_p(srl, getbox2d_internal(srl)) )
+               {
+                       oldgeom = result;
+                       result = PG_LWGEOM_construct(srl, lwgeom_getSRID(result), 0);
+                       lwfree(oldgeom);
+               }
+       }
+
        PG_RETURN_POINTER(result); // new geometry
 }