From: Sandro Santilli Date: Wed, 5 Jan 2005 22:11:03 +0000 (+0000) Subject: Made apply_grid compute output bbox WHEN_SIMPLE (input bbox is present) X-Git-Tag: pgis_1_0_0RC1~81 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7b1361128b0d05d21c286089a13419d8e6522db;p=postgis Made apply_grid compute output bbox WHEN_SIMPLE (input bbox is present) git-svn-id: http://svn.osgeo.org/postgis/trunk@1223 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/BBOXCACHE_BEHAVIOURS b/lwgeom/BBOXCACHE_BEHAVIOURS index 144c82ece..eed4d6d38 100644 --- a/lwgeom/BBOXCACHE_BEHAVIOURS +++ b/lwgeom/BBOXCACHE_BEHAVIOURS @@ -100,7 +100,9 @@ section also use it. ### input bbox (if all available) collect(geometry, geometry) *LWG* collect_garray (geometry[]) *LWG* - + + ## apply grid to eventually present box in input + apply_grid(geometry, float8, float8, float8, float8); ## These use LWGEOM as a mean to access and modigy SERIALIZED form reverse(geometry) *LWG* **SRL** diff --git a/lwgeom/lwgeom_functions_analytic.c b/lwgeom/lwgeom_functions_analytic.c index 81c6eacab..567361fad 100644 --- a/lwgeom/lwgeom_functions_analytic.c +++ b/lwgeom/lwgeom_functions_analytic.c @@ -308,6 +308,7 @@ Datum LWGEOM_simplify2d(PG_FUNCTION_ARGS) double dist = PG_GETARG_FLOAT8(1); out = simplify2d_lwgeom(in, dist); + if ( ! out ) PG_RETURN_NULL(); /* COMPUTE_BBOX TAINTING */ if ( in->bbox ) lwgeom_addBBOX(out); @@ -793,8 +794,8 @@ Datum LWGEOM_apply_grid(PG_FUNCTION_ARGS) LWGEOM *in_lwgeom; PG_LWGEOM *out_geom = NULL; LWGEOM *out_lwgeom; - size_t size; gridspec grid; + BOX2DFLOAT4 *box; if ( PG_ARGISNULL(0) ) PG_RETURN_NULL(); datum = PG_GETARG_DATUM(0); @@ -824,14 +825,26 @@ Datum LWGEOM_apply_grid(PG_FUNCTION_ARGS) out_lwgeom = lwgeom_grid(in_lwgeom, &grid); if ( out_lwgeom == NULL ) PG_RETURN_NULL(); + /* COMPUTE_BBOX WHEN_SIMPLE */ + if ( in_lwgeom->bbox ) + { + box = palloc(sizeof(BOX2DFLOAT4)); + box->xmin = rint((in_lwgeom->bbox->xmin - grid.ipx)/grid.xsize) + * grid.xsize + grid.ipx; + box->xmax = rint((in_lwgeom->bbox->xmax - grid.ipx)/grid.xsize) + * grid.xsize + grid.ipx; + box->ymin = rint((in_lwgeom->bbox->ymin - grid.ipy)/grid.ysize) + * grid.ysize + grid.ipy; + box->ymax = rint((in_lwgeom->bbox->ymax - grid.ipy)/grid.ysize) + * grid.ysize + grid.ipy; + out_lwgeom->bbox = box; + } + #if VERBOSE elog(NOTICE, "apply_grid made a %s", lwgeom_typename(TYPE_GETTYPE(out_lwgeom->type))); #endif - size = lwgeom_serialize_size(out_lwgeom); - out_geom = palloc(size+4); - out_geom->size = size+4; - lwgeom_serialize_buf(out_lwgeom, SERIALIZED_FORM(out_geom), NULL); + out_geom = pglwgeom_serialize(out_lwgeom); PG_RETURN_POINTER(out_geom); }