]> granicus.if.org Git - postgis/commitdiff
Don't let ST_RemoveRepeatedPoint collapse LINESTRINGs (not sure why, but someone...
authorSandro Santilli <strk@keybit.net>
Tue, 23 Feb 2010 19:42:15 +0000 (19:42 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 23 Feb 2010 19:42:15 +0000 (19:42 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@5322 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/ptarray.c
regress/remove_repeated_points.sql
regress/remove_repeated_points_expected

index 9265207f968d2415094d2afc6b3bcc9d71c921a9..a25f7641e481e37c1c4ce63b658683dbe8c31ac4 100644 (file)
@@ -952,7 +952,7 @@ ptarray_remove_repeated_points(POINTARRAY *in)
        LWDEBUG(3, "ptarray_remove_repeated_points called.");
 
        /* Single or zero point arrays can't have duplicates */
-       if ( in->npoints < 2 ) return ptarray_clone(in);
+       if ( in->npoints < 3 ) return ptarray_clone(in);
 
        ptsize = pointArray_ptsize(in);
 
@@ -969,7 +969,7 @@ ptarray_remove_repeated_points(POINTARRAY *in)
        LWDEBUGF(3, " first point copied, out points: %d", opn);
        for (ipn=1; ipn<in->npoints; ++ipn)
        {
-               if ( memcmp(getPoint_internal(in, ipn-1),
+               if ( (ipn==in->npoints-1 && opn==1) || memcmp(getPoint_internal(in, ipn-1),
                            getPoint_internal(in, ipn), ptsize) )
                {
                        /* The point is different from the previous,
index 5e2ff1fcf26289d7ce255fc624528319a461dc04..bc89372770ad53a068f44ff8283672ac27d8037d 100644 (file)
@@ -17,22 +17,5 @@ SELECT 9, ST_AsText(ST_RemoveRepeatedPoints('CURVEPOLYGON(CIRCULARSTRING(
                 -2 0 0 0),
                 (-1 0 1 2,                                                                      0 0.5 2 4,
                 1 0 3 6,                                                                        0 1 3 4,                                                                        -1 0 1 2))'));        
-SELECT 0, ST_AsText(ST_RemoveRepeatedPoints('GEOMETRYCOLLECTION EMPTY'));
-SELECT 1, ST_AsText(ST_RemoveRepeatedPoints('LINESTRING(0 0, 1 1, 1 1, 2 2)'));
-SELECT 2, ST_AsText(ST_RemoveRepeatedPoints('LINESTRING(0 0, 1 1, 1 1, 2 2, 2 2, 2 2, 2 2, 3 3, 3 3)'));
-SELECT 3, ST_AsText(ST_RemoveRepeatedPoints('MULTILINESTRING((0 0, 1 1, 1 1, 2 2, 2 2, 2 2, 2 2, 3 3, 3 3),(5 5, 5 5, 5 5, 4 4, 2 2))'));
-SELECT 4, ST_AsText(ST_RemoveRepeatedPoints('POLYGON((0 0, 10 0, 10 10, 10 10, 0 10, 0 10, 0 10, 0 0, 0 0, 0 0),(5 5, 5 5, 5 8, 8 8, 8 8, 8 8, 8 5,8 5, 5 5, 5 5, 5 5, 5 5, 5 5))'));
-SELECT 5, ST_AsText(ST_RemoveRepeatedPoints('MULTIPOLYGON(((0 0, 10 0, 10 10, 10 10, 0 10, 0 10, 0 10, 0 0, 0 0, 0 0),(5 5, 5 5, 5 8, 8 8, 8 8, 8 8, 8 5,8 5, 5 5, 5 5, 5 5, 5 5, 5 5)),((50 50, 50 50, 50 50, 50 60, 50 60, 50 60, 60 60, 60 50, 60 50, 50 50),(55 55, 55 58, 58 58, 58 55, 58 55, 55 55)))'));
-SELECT 6, ST_AsText(ST_RemoveRepeatedPoints('MULTIPOINT(0 0, 10 0, 10 10, 10 10, 0 10, 0 10, 0 10, 0 0, 0 0, 0 0,5 5, 5 5, 5 8, 8 8, 8 8, 8 8, 8 5,8 5, 5 5, 5 5, 5 5, 5 5, 5 5,50 50, 50 50, 50 50, 50 60, 50 60, 50 60, 60 60, 60 50, 60 50, 50 50,55 55, 55 58, 58 58, 58 55, 58 55, 55 55)'));
-SELECT 7, ST_AsText(ST_RemoveRepeatedPoints('GEOMETRYCOLLECTION(MULTIPOINT(0 0, 10 0, 10 10, 10 10, 0 10, 0 10, 0 10, 0 0, 0 0, 0 0,5 5, 5 5, 5 8, 8 8, 8 8, 8 8, 8 5,8 5, 5 5, 5 5, 5 5, 5 5, 5 5,50 50, 50 50, 50 50, 50 60, 50 60, 50 60, 60 60, 60 50, 60 50, 50 50,55 55, 55 58, 58 58, 58 55, 58 55, 55 55),MULTIPOLYGON(((0 0, 10 0, 10 10, 10 10, 0 10, 0 10, 0 10, 0 0, 0 0, 0 0),(5 5, 5 5, 5 8, 8 8, 8 8, 8 8, 8 5,8 5, 5 5, 5 5, 5 5, 5 5, 5 5)),((50 50, 50 50, 50 50, 50 60, 50 60, 50 60, 60 60, 60 50, 60 50, 50 50),(55 55, 55 58, 58 58, 58 55, 58 55, 55 55))))'));
-SELECT 8, ST_AsText(ST_RemoveRepeatedPoints('POINT(0 0)'));
-SELECT 9, ST_AsText(ST_RemoveRepeatedPoints('CURVEPOLYGON(CIRCULARSTRING(
-                -2 0 0 0,
-                -1 -1 1 2,
-                0 0 2 4,
-                1 -1 3 6,
-                2 0 4 8,
-                0 2 2 4,
-                -2 0 0 0),
-                (-1 0 1 2,                                                                      0 0.5 2 4,
-                1 0 3 6,                                                                        0 1 3 4,                                                                        -1 0 1 2))'));        
+SELECT 10, ST_AsText(ST_RemoveRepeatedPoints('LINESTRING(0 0, 0 0)'));
+SELECT 11, ST_AsText(ST_RemoveRepeatedPoints('LINESTRING(0 0, 0 0, 0 0, 0 0, 0 0)'));
index 002b3ec63ce0a5bd26d18bf549f3f4ab46b9c86b..35f7597ea71b68346f41f10d66bc5aef4c83669f 100644 (file)
@@ -8,13 +8,5 @@
 7|GEOMETRYCOLLECTION(MULTIPOINT(0 0,10 0,10 10,0 10,5 5,5 8,8 8,8 5,50 50,50 60,60 60,60 50,55 55,55 58,58 58,58 55),MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(5 5,5 8,8 8,8 5,5 5)),((50 50,50 60,60 60,60 50,50 50),(55 55,55 58,58 58,58 55,55 55))))
 8|POINT(0 0)
 9|CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0))
-0|GEOMETRYCOLLECTION EMPTY
-1|LINESTRING(0 0,1 1,2 2)
-2|LINESTRING(0 0,1 1,2 2,3 3)
-3|MULTILINESTRING((0 0,1 1,2 2,3 3),(5 5,4 4,2 2))
-4|POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,5 8,8 8,8 5,5 5))
-5|MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(5 5,5 8,8 8,8 5,5 5)),((50 50,50 60,60 60,60 50,50 50),(55 55,55 58,58 58,58 55,55 55)))
-6|MULTIPOINT(0 0,10 0,10 10,0 10,5 5,5 8,8 8,8 5,50 50,50 60,60 60,60 50,55 55,55 58,58 58,58 55)
-7|GEOMETRYCOLLECTION(MULTIPOINT(0 0,10 0,10 10,0 10,5 5,5 8,8 8,8 5,50 50,50 60,60 60,60 50,55 55,55 58,58 58,58 55),MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(5 5,5 8,8 8,8 5,5 5)),((50 50,50 60,60 60,60 50,50 50),(55 55,55 58,58 58,58 55,55 55))))
-8|POINT(0 0)
-9|CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0))
+10|LINESTRING(0 0,0 0)
+11|LINESTRING(0 0,0 0)