]> granicus.if.org Git - postgis/commitdiff
#2019, ST_FlipCoordinates does not update bbox
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 2 Nov 2012 17:52:45 +0000 (17:52 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 2 Nov 2012 17:52:45 +0000 (17:52 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10621 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/cunit/cu_libgeom.c
liblwgeom/lwgeom.c

diff --git a/NEWS b/NEWS
index 5d50104d8ef5807b8d9abf41039332c24cc2f3ff..5fcaf4ef5012eb942caf44c61a0920b323d4df38 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -97,6 +97,8 @@ PostGIS 2.1.0
   - #2026, improve performance of distance calculations 
   - #2057, Fixed linking issue for raster2psql to libpq
   - #2077, Fixed incorrect values returning from ST_Hillshade()
+  - #2019, ST_FlipCoordinates does not update bbox
+
 
 PostGIS 2.0.1
 2012/06/22
index 4c1d958b854f00c58a1ad1187ba5c13800e5119e..5e41f44024b22d0e17f45a7ef505e8d688704fd5 100644 (file)
@@ -462,11 +462,27 @@ static void test_lwgeom_free(void)
 
 static void do_lwgeom_flip_coordinates(char *in, char *out)
 {
-       LWGEOM *g,*h;
+       LWGEOM *g;
        char * t;
+       double xmax, ymax;
+       int testbox;
 
        g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
-       h = lwgeom_flip_coordinates(g);
+       lwgeom_add_bbox(g);
+
+       if ( testbox = (g->bbox != NULL) )
+       {
+               xmax = g->bbox->xmax;
+               ymax = g->bbox->ymax;
+       }
+       
+       g = lwgeom_flip_coordinates(g);
+       
+       if ( testbox )
+       {
+               CU_ASSERT_DOUBLE_EQUAL(g->bbox->xmax, ymax, 0.00001);
+               CU_ASSERT_DOUBLE_EQUAL(g->bbox->ymax, xmax, 0.00001);
+       }
 
        t = lwgeom_to_wkt(g, WKT_EXTENDED, 8, NULL);
        if (t == NULL) fprintf(stderr, "In:%s", in);
@@ -872,7 +888,6 @@ static void test_lwgeom_same(void)
 
 }
 
-
 /*
 ** Used by test harness to register the tests in this file.
 */
@@ -896,6 +911,7 @@ CU_TestInfo libgeom_tests[] =
        PG_TEST(test_lwgeom_calculate_gbox),
        PG_TEST(test_lwgeom_is_empty),
        PG_TEST(test_lwgeom_same),
+       PG_TEST(test_lwgeom_flip_coordinates),
        CU_TEST_INFO_NULL
 };
 CU_SuiteInfo libgeom_suite = {"libgeom",  NULL,  NULL, libgeom_tests};
index 54dd155f949eeeca3a3aaf4182bff3cdf185fe40..ddfd917f6b2a2fe7ff1ec84b86b8e04c6de1f83a 100644 (file)
@@ -1313,6 +1313,9 @@ LWGEOM* lwgeom_flip_coordinates(LWGEOM *in)
        LWPOLY *poly;
        int i;
 
+       if ( (!in) || lwgeom_is_empty(in) )
+               return in;
+
        LWDEBUGF(4, "lwgeom_flip_coordinates, got type: %s",
                 lwtype_name(in->type));
 
@@ -1320,25 +1323,27 @@ LWGEOM* lwgeom_flip_coordinates(LWGEOM *in)
        {
        case POINTTYPE:
                ptarray_flip_coordinates(lwgeom_as_lwpoint(in)->point);
-               return in;
+               break;
 
        case LINETYPE:
                ptarray_flip_coordinates(lwgeom_as_lwline(in)->points);
-               return in;
+               break;
 
        case CIRCSTRINGTYPE:
                ptarray_flip_coordinates(lwgeom_as_lwcircstring(in)->points);
-               return in;
+               break;
 
        case POLYGONTYPE:
                poly = (LWPOLY *) in;
                for (i=0; i<poly->nrings; i++)
+               {
                        ptarray_flip_coordinates(poly->rings[i]);
-               return in;
+               }
+               break;
 
        case TRIANGLETYPE:
                ptarray_flip_coordinates(lwgeom_as_lwtriangle(in)->points);
-               return in;
+               break;
 
        case MULTIPOINTTYPE:
        case MULTILINETYPE:
@@ -1352,14 +1357,20 @@ LWGEOM* lwgeom_flip_coordinates(LWGEOM *in)
        case TINTYPE:
                col = (LWCOLLECTION *) in;
                for (i=0; i<col->ngeoms; i++)
+               {
                        lwgeom_flip_coordinates(col->geoms[i]);
-               return in;
+               }
+               break;
 
        default:
                lwerror("lwgeom_flip_coordinates: unsupported geometry type: %s",
                        lwtype_name(in->type));
+               return NULL;
        }
-       return NULL;
+
+       lwgeom_drop_bbox(in);
+       lwgeom_add_bbox(in);
+       return in;
 }
 
 void lwgeom_set_srid(LWGEOM *geom, int32_t srid)