]> granicus.if.org Git - postgis/commitdiff
Make ST_Simplify(TRIANGLE) collapse if requested
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Thu, 5 Sep 2019 17:11:29 +0000 (17:11 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Thu, 5 Sep 2019 17:11:29 +0000 (17:11 +0000)
Closes #4496

git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@17805 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/lwgeom.c
regress/simplify.sql
regress/simplify_expected

diff --git a/NEWS b/NEWS
index 8e363dbea9cd7b3a4bb144cfb8f4bf7b47a4897d..3966cc1d590f4df2b4a4be9e644b6cba009de133 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ XXXX/XX/XX
   - #4494, Fix ST_Simplify output having an outdated bbox (Raúl Marín)
   - #4493, Fix ST_RemoveRepeatedPoints output having an outdated bbox (Raúl Marín)
   - #4495, Fix ST_SnapToGrid output having an outdated bbox (Raúl Marín)
+  - #4496, Make ST_Simplify(TRIANGLE) collapse if requested (Raúl Marín)
 
 PostGIS 2.5.3
 2019/08/11
index e152ff54067170bb1a96eacb2ef8ad67cfbbd774..12873ed3ecf66365a6376506c034981f7dade43e 100644 (file)
@@ -1753,8 +1753,19 @@ lwgeom_simplify_in_place(LWGEOM *geom, double epsilon, int preserve_collapsed)
        {
                /* No-op! Cannot simplify points or triangles */
                case POINTTYPE:
-               case TRIANGLETYPE:
                        return;
+               case TRIANGLETYPE:
+               {
+                       if (preserve_collapsed)
+                               return;
+                       LWTRIANGLE *t = lwgeom_as_lwtriangle(geom);
+                       POINTARRAY *pa = t->points;
+                       ptarray_simplify_in_place(pa, epsilon, 0);
+                       if (pa->npoints < 3)
+                       {
+                               pa->npoints = 0;
+                       }
+               }
                case LINETYPE:
                {
                        LWLINE *g = (LWLINE*)(geom);
index a8a343b363e6c5219804368f2ee9ae47d97c7a55..d5c2b01c204c0f8c313a573ceaa57da87d6f9173 100644 (file)
@@ -21,4 +21,8 @@ WITH geom AS
 (
     SELECT ST_Simplify('POLYGON((0 0, 10 0, 10 10, 10.6 10, 10.5 10.5, 10 10, 0 10, 0 0))', 1) as g
 )
-Select '15', ST_AsText(g) as geometry, postgis_getbbox(g) AS box from geom;
\ No newline at end of file
+Select '15', ST_AsText(g) as geometry, postgis_getbbox(g) AS box from geom;
+
+-- Triangle should collapse if requested
+SELECT '16', ST_AsText(ST_Simplify('TRIANGLE ((0 0, 0 9, 9 0, 0 0))', 10, true));
+SELECT '17', ST_AsText(ST_Simplify('TRIANGLE ((0 0, 0 9, 9 0, 0 0))', 10, false));
\ No newline at end of file
index c2920ecd0456413cc7beb7fe067d4d1af81b8637..63bcb8c7e816cf69f441fad6a55ce9d1fda36811 100644 (file)
@@ -13,3 +13,5 @@
 13|
 14|POLYGON((0 0,10 0,10 10,0 0))
 15|POLYGON((0 0,10 0,10.5 10.5,0 10,0 0))|BOX(0 0,10.5 10.5)
+16|TRIANGLE((0 0,0 9,9 0,0 0))
+17|