[postgis-tickets] r14493 - #3388, ST_RemoveRepeatedPoints can change endpoint
Paul Ramsey
pramsey at cleverelephant.ca
Thu Dec 17 11:14:55 PST 2015
Author: pramsey
Date: 2015-12-17 11:14:55 -0800 (Thu, 17 Dec 2015)
New Revision: 14493
Modified:
trunk/liblwgeom/ptarray.c
trunk/regress/remove_repeated_points.sql
trunk/regress/remove_repeated_points_expected
Log:
#3388, ST_RemoveRepeatedPoints can change endpoint
Modified: trunk/liblwgeom/ptarray.c
===================================================================
--- trunk/liblwgeom/ptarray.c 2015-12-17 18:12:23 UTC (rev 14492)
+++ trunk/liblwgeom/ptarray.c 2015-12-17 19:14:55 UTC (rev 14493)
@@ -1439,18 +1439,22 @@
/* Now fill up the actual points (NOTE: could be optimized) */
opn=1;
+ /* Keep the first point */
memcpy(getPoint_internal(out, 0), getPoint_internal(in, 0), ptsize);
last_point = getPoint2d_cp(in, 0);
LWDEBUGF(3, " first point copied, out points: %d", opn);
for ( ipn = 1; ipn < in->npoints; ++ipn)
{
this_point = getPoint2d_cp(in, ipn);
- if ( (ipn >= in->npoints-minpoints+1 && opn < minpoints) ||
- (tolerance == 0 && memcmp(getPoint_internal(in, ipn-1), getPoint_internal(in, ipn), ptsize) != 0) ||
- (tolerance > 0.0 && distance2d_sqr_pt_pt(last_point, this_point) > tolsq) )
+ if ( (ipn >= in->npoints-minpoints+1 && opn < minpoints) || /* need extra points to hit minponts */
+ (ipn == in->npoints-1 && memcmp(getPoint_internal(in, ipn-1), getPoint_internal(in, ipn), ptsize) != 0) || /* last point (and not exact dupe) */
+ (tolerance == 0 && memcmp(getPoint_internal(in, ipn-1), getPoint_internal(in, ipn), ptsize) != 0) || /* not an exact dupe */
+ (tolerance > 0.0 && distance2d_sqr_pt_pt(last_point, this_point) > tolsq) ) /* not within the removal tolerance */
{
- /* The point is different from the previous,
- * we add it to output */
+ /*
+ * The point is different (see above) from the previous,
+ * so we add it to output
+ */
memcpy(getPoint_internal(out, opn++), getPoint_internal(in, ipn), ptsize);
last_point = this_point;
LWDEBUGF(3, " Point %d differs from point %d. Out points: %d", ipn, ipn-1, opn);
Modified: trunk/regress/remove_repeated_points.sql
===================================================================
--- trunk/regress/remove_repeated_points.sql 2015-12-17 18:12:23 UTC (rev 14492)
+++ trunk/regress/remove_repeated_points.sql 2015-12-17 19:14:55 UTC (rev 14493)
@@ -21,4 +21,5 @@
SELECT 11, ST_AsText(ST_RemoveRepeatedPoints('LINESTRING(0 0, 0 0, 0 0, 0 0, 0 0)'));
SELECT 12, ST_SRID(ST_RemoveRepeatedPoints('SRID=3;LINESTRING(0 0, 0 0, 0 0, 0 0, 0 0)'));
SELECT 13, ST_AsText(ST_RemoveRepeatedPoints('LINESTRING(0 0, 1 0, 2 0, 3 0, 4 0)',1.5));
+SELECT 14, ST_AsText(ST_RemoveRepeatedPoints('LINESTRING(10 0,10 9,10 10)', 2));
Modified: trunk/regress/remove_repeated_points_expected
===================================================================
--- trunk/regress/remove_repeated_points_expected 2015-12-17 18:12:23 UTC (rev 14492)
+++ trunk/regress/remove_repeated_points_expected 2015-12-17 19:14:55 UTC (rev 14493)
@@ -12,3 +12,4 @@
11|LINESTRING(0 0,0 0)
12|3
13|LINESTRING(0 0,2 0,4 0)
+14|LINESTRING(10 0,10 9,10 10)
More information about the postgis-tickets
mailing list