From: Raúl Marín Rodríguez Date: Thu, 5 Sep 2019 17:11:29 +0000 (+0000) Subject: Make ST_Simplify(TRIANGLE) collapse if requested X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ce423115b8de876edb2cd2add914937a01f91a88;p=postgis Make ST_Simplify(TRIANGLE) collapse if requested Closes #4496 git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@17805 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 8e363dbea..3966cc1d5 100644 --- 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 diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index e152ff540..12873ed3e 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -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); diff --git a/regress/simplify.sql b/regress/simplify.sql index a8a343b36..d5c2b01c2 100644 --- a/regress/simplify.sql +++ b/regress/simplify.sql @@ -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 diff --git a/regress/simplify_expected b/regress/simplify_expected index c2920ecd0..63bcb8c7e 100644 --- a/regress/simplify_expected +++ b/regress/simplify_expected @@ -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|