[postgis-tickets] [SCM] PostGIS branch master updated. bbbd77d0b9504281ad19731316ae7dd0ad7d9f6f

git at osgeo.org git at osgeo.org
Thu Dec 12 06:57:53 PST 2019


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  bbbd77d0b9504281ad19731316ae7dd0ad7d9f6f (commit)
      from  21451108484d163e0b535bdfc5dcc7c07a0c853e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit bbbd77d0b9504281ad19731316ae7dd0ad7d9f6f
Author: Raúl Marín <git at rmr.ninja>
Date:   Wed Dec 11 19:47:48 2019 +0100

    LWGEOM_addpoint: Accept -1 as a valid position
    
    Closes #4599
    Closes https://github.com/postgis/postgis/pull/521

diff --git a/NEWS b/NEWS
index dea80ab..10130b7 100644
--- a/NEWS
+++ b/NEWS
@@ -33,7 +33,7 @@ PostGIS 3.1.0
   - #4588, Fix update when st_union(geometry) doesn't exist (Raúl Marín)
   - #4590, Fix pg_upgrade issue with st_linecrossingdirection (Raúl Marín)
   - #4592, Add missing CPPFLAGS in multiple Makefiles (Raúl Marín)
-
+  - #4599, ST_AddPoint: Accept -1 as a valid position (Raúl Marín)
 
 PostGIS 3.0.0
 2019/10/xx
diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c
index 89a395b..1a02b0a 100644
--- a/postgis/lwgeom_functions_basic.c
+++ b/postgis/lwgeom_functions_basic.c
@@ -2204,7 +2204,7 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
 	GSERIALIZED *pglwg1, *pglwg2, *result;
 	LWPOINT *point;
 	LWLINE *line, *linecopy;
-	int32 where = -1;
+	uint32_t uwhere = 0;
 
 	POSTGIS_DEBUGF(2, "%s called.", __func__);
 
@@ -2225,26 +2225,29 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
 
 	line = lwgeom_as_lwline(lwgeom_from_gserialized(pglwg1));
 
-	if (PG_NARGS() > 2)
+	if (PG_NARGS() <= 2)
 	{
-		where = PG_GETARG_INT32(2);
+		uwhere = line->points->npoints;
 	}
 	else
 	{
-		where = line->points->npoints;
-	}
-
-	if (where < 0 || where > (int32)line->points->npoints)
-	{
-		elog(ERROR, "Invalid offset");
-		PG_RETURN_NULL();
+		int32 where = PG_GETARG_INT32(2);
+		if (where == -1)
+		{
+			uwhere = line->points->npoints;
+		}
+		else if (where < 0 || where > (int32)line->points->npoints)
+		{
+			elog(ERROR, "Invalid offset");
+			PG_RETURN_NULL();
+		}
 	}
 
 	point = lwgeom_as_lwpoint(lwgeom_from_gserialized(pglwg2));
 	linecopy = lwgeom_as_lwline(lwgeom_clone_deep(lwline_as_lwgeom(line)));
 	lwline_free(line);
 
-	if (lwline_add_lwpoint(linecopy, point, (uint32_t)where) == LW_FAILURE)
+	if (lwline_add_lwpoint(linecopy, point, uwhere) == LW_FAILURE)
 	{
 		elog(ERROR, "Point insert failed");
 		PG_RETURN_NULL();
diff --git a/regress/core/tickets.sql b/regress/core/tickets.sql
index adb64fb..4e1b3e0 100644
--- a/regress/core/tickets.sql
+++ b/regress/core/tickets.sql
@@ -1284,3 +1284,7 @@ union all
 select '#4399', 'ST_GeoHash', ST_GeoHash(geom)::text from geom
 union all
 select '#4399', 'ST_AsGeoJSON', ST_AsGeoJSON(geom)::text from geom;
+
+SELECT '#4599-1', ST_AsEWKT(ST_AddPoint(ST_GeomFromEWKT('LINESTRING(0 0 1, 1 1 1)'), ST_MakePoint(1, 2, 3)));
+SELECT '#4599-2', ST_AsEWKT(ST_AddPoint(ST_GeomFromEWKT('LINESTRING(0 0 1, 1 1 1)'), ST_MakePoint(1, 2, 3), 0));
+SELECT '#4599-3', ST_AsEWKT(ST_AddPoint(ST_GeomFromEWKT('LINESTRING(0 0 1, 1 1 1)'), ST_MakePoint(1, 2, 3), -1));
diff --git a/regress/core/tickets_expected b/regress/core/tickets_expected
index e821f1c..4b34ba7 100644
--- a/regress/core/tickets_expected
+++ b/regress/core/tickets_expected
@@ -424,3 +424,6 @@ ERROR:  BOX2D_construct: args can not be empty points
 #4399|ST_AsGeoJSON|{"type":"Polygon","coordinates":[[[0,0],[1,1],[0,1],[0,0]]]}
 #4399|ST_AsGeoJSON|{"type":"GeometryCollection","geometries":[{"type":"Polygon","coordinates":[[[0,0],[1,1],[0,1],[0,0]]]}]}
 #4399|ST_AsGeoJSON|{"type":"Polygon","coordinates":[[]]}
+#4599-1|LINESTRING(0 0 1,1 1 1,1 2 3)
+#4599-2|LINESTRING(1 2 3,0 0 1,1 1 1)
+#4599-3|LINESTRING(0 0 1,1 1 1,1 2 3)

-----------------------------------------------------------------------

Summary of changes:
 NEWS                             |  2 +-
 postgis/lwgeom_functions_basic.c | 25 ++++++++++++++-----------
 regress/core/tickets.sql         |  4 ++++
 regress/core/tickets_expected    |  3 +++
 4 files changed, 22 insertions(+), 12 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list