From d09a9bf053d678fbd29aea6d0077f0768640f7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicklas=20Av=C3=A9n?= Date: Mon, 13 Jul 2015 21:32:21 +0000 Subject: [PATCH] Fix bbox on collection level in TWKB output, #3187 git-svn-id: http://svn.osgeo.org/postgis/trunk@13801 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/lwout_twkb.c | 16 ++++++++++++++++ regress/twkb.sql | 22 ++-------------------- regress/twkb_expected | 1 + 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/liblwgeom/lwout_twkb.c b/liblwgeom/lwout_twkb.c index 04d817432..ae542e824 100644 --- a/liblwgeom/lwout_twkb.c +++ b/liblwgeom/lwout_twkb.c @@ -493,6 +493,21 @@ static int lwgeom_write_to_buffer(const LWGEOM *geom, TWKB_GLOBALS *globals, TWK /* Write the TWKB into the output buffer */ lwgeom_to_twkb_buf(geom, globals, &child_state); + /*If we have a header_buf, we know that this function is called inside a collection*/ + /*and then we have to merge the bboxes of the included geometries*/ + /*and put the result to the parent (the collection)*/ + if( (globals->variant & TWKB_BBOX) && parent_state->header_buf ) + { + LWDEBUG(4,"Merge bboxes"); + for ( i = 0; i < ndims; i++ ) + { + if(child_state.bbox_min[i]bbox_min[i]) + parent_state->bbox_min[i] = child_state.bbox_min[i]; + if(child_state.bbox_max[i]>parent_state->bbox_max[i]) + parent_state->bbox_max[i] = child_state.bbox_max[i]; + } + } + /* Did we have a box? If so, how big? */ bbox_size = 0; if( globals->variant & TWKB_BBOX ) @@ -562,6 +577,7 @@ lwgeom_to_twkb_with_idlist(const LWGEOM *geom, int64_t *idlist, uint8_t variant, } ts.idlist = idlist; + ts.header_buf = NULL; ts.geom_buf = bytebuffer_create(); lwgeom_write_to_buffer(geom, &tg, &ts); diff --git a/regress/twkb.sql b/regress/twkb.sql index f5baeed39..5ff31ed18 100644 --- a/regress/twkb.sql +++ b/regress/twkb.sql @@ -61,24 +61,6 @@ union all select 'POLYGON((1 1, 1 2, 2 2, 2 1, 1 1))'::text g ) foo; - ---Aggregated geoemtries with preserved id --- select st_astext(st_collect(g::geometry)), encode(ST_AsTWKBagg(g::geometry,0),'hex') from --- ( --- select 'POINT(1 1)'::text g --- union all --- select 'POINT(2 2)'::text g --- ) foo; - ---Aggregated geoemtries with preserved id --- select st_astext(st_collect(g::geometry)), encode(ST_AsTWKBagg(g::geometry,0),'hex') from --- ( --- select 'MULTIPOINT((1 1),(2 2))'::text g --- union all --- select 'POINT(78 -78)'::text g --- union all --- select 'POLYGON((1 1, 1 2, 2 2, 2 1, 1 1))'::text g --- ) foo; - - +--GEOMETRYCOLLECTION with bounding box ref #3187 +select encode(st_astwkb(st_collect('point(4 1)'::geometry,'linestring(1 1, 0 3)'::geometry),0,0,0,false,true),'hex'); diff --git a/regress/twkb_expected b/regress/twkb_expected index 3105220ac..418732f2a 100644 --- a/regress/twkb_expected +++ b/regress/twkb_expected @@ -13,3 +13,4 @@ MULTIPOLYGON(((1 1, 1 2, 2 2, 2 1, 1 1)),((3 3,3 4,4 4,4 3,3 3)))|06000201050202 MULTIPOLYGON(((1 1, 1 20, 20 20, 20 1, 1 1),(3 3,3 4, 4 4,4 3,3 3)),((-1 1, -1 20, -20 20, -20 1, -1 1),(-3 3,-3 4, -4 4,-4 3,-3 3)))|06000202050202002626000025250005040400020200000101000205070300262500002526000503040002010000010200 GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(2 2,3 3))|0700020100020202000204040202 GEOMETRYCOLLECTION(MULTIPOINT(1 1,2 2),POINT(78 -78),POLYGON((1 1,1 2,2 2,2 1,1 1)))|0700030400020202020201009c019b010300010502020002020000010100 +0701000802040201010800020008020201000202040202020104