[postgis-tickets] [SCM] PostGIS branch stable-2.5 updated. 81754c50035bd6efb8751786cfc08bd09b284c6d
git at osgeo.org
git at osgeo.org
Thu Dec 12 08:25:11 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, stable-2.5 has been updated
via 81754c50035bd6efb8751786cfc08bd09b284c6d (commit)
from 9b3cc0df685782004911d5bb45cca97958e23a78 (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 81754c50035bd6efb8751786cfc08bd09b284c6d
Author: Raúl Marín <git at rmr.ninja>
Date: Thu Dec 12 17:19:54 2019 +0100
LWGEOM_addpoint: Accept -1 as a valid position
References #4600
diff --git a/NEWS b/NEWS
index 057a464..1fd587a 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,7 @@ PostGIS 2.5.4
- #4549, Fix schema qualification of internal types (Raúl Marín)
- #4546, Fix PLPGSQL functions missing the schema qualification (Raúl Marín)
- #4588, Fix update when st_union(geometry) doesn't exist (Raúl Marín)
+ - #4599, ST_AddPoint: Accept -1 as a valid position (Raúl Marín)
PostGIS 2.5.3
diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c
index 8d622aa..492c02f 100644
--- a/postgis/lwgeom_functions_basic.c
+++ b/postgis/lwgeom_functions_basic.c
@@ -2166,21 +2166,20 @@ 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__);
pglwg1 = PG_GETARG_GSERIALIZED_P(0);
pglwg2 = PG_GETARG_GSERIALIZED_P(1);
-
- if ( gserialized_get_type(pglwg1) != LINETYPE )
+ if (gserialized_get_type(pglwg1) != LINETYPE)
{
elog(ERROR, "First argument must be a LINESTRING");
PG_RETURN_NULL();
}
- if ( gserialized_get_type(pglwg2) != POINTTYPE )
+ if (gserialized_get_type(pglwg2) != POINTTYPE)
{
elog(ERROR, "Second argument must be a POINT");
PG_RETURN_NULL();
@@ -2188,26 +2187,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();
@@ -2221,7 +2223,6 @@ Datum LWGEOM_addpoint(PG_FUNCTION_ARGS)
lwpoint_free(point);
PG_RETURN_POINTER(result);
-
}
PG_FUNCTION_INFO_V1(LWGEOM_removepoint);
diff --git a/regress/tickets.sql b/regress/tickets.sql
index 08e7c92..419b8fa 100644
--- a/regress/tickets.sql
+++ b/regress/tickets.sql
@@ -1115,3 +1115,7 @@ DROP TABLE IF EXISTS bug_4144_table;
DELETE FROM spatial_ref_sys;
SELECT '#4176', ST_Intersects('POLYGON((0 0, 10 10, 3 5, 0 0))', 'GEOMETRYCOLLECTION(POINT(10 10), LINESTRING(0 0, 3 3))');
+
+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/tickets_expected b/regress/tickets_expected
index b77d84d..317bad8 100644
--- a/regress/tickets_expected
+++ b/regress/tickets_expected
@@ -336,3 +336,6 @@ ERROR: lwgeom_union: GEOS Error: TopologyException: Input geom 0 is invalid: Se
#4081|f|t
NOTICE: table "bug_4144_table" does not exist, skipping
#4176|t
+#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 | 1 +
postgis/lwgeom_functions_basic.c | 31 ++++++++++++++++---------------
regress/tickets.sql | 4 ++++
regress/tickets_expected | 3 +++
4 files changed, 24 insertions(+), 15 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list