[SCM] PostGIS branch master updated. 3.4.0rc1-977-g8bfdce1c8

git at osgeo.org git at osgeo.org
Wed Mar 6 00:00:53 PST 2024


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  8bfdce1c8577ccec4fe870c9a35c196b7dffe24c (commit)
       via  444fe40b54acd43b45a59c4db9a85c0e673498a5 (commit)
       via  a527255c91830c0ed1080d999c2a3d1728007e2c (commit)
      from  376d4ec7caf5b3772a8615f7b44b880bf4942ef8 (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 8bfdce1c8577ccec4fe870c9a35c196b7dffe24c
Author: Sandro Santilli <strk at kbt.io>
Date:   Tue Mar 5 17:01:28 2024 +0100

    Fix ST_Node with 1-vertex linestring
    
    References #5685 in master branch
    
    Includes unit test

diff --git a/liblwgeom/cunit/cu_node.c b/liblwgeom/cunit/cu_node.c
index 3497476c2..9308341ba 100644
--- a/liblwgeom/cunit/cu_node.c
+++ b/liblwgeom/cunit/cu_node.c
@@ -61,6 +61,15 @@ static void test_lwgeom_node(void)
 "MULTILINESTRING((0 0,2.5 2.5),(0 5,2.5 2.5),(2.5 2.5,5 5,10 0),(10 0,11 0,12 0,20 0),(20 0,22 0),(2.5 2.5,5 0))",
 		tmp);
 	lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
+
+	/* See https://trac.osgeo.org/postgis/ticket/5685 */
+	wkt = "LINESTRING(0 0,0 0)";
+	in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE);
+	out = lwgeom_node(in);
+	/* printf("%s\n", lwgeom_to_ewkt(out)); */
+	CU_ASSERT_FATAL(out != NULL);
+	ASSERT_LWGEOM_EQUAL(in, out);
+	lwgeom_free(out); lwgeom_free(in);
 }
 
 static int
diff --git a/liblwgeom/lwgeom_geos_node.c b/liblwgeom/lwgeom_geos_node.c
index 5c8fd7abb..5c67b7d09 100644
--- a/liblwgeom/lwgeom_geos_node.c
+++ b/liblwgeom/lwgeom_geos_node.c
@@ -166,22 +166,52 @@ lwgeom_node(const LWGEOM* lwgeom_in)
 	}
 	LWDEBUGGEOS(1, gn, "Noded");
 
-	gm = GEOSLineMerge(gn);
-	GEOSGeom_destroy(gn);
-	if ( ! gm ) {
-		lwgeom_free(ep);
-		lwerror("GEOSLineMerge: %s", lwgeom_geos_errmsg);
-		return NULL;
-	}
-	LWDEBUGGEOS(1, gm, "LineMerged");
+	nl = GEOSGetNumGeometries(gn);
+	if ( nl > 1 )
+	{
+		gm = GEOSLineMerge(gn);
+		GEOSGeom_destroy(gn);
+		if ( ! gm ) {
+			lwgeom_free(ep);
+			lwerror("GEOSLineMerge: %s", lwgeom_geos_errmsg);
+			return NULL;
+		}
+		LWDEBUGGEOS(1, gm, "LineMerged");
+		gn = gm;
 
-	lines = GEOS2LWGEOM(gm, FLAGS_GET_Z(lwgeom_in->flags));
-	GEOSGeom_destroy(gm);
-	if ( ! lines ) {
-		lwgeom_free(ep);
-		lwerror("Error during GEOS2LWGEOM");
-		return NULL;
+		lines = GEOS2LWGEOM(gn, FLAGS_GET_Z(lwgeom_in->flags));
+		GEOSGeom_destroy(gn);
+		if ( ! lines ) {
+			lwgeom_free(ep);
+			lwerror("Error during GEOS2LWGEOM");
+			return NULL;
+		}
 	}
+	else if ( nl == 1 )
+	{
+		const GEOSGeometry *gc = GEOSGetGeometryN(gn, 0);
+		lines = GEOS2LWGEOM(gc, FLAGS_GET_Z(lwgeom_in->flags));
+		GEOSGeom_destroy(gn);
+		if ( ! lines ) {
+			lwgeom_free(ep);
+			lwerror("Error during GEOS2LWGEOM");
+			return NULL;
+		}
+	}
+	else
+	{
+		/* No geometries, don't bother with re-adding endpoints */
+		lines = GEOS2LWGEOM(gn, FLAGS_GET_Z(lwgeom_in->flags));
+		GEOSGeom_destroy(gn);
+		if ( ! lines ) {
+			lwgeom_free(ep);
+			lwerror("Error during GEOS2LWGEOM");
+			return NULL;
+		}
+		lwgeom_set_srid(lines, lwgeom_in->srid);
+		return (LWGEOM*)lines;
+	}
+
 
 	/*
 	 * Reintroduce endpoints from input, using split-line-by-point.

commit 444fe40b54acd43b45a59c4db9a85c0e673498a5
Author: Sandro Santilli <strk at kbt.io>
Date:   Tue Mar 5 16:46:34 2024 +0100

    Debug GEOS geometries in lwgeom_noded
    
    References #5685

diff --git a/liblwgeom/lwgeom_geos_node.c b/liblwgeom/lwgeom_geos_node.c
index 8e5e8c3bc..5c8fd7abb 100644
--- a/liblwgeom/lwgeom_geos_node.c
+++ b/liblwgeom/lwgeom_geos_node.c
@@ -18,10 +18,14 @@
  *
  **********************************************************************
  *
- * Copyright (C) 2011 Sandro Santilli <strk at kbt.io>
+ * Copyright (C) 2011-2024 Sandro Santilli <strk at kbt.io>
  *
  **********************************************************************/
 
+#include "../postgis_config.h"
+
+/*#define POSTGIS_DEBUG_LEVEL 1*/
+#include "lwgeom_log.h"
 
 #include "lwgeom_geos.h"
 #include "liblwgeom_internal.h"
@@ -160,6 +164,7 @@ lwgeom_node(const LWGEOM* lwgeom_in)
 		lwerror("GEOSNode: %s", lwgeom_geos_errmsg);
 		return NULL;
 	}
+	LWDEBUGGEOS(1, gn, "Noded");
 
 	gm = GEOSLineMerge(gn);
 	GEOSGeom_destroy(gn);
@@ -168,6 +173,7 @@ lwgeom_node(const LWGEOM* lwgeom_in)
 		lwerror("GEOSLineMerge: %s", lwgeom_geos_errmsg);
 		return NULL;
 	}
+	LWDEBUGGEOS(1, gm, "LineMerged");
 
 	lines = GEOS2LWGEOM(gm, FLAGS_GET_Z(lwgeom_in->flags));
 	GEOSGeom_destroy(gm);

commit a527255c91830c0ed1080d999c2a3d1728007e2c
Author: Sandro Santilli <strk at kbt.io>
Date:   Tue Mar 5 16:46:13 2024 +0100

    Add LWDEBUGGEOS macro for debugging geos geometries

diff --git a/liblwgeom/lwgeom_geos.h b/liblwgeom/lwgeom_geos.h
index e1b278e0c..90a1562fb 100644
--- a/liblwgeom/lwgeom_geos.h
+++ b/liblwgeom/lwgeom_geos.h
@@ -46,3 +46,30 @@ POINTARRAY* ptarray_from_GEOSCoordSeq(const GEOSCoordSequence* cs, uint8_t want3
 
 extern char lwgeom_geos_errmsg[];
 extern void lwgeom_geos_error(const char* fmt, ...);
+
+
+/*
+ * Debug macros
+ */
+#if POSTGIS_DEBUG_LEVEL > 0
+
+/* Display a notice and a WKT representation of a geometry
+ * at the given debug level */
+#define LWDEBUGGEOS(level, geom, msg) \
+  if (POSTGIS_DEBUG_LEVEL >= level) \
+  do { \
+		GEOSWKTWriter *wktwriter = GEOSWKTWriter_create(); \
+		char *wkt = GEOSWKTWriter_write(wktwriter, (geom)); \
+		LWDEBUGF(1, msg " (GEOS): %s", wkt); \
+		GEOSFree(wkt); \
+		GEOSWKTWriter_destroy(wktwriter); \
+  } while (0);
+
+#else /* POSTGIS_DEBUG_LEVEL <= 0 */
+
+/* Empty prototype that can be optimised away by the compiler
+ * for non-debug builds */
+#define LWDEBUGGEOS(level, geom, msg) \
+        ((void) 0)
+
+#endif /*POSTGIS_DEBUG_LEVEL <= 0 */

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

Summary of changes:
 liblwgeom/cunit/cu_node.c    |  9 +++++++
 liblwgeom/lwgeom_geos.h      | 27 +++++++++++++++++++
 liblwgeom/lwgeom_geos_node.c | 64 ++++++++++++++++++++++++++++++++++----------
 3 files changed, 86 insertions(+), 14 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list