From: Raúl Marín Rodríguez Date: Thu, 5 Sep 2019 17:10:57 +0000 (+0000) Subject: Make ST_Simplify(TRIANGLE) collapse if requested X-Git-Tag: 3.0.0beta1~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15520c12606c1adce46f10d7fc5506cb1c497b81;p=postgis Make ST_Simplify(TRIANGLE) collapse if requested 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 --- diff --git a/NEWS b/NEWS index 0cc955b30..6cc4eb740 100644 --- 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 diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 112ada501..2596fb9f2 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -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); diff --git a/regress/core/simplify.sql b/regress/core/simplify.sql index a8a343b36..d5c2b01c2 100644 --- a/regress/core/simplify.sql +++ b/regress/core/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/core/simplify_expected b/regress/core/simplify_expected index c2920ecd0..63bcb8c7e 100644 --- a/regress/core/simplify_expected +++ b/regress/core/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|