[postgis-tickets] [SCM] PostGIS branch main updated. 3.1.0rc1-374-gf885c33

git at osgeo.org git at osgeo.org
Thu Jul 29 15:00:11 PDT 2021


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, main has been updated
       via  f885c33548a5f58f2e1568765f87a93f6dc36333 (commit)
      from  eb6248024ccbd9aac73e97a52352347f72e6ba64 (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 f885c33548a5f58f2e1568765f87a93f6dc36333
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Jul 29 14:58:55 2021 -0700

    Return NULL for ST_GeometryN(empty) for all empty inputs.
    This harmonizes with the behaviour of ST_GeometryN when N is
    out-of-range for non-empty geometry (returns NULL). It also
    matches up with ST_InteriorRingN(empty), which returns NULL.
    Also updated relevant wiki page with this behaviour.
    https://trac.osgeo.org/postgis/wiki/DevWikiEmptyGeometry

diff --git a/postgis/lwgeom_ogc.c b/postgis/lwgeom_ogc.c
index 9d2f994..e1745e2 100644
--- a/postgis/lwgeom_ogc.c
+++ b/postgis/lwgeom_ogc.c
@@ -241,11 +241,11 @@ Datum LWGEOM_numgeometries_collection(PG_FUNCTION_ARGS)
 	int32 ret = 1;
 
 	lwgeom = lwgeom_from_gserialized(geom);
-	if ( lwgeom_is_empty(lwgeom) )
+	if (lwgeom_is_empty(lwgeom))
 	{
 		ret = 0;
 	}
-	else if ( lwgeom_is_collection(lwgeom) )
+	else if (lwgeom_is_collection(lwgeom))
 	{
 		LWCOLLECTION *col = lwgeom_as_lwcollection(lwgeom);
 		ret = col->ngeoms;
@@ -273,10 +273,15 @@ Datum LWGEOM_geometryn_collection(PG_FUNCTION_ARGS)
 	idx = PG_GETARG_INT32(1);
 	idx -= 1; /* index is 1-based */
 
+	if (gserialized_is_empty(geom))
+	{
+		PG_RETURN_NULL();
+	}
+
 	/* call is valid on multi* geoms only */
-	if (type==POINTTYPE || type==LINETYPE || type==CIRCSTRINGTYPE ||
-	        type==COMPOUNDTYPE || type==POLYGONTYPE ||
-		type==CURVEPOLYTYPE || type==TRIANGLETYPE)
+	if (type==POINTTYPE     || type==LINETYPE    || type==CIRCSTRINGTYPE ||
+	    type==COMPOUNDTYPE  || type==POLYGONTYPE ||
+	    type==CURVEPOLYTYPE || type==TRIANGLETYPE)
 	{
 		if ( idx == 0 ) PG_RETURN_POINTER(geom);
 		PG_RETURN_NULL();
diff --git a/regress/core/empty.sql b/regress/core/empty.sql
index 6dfe078..d07ce25 100644
--- a/regress/core/empty.sql
+++ b/regress/core/empty.sql
@@ -111,6 +111,10 @@ WITH inp AS (SELECT
 WITH inp AS (SELECT
  'POLYGON EMPTY'::geometry as empty
  ) SELECT 'ST_NumGeometries(empty) == 0', ST_NumGeometries(empty) FROM inp;
+-- https://trac.osgeo.org/postgis/ticket/4736
+WITH inp AS (SELECT
+ 'GEOMETRYCOLLECTION(POLYGON EMPTY)'::geometry as empty
+ ) SELECT 'ST_NumGeometries(emptycollection) == 0', ST_NumGeometries(empty) FROM inp;
 WITH inp AS (SELECT
  'POLYGON EMPTY'::geometry as empty
  ) SELECT 'ST_NRings(empty) == 0', ST_NRings(empty) FROM inp;
@@ -123,7 +127,12 @@ WITH inp AS (SELECT
 WITH inp AS (SELECT
  'POLYGON EMPTY'::geometry as empty,
  1 as n
- ) SELECT 'ST_GeometryN(empty, n) == empty', encode(ST_AsEWKB(ST_GeometryN(empty, n),'ndr'),'hex') FROM inp;
+ ) SELECT 'ST_GeometryN(empty, n) == NULL', encode(ST_AsEWKB(ST_GeometryN(empty, n),'ndr'),'hex') FROM inp;
+-- https://trac.osgeo.org/postgis/ticket/4736
+WITH inp AS (SELECT
+ 'GEOMETRYCOLLECTION(POLYGON EMPTY)'::geometry as empty,
+ 1 as n
+ ) SELECT 'ST_GeometryN(emptycollection, n) == NULL', encode(ST_AsEWKB(ST_GeometryN(empty, n),'ndr'),'hex') FROM inp;
 WITH inp AS (SELECT
  'POLYGON EMPTY'::geometry as empty
  ) SELECT 'ST_ExteriorRing(empty) == empty', encode(ST_AsEWKB(ST_ExteriorRing(empty),'ndr'),'hex') FROM inp;
@@ -138,6 +147,8 @@ WITH inp AS (SELECT
  'LINESTRING EMPTY'::geometry as empty
  ) SELECT 'ST_Length(empty) == 0', ST_Length(empty) FROM inp;
 
+
+
 -- Operators
 
 -- same box, see http://trac.osgeo.org/postgis/ticket/1453
diff --git a/regress/core/empty_expected b/regress/core/empty_expected
index 53f4e8b..2eb4511 100644
--- a/regress/core/empty_expected
+++ b/regress/core/empty_expected
@@ -44,10 +44,12 @@ ST_Equals(empty1, empty2) == TRUE|t
 ST_IsSimple(empty) == TRUE|t
 ST_IsValid(empty) == TRUE|t
 ST_NumGeometries(empty) == 0|0
+ST_NumGeometries(emptycollection) == 0|0
 ST_NRings(empty) == 0|0
 ST_NumPoints(empty) == 0|0
 ST_NPoints(empty) == 0|0
-ST_GeometryN(empty, n) == empty|010300000000000000
+ST_GeometryN(empty, n) == NULL|
+ST_GeometryN(emptycollection, n) == NULL|
 ST_ExteriorRing(empty) == empty|010200000000000000
 ST_InteriorRingN(empty, n) == NULL|
 ST_Area(empty) == 0|0

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

Summary of changes:
 postgis/lwgeom_ogc.c        | 15 ++++++++++-----
 regress/core/empty.sql      | 13 ++++++++++++-
 regress/core/empty_expected |  4 +++-
 3 files changed, 25 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list