]> 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:10:57 +0000 (17:10 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Thu, 5 Sep 2019 17:10:57 +0000 (17:10 +0000)
References #4496
Closes https://github.com/postgis/postgis/pull/474

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

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

diff --git a/NEWS b/NEWS
index 0cc955b3089bc0411bb02580dcc3d48e199921c6..6cc4eb740082d9a8edf97e3b689a4723e1b661e2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Additional features enabled if you are running Proj6+ and PostgreSQL 12
   - #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 3.0.0alpha4
 2019/08/10
index 112ada501d1ec17d52ac7115e5411c1a8e1a0e7f..2596fb9f2782b749a75ac54d028e9a18ad6e8b28 100644 (file)
@@ -1704,8 +1704,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|