]> granicus.if.org Git - postgis/commitdiff
Fix bbox on collection level in TWKB output, #3187
authorNicklas Avén <nicklas.aven@jordogskog.no>
Mon, 13 Jul 2015 21:32:21 +0000 (21:32 +0000)
committerNicklas Avén <nicklas.aven@jordogskog.no>
Mon, 13 Jul 2015 21:32:21 +0000 (21:32 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13801 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwout_twkb.c
regress/twkb.sql
regress/twkb_expected

index 04d817432b5a3ea298e36925986a0f0c7f0874b9..ae542e824940367362a5e422708d9c1951cbef4b 100644 (file)
@@ -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]<parent_state->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);
 
index f5baeed391ece795fb143fa2cc4a8a8c129780d1..5ff31ed183468c7dfc5afec00988fc41301a360e 100644 (file)
@@ -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');
 
index 3105220ac594b713833d6e068763ffb3d0288df3..418732f2afaf1da91eb5320c588ed29b5b59937b 100644 (file)
@@ -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