]> granicus.if.org Git - postgis/commitdiff
Restore 1.5.x behaviour of ST_Simplify (#1987)
authorSandro Santilli <strk@keybit.net>
Mon, 19 Nov 2012 10:20:09 +0000 (10:20 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 19 Nov 2012 10:20:09 +0000 (10:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10702 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwcollection.c
liblwgeom/lwline.c
liblwgeom/lwpoly.c
regress/simplify.sql
regress/simplify_expected

index dedc02962903ff3abf3fd5a0a88f90c376aa13ec..fd95b7dbd7ba788a0ea48cf0725e27fdeba149b6 100644 (file)
@@ -499,12 +499,12 @@ LWCOLLECTION* lwcollection_simplify(const LWCOLLECTION *igeom, double dist)
        LWCOLLECTION *out = lwcollection_construct_empty(igeom->type, igeom->srid, FLAGS_GET_Z(igeom->flags), FLAGS_GET_M(igeom->flags));
 
        if( lwcollection_is_empty(igeom) )
-               return out;
+               return out; /* should we return NULL instead ? */
 
        for( i = 0; i < igeom->ngeoms; i++ )
        {
                LWGEOM *ngeom = lwgeom_simplify(igeom->geoms[i], dist);
-               out = lwcollection_add_lwgeom(out, ngeom);
+               if ( ngeom ) out = lwcollection_add_lwgeom(out, ngeom);
        }
 
        return out;
@@ -553,4 +553,4 @@ lwcollection_startpoint(const LWCOLLECTION* col, POINT4D* pt)
                return LW_FAILURE;
                
        return lwgeom_startpoint(col->geoms[0], pt);
-}
\ No newline at end of file
+}
index 84cff91f1da36bcbd35800af0850edf20e447d3d..30de4ad41759ce98a256782fe6fb515417dc19e1 100644 (file)
@@ -480,7 +480,8 @@ LWLINE* lwline_simplify(const LWLINE *iline, double dist)
        if( lwline_is_empty(iline) )
                return lwline_clone(iline);
                
-       oline = lwline_construct(iline->srid, NULL, ptarray_simplify(iline->points, dist, 2));
+       static const int minvertices = 0; /* TODO: allow setting this */
+       oline = lwline_construct(iline->srid, NULL, ptarray_simplify(iline->points, dist, minvertices));
        oline->type = iline->type;
        return oline;
 }
index c6b6dcbe0e9b3c0f907eeb596615bb0c6e2a788f..52c27fad987e40adfc799efb4f0bd9582cf611c0 100644 (file)
@@ -350,36 +350,35 @@ LWPOLY* lwpoly_simplify(const LWPOLY *ipoly, double dist)
        LWDEBUGF(2, "simplify_polygon3d: simplifying polygon with %d rings", ipoly->nrings);
 
        if( lwpoly_is_empty(ipoly) )
-               return opoly;
+               return opoly; /* should we return NULL instead ? */
 
        for (i = 0; i < ipoly->nrings; i++)
        {
-               POINTARRAY *opts = ptarray_simplify(ipoly->rings[i], dist, 3);
+               static const int minvertices = 0; /* TODO: allow setting this */
+               POINTARRAY *opts = ptarray_simplify(ipoly->rings[i], dist, minvertices);
+
+               LWDEBUGF(3, "ring%d simplified from %d to %d points", i, ipoly->rings[i]->npoints, opts->npoints);
 
                /* Less points than are needed to form a closed ring, we can't use this */
-               if ( i && opts->npoints < 4 )
+               if ( opts->npoints < 4 )
                {
                        LWDEBUGF(3, "ring%d skipped (% pts)", i, opts->npoints);
                        ptarray_free(opts);
-                       continue;
+                       if ( i ) continue;
+                       else break; /* Don't scan holes if shell is collapsed */
                }
 
-               LWDEBUGF(3, "ring%d simplified from %d to %d points", i, ipoly->rings[i]->npoints, opts->npoints);
-
                /* Add ring to simplified polygon */
                if( lwpoly_add_ring(opoly, opts) == LW_FAILURE )
                        return NULL;
-
-    /* Don't scan holes if shell is collapsed */
-               if (  !i && opts->npoints < 4 )
-               {
-                 LWDEBUG(3, "nothing more to do for collapsed shell");
-                       break;
-               }
        }
 
        LWDEBUGF(3, "simplified polygon with %d rings", ipoly->nrings);
        opoly->type = ipoly->type;
+
+       if( lwpoly_is_empty(opoly) )
+               return NULL;
+
        return opoly;
 }
 
index 76524587d8774020c8aaac48a6f305837017570b..c8ba2137c5fd72434c1ce4dcb5cf23e81777c5bd 100644 (file)
@@ -9,3 +9,6 @@ SELECT '7', ST_astext(ST_Simplify('POLYGON((0 0 3 2, 0 10 6 1, 0 51 1 6, 50 20 6
 SELECT '8', ST_astext(ST_Simplify('POLYGON((0 0 3 2, 0 10 6 1, 0 51 1 6, 50 20 6 7, 30 20 9 9, 7 32 10 5, 0 0 3 2), (1 1 4 3, 1 3 2 3, 18 18 5 30, 1 1 4 3))', 1));
 
 SELECT '9', ST_astext(ST_Simplify('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5))', 20));
+SELECT '10', ST_astext(ST_Simplify('LINESTRING(0 0, 0 10)', 20));
+SELECT '11', ST_astext(ST_Simplify('MULTIPOLYGON(((100 100, 100 130, 130 130, 130 100, 100 100)), ((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5)) )', 20));
+SELECT '12', ST_astext(ST_Simplify('MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0),(5 5, 5 6, 6 6, 8 5, 5 5)),((100 100, 100 130, 130 130, 130 100, 100 100)))', 20));
index 52c8de49a0d5cafb69bc480582c261d4dc52cc7a..93a5c462219edcfed27e17fd8ac8eb8735ccdddf 100644 (file)
@@ -6,4 +6,7 @@
 6|MULTILINESTRING ZM ((0 0 3 2,0 51 1 6,50 20 6 7,7 32 10 5),(0 0 4 3,20 20 5 30))
 7|POLYGON ZM ((0 0 3 2,0 51 1 6,50 20 6 7,7 32 10 5,0 0 3 2))
 8|POLYGON ZM ((0 0 3 2,0 51 1 6,50 20 6 7,30 20 9 9,7 32 10 5,0 0 3 2),(1 1 4 3,1 3 2 3,18 18 5 30,1 1 4 3))
-9|POLYGON((0 0,10 10,0 0))
+9|
+10|LINESTRING(0 0,0 10)
+11|MULTIPOLYGON(((100 100,100 130,130 130,130 100,100 100)))
+12|MULTIPOLYGON(((100 100,100 130,130 130,130 100,100 100)))