[postgis-tickets] r17221 - ST_ClipByBox2D: Do not throw when the geometry is invalid

Raul raul at rmr.ninja
Wed Jan 30 11:17:05 PST 2019


Author: algunenano
Date: 2019-01-30 11:17:05 -0800 (Wed, 30 Jan 2019)
New Revision: 17221

Modified:
   branches/2.5/NEWS
   branches/2.5/liblwgeom/cunit/cu_clip_by_rect.c
   branches/2.5/liblwgeom/lwgeom_geos.c
   branches/2.5/regress/clipbybox2d.sql
   branches/2.5/regress/clipbybox2d_expected
   branches/2.5/regress/mvt.sql
   branches/2.5/regress/mvt_expected
Log:
ST_ClipByBox2D: Do not throw when the geometry is invalid

Closes #4314


Modified: branches/2.5/NEWS
===================================================================
--- branches/2.5/NEWS	2019-01-30 19:13:47 UTC (rev 17220)
+++ branches/2.5/NEWS	2019-01-30 19:17:05 UTC (rev 17221)
@@ -27,6 +27,7 @@
   - #4296, Use `server_version_num` instead of parsing `version()` (Raúl Marín)
   - #4290, More robust geography distance (Paul Ramsey)
   - #4283, Avoid final point duplicates for circle stroking (Paul Ramsey)
+  - #4314, ST_ClipByBox2D: Do not throw when the geometry is invalid (Raúl Marín)
 
 
 

Modified: branches/2.5/liblwgeom/cunit/cu_clip_by_rect.c
===================================================================
--- branches/2.5/liblwgeom/cunit/cu_clip_by_rect.c	2019-01-30 19:13:47 UTC (rev 17220)
+++ branches/2.5/liblwgeom/cunit/cu_clip_by_rect.c	2019-01-30 19:17:05 UTC (rev 17221)
@@ -64,6 +64,13 @@
 	//tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); lwfree(tmp);
 	CU_ASSERT(lwgeom_is_empty(out));
 	lwgeom_free(out); lwgeom_free(in);
+
+	/* Returns NULL with an invalid polygon (line) */
+	wkt = "POLYGON((1410 2055, 1410 2056, 1410 2057, 1410 2055))";
+	in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE);
+	out = lwgeom_clip_by_rect(in, -8.000000, -8.000000, 2056.000000, 2056.000000);
+	CU_ASSERT_PTR_NULL(out);
+	lwgeom_free(in);
 }
 
 /*

Modified: branches/2.5/liblwgeom/lwgeom_geos.c
===================================================================
--- branches/2.5/liblwgeom/lwgeom_geos.c	2019-01-30 19:13:47 UTC (rev 17220)
+++ branches/2.5/liblwgeom/lwgeom_geos.c	2019-01-30 19:17:05 UTC (rev 17221)
@@ -65,6 +65,14 @@
 	return NULL; \
 } while (0)
 
+/* Pass the latest GEOS error to lwdebug, then return NULL */
+#define GEOS_FAIL_DEBUG() \
+	do \
+	{ \
+		lwdebug(1, "%s: GEOS Error: %s", __func__, lwgeom_geos_errmsg); \
+		return NULL; \
+	} while (0)
+
 #define GEOS_FREE_AND_FAIL(...) \
 do { \
 	GEOS_FREE(__VA_ARGS__); \
@@ -71,6 +79,13 @@
 	GEOS_FAIL(); \
 } while (0)
 
+#define GEOS_FREE_AND_FAIL_DEBUG(...) \
+	do \
+	{ \
+		GEOS_FREE(__VA_ARGS__); \
+		GEOS_FAIL_DEBUG(); \
+	} while (0)
+
 /* Return the consistent SRID of all inputs, or call lwerror
  * in case of SRID mismatch. */
 #define RESULT_SRID(...) \
@@ -870,10 +885,10 @@
 	initGEOS(lwnotice, lwgeom_geos_error);
 
 	if (!(g1 = LWGEOM2GEOS(geom1, AUTOFIX)))
-		GEOS_FAIL();
+		GEOS_FAIL_DEBUG();
 
 	if (!(g3 = GEOSClipByRect(g1, x1, y1, x2, y2)))
-		GEOS_FREE_AND_FAIL(g1);
+		GEOS_FREE_AND_FAIL_DEBUG(g1);
 
 	GEOS_FREE(g1);
 	result = GEOS2LWGEOM(g3, is3d);
@@ -880,7 +895,7 @@
 	GEOS_FREE(g3);
 
 	if (!result)
-		GEOS_FAIL();
+		GEOS_FAIL_DEBUG();
 
 	result->srid = geom1->srid;
 

Modified: branches/2.5/regress/clipbybox2d.sql
===================================================================
--- branches/2.5/regress/clipbybox2d.sql	2019-01-30 19:13:47 UTC (rev 17220)
+++ branches/2.5/regress/clipbybox2d.sql	2019-01-30 19:17:05 UTC (rev 17221)
@@ -22,3 +22,5 @@
 SELECT '8', ST_AsEWKT(ST_ClipByBox2d(g, ST_MakeEnvelope(-20,-20,-10,-10))) FROM t;
 -- See http://trac.osgeo.org/postgis/ticket/2954
 SELECT '9', ST_AsEWKT(ST_ClipByBox2D('SRID=4326;POINT(0 0)','BOX3D(-1 -1,1 1)'::box3d::box2d));
+-- See https://trac.osgeo.org/postgis/ticket/4314
+SELECT '10', ST_ClipByBox2D('POLYGON((1410 2055, 1410 2056, 1410 2057, 1410 2055))'::geometry, ST_MakeEnvelope(-8.000000, -8.000000, 2056.000000, 2056.000000));
\ No newline at end of file

Modified: branches/2.5/regress/clipbybox2d_expected
===================================================================
--- branches/2.5/regress/clipbybox2d_expected	2019-01-30 19:13:47 UTC (rev 17220)
+++ branches/2.5/regress/clipbybox2d_expected	2019-01-30 19:17:05 UTC (rev 17221)
@@ -7,3 +7,4 @@
 7|POLYGON((2 2,2 5,5 5,5 2,2 2))
 8|SRID=3857;POLYGON EMPTY
 9|SRID=4326;POINT(0 0)
+10|

Modified: branches/2.5/regress/mvt.sql
===================================================================
--- branches/2.5/regress/mvt.sql	2019-01-30 19:13:47 UTC (rev 17220)
+++ branches/2.5/regress/mvt.sql	2019-01-30 19:17:05 UTC (rev 17221)
@@ -561,3 +561,10 @@
 		0,
 		true
 		));
+
+SELECT '#4314', ST_AsMVTGeom(
+	'SRID=3857;MULTIPOLYGON(((-8230700.44460474 4970098.60762691,-8230694.76395068 4970080.40480045,-8230692.98226063 4970074.69572152,-8230702.2389602 4970071.78449542,-8230709.99536139 4970096.63875167,-8230700.73864062 4970099.5499925,-8230700.44460474 4970098.60762691)))'::geometry,
+	'SRID=3857;POLYGON((-8257645.03970416 5009377.08569731,-8257645.03970416 4970241.3272153,-8218509.28122215 4970241.3272153,-8218509.28122215 5009377.08569731,-8257645.03970416 5009377.08569731))'::geometry,
+	2048,
+	8,
+	true);
\ No newline at end of file

Modified: branches/2.5/regress/mvt_expected
===================================================================
--- branches/2.5/regress/mvt_expected	2019-01-30 19:13:47 UTC (rev 17220)
+++ branches/2.5/regress/mvt_expected	2019-01-30 19:17:05 UTC (rev 17221)
@@ -118,3 +118,4 @@
 ERROR:  pgis_asmvt_transfn: parameter row cannot be other than a rowtype
 TU3|
 #3922|6.5
+#4314|



More information about the postgis-tickets mailing list