[postgis-tickets] r17396 - Allow passing TINs to GEOS functions.

Darafei komzpa at gmail.com
Tue Apr 16 11:31:05 PDT 2019


Author: komzpa
Date: 2019-04-16 23:31:04 -0700 (Tue, 16 Apr 2019)
New Revision: 17396

Modified:
   trunk/NEWS
   trunk/liblwgeom/cunit/cu_geos.c
   trunk/liblwgeom/lwgeom_geos.c
Log:
Allow passing TINs to GEOS functions.

Closes #4378
Closes https://github.com/postgis/postgis/pull/392



Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2019-04-15 06:37:00 UTC (rev 17395)
+++ trunk/NEWS	2019-04-17 06:31:04 UTC (rev 17396)
@@ -88,6 +88,8 @@
   - #4295, Allow GEOMETRYCOLLECTION in ST_Overlaps, ST_Contains, ST_ContainsProperly,
            ST_Covers, ST_CoveredBy, ST_Crosses, ST_Touches, ST_Disjoint, ST_Relate,
            ST_Equals (Esteban Zimányi)
+  - #4378, Allow passing TINs as input to GEOS-backed functions (Darafei
+           Praliaskouski)
 
 PostGIS 2.5.0
 2018/09/23

Modified: trunk/liblwgeom/cunit/cu_geos.c
===================================================================
--- trunk/liblwgeom/cunit/cu_geos.c	2019-04-15 06:37:00 UTC (rev 17395)
+++ trunk/liblwgeom/cunit/cu_geos.c	2019-04-17 06:31:04 UTC (rev 17396)
@@ -20,49 +20,61 @@
 
 #include "liblwgeom_internal.h"
 
-static void test_geos_noop(void)
+static void
+test_geos_noop(void)
 {
 	size_t i;
+	char *in_ewkt;
+	char *out_ewkt;
+	LWGEOM *geom_in;
+	LWGEOM *geom_out;
 
-	char *ewkt[] =
-	{
-		"POINT(0 0.2)",
-		"LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
-		"MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
-		"SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
-		"SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
-		"POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
-		"SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
-		"SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
-		"SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
-		"SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
-		"SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
-		"GEOMETRYCOLLECTION( LINESTRING (1 1, 2 2), POINT EMPTY, TRIANGLE ((0 0, 1 0, 1 1, 0 0)) )",
+	char *ewkt[] = {
+	    "POINT(0 0.2)",
+	    "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
+	    "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
+	    "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
+	    "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
+	    "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
+	    "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
+	    "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
+	    "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
+	    "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
+	    "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
 	};
 
-
-	for ( i = 0; i < (sizeof ewkt/sizeof(char *)); i++ )
+	for (i = 0; i < (sizeof ewkt / sizeof(char *)); i++)
 	{
-		LWGEOM *geom_in, *geom_out;
-		char *in_ewkt;
-		char *out_ewkt;
-
 		in_ewkt = ewkt[i];
 		geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
 		geom_out = lwgeom_geos_noop(geom_in);
-		if ( ! geom_out ) {
-			// fprintf(stderr, "\nNull return from lwgeom_geos_noop with wkt:   %s\n", in_ewkt);
-			lwgeom_free(geom_in);
-			continue;
-		}
+		CU_ASSERT_PTR_NOT_NULL_FATAL(geom_out);
 		out_ewkt = lwgeom_to_ewkt(geom_out);
-		if (strcmp(in_ewkt, out_ewkt))
-			fprintf(stderr, "\nExp:   %s\nObt:  %s\n", in_ewkt, out_ewkt);
-		CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
+		ASSERT_STRING_EQUAL(out_ewkt, in_ewkt);
 		lwfree(out_ewkt);
 		lwgeom_free(geom_out);
 		lwgeom_free(geom_in);
 	}
+
+	/* TINs become collections of Polygons */
+	in_ewkt = "TIN(((0 0, 1 1, 2 2, 0 0)), ((0 0, 1 1, 2 2, 0 0)))";
+	geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
+	geom_out = lwgeom_geos_noop(geom_in);
+	out_ewkt = lwgeom_to_ewkt(geom_out);
+	ASSERT_STRING_EQUAL(out_ewkt, "GEOMETRYCOLLECTION(POLYGON((0 0,1 1,2 2,0 0)),POLYGON((0 0,1 1,2 2,0 0)))");
+	lwfree(out_ewkt);
+	lwgeom_free(geom_in);
+	lwgeom_free(geom_out);
+
+	/* Empties disappear */
+	in_ewkt = "GEOMETRYCOLLECTION( LINESTRING (1 1, 2 2), POINT EMPTY, TRIANGLE ((0 0, 1 0, 1 1, 0 0)) )";
+	geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
+	geom_out = lwgeom_geos_noop(geom_in);
+	out_ewkt = lwgeom_to_ewkt(geom_out);
+	ASSERT_STRING_EQUAL(out_ewkt, "GEOMETRYCOLLECTION(LINESTRING(1 1,2 2),POLYGON((0 0,1 0,1 1,0 0)))");
+	lwfree(out_ewkt);
+	lwgeom_free(geom_in);
+	lwgeom_free(geom_out);
 }
 
 static void test_geos_linemerge(void)

Modified: trunk/liblwgeom/lwgeom_geos.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos.c	2019-04-15 06:37:00 UTC (rev 17395)
+++ trunk/liblwgeom/lwgeom_geos.c	2019-04-17 06:31:04 UTC (rev 17396)
@@ -454,9 +454,25 @@
 		}
 		if (!g) return NULL;
 		break;
+
+	case TRIANGLETYPE:
+		if (lwgeom_is_empty(lwgeom))
+			g = GEOSGeom_createEmptyPolygon();
+		else
+		{
+			LWTRIANGLE *lwt = (LWTRIANGLE *)lwgeom;
+			shell = ptarray_to_GEOSLinearRing(lwt->points, autofix);
+			if (!shell)
+				return NULL;
+			g = GEOSGeom_createPolygon(shell, NULL, 0);
+		}
+		if (!g)
+			return NULL;
+		break;
 	case MULTIPOINTTYPE:
 	case MULTILINETYPE:
 	case MULTIPOLYGONTYPE:
+	case TINTYPE:
 	case COLLECTIONTYPE:
 		if (lwgeom->type == MULTIPOINTTYPE)
 			geostype = GEOS_MULTIPOINT;



More information about the postgis-tickets mailing list