From: Sandro Santilli Date: Thu, 30 Dec 2004 15:59:41 +0000 (+0000) Subject: Fixed a bug in translate() and transform() leaving result geometries with X-Git-Tag: pgis_1_0_0RC1~106 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b027f1d2f3ce34208fb29ae4702e1d48241fb40;p=postgis Fixed a bug in translate() and transform() leaving result geometries with the old bounding box cache. git-svn-id: http://svn.osgeo.org/postgis/trunk@1198 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/lwgeom_functions_basic.c b/lwgeom/lwgeom_functions_basic.c index a7deced32..6860bb8a7 100644 --- a/lwgeom/lwgeom_functions_basic.c +++ b/lwgeom/lwgeom_functions_basic.c @@ -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); } diff --git a/lwgeom/lwgeom_transform.c b/lwgeom/lwgeom_transform.c index 49700256a..8c3babb6c 100644 --- a/lwgeom/lwgeom_transform.c +++ b/lwgeom/lwgeom_transform.c @@ -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 }