[postgis-tickets] r17220 - ST_ClipByBox2D: Do not throw when the geometry is invalid
Raul
raul at rmr.ninja
Wed Jan 30 11:13:47 PST 2019
Author: algunenano
Date: 2019-01-30 11:13:47 -0800 (Wed, 30 Jan 2019)
New Revision: 17220
Modified:
trunk/NEWS
trunk/liblwgeom/cunit/cu_clip_by_rect.c
trunk/liblwgeom/lwgeom_geos.c
trunk/regress/core/clipbybox2d.sql
trunk/regress/core/clipbybox2d_expected
trunk/regress/core/mvt.sql
trunk/regress/core/mvt_expected
Log:
ST_ClipByBox2D: Do not throw when the geometry is invalid
References #4314
Closes https://github.com/postgis/postgis/pull/369
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2019-01-30 13:35:17 UTC (rev 17219)
+++ trunk/NEWS 2019-01-30 19:13:47 UTC (rev 17220)
@@ -66,6 +66,7 @@
- #4275, Avoid passing a NULL pointer to GEOSisEmpty (Raúl Marín)
- #4296, Use `server_version_num` instead of parsing `version()` (Raúl Marín)
- #4272, Improve notice message when unable to compute stats (Raúl Marín)
+ - #4314, ST_ClipByBox2D: Do not throw when the geometry is invalid (Raúl Marín)
PostGIS 2.5.0
Modified: trunk/liblwgeom/cunit/cu_clip_by_rect.c
===================================================================
--- trunk/liblwgeom/cunit/cu_clip_by_rect.c 2019-01-30 13:35:17 UTC (rev 17219)
+++ trunk/liblwgeom/cunit/cu_clip_by_rect.c 2019-01-30 19:13:47 UTC (rev 17220)
@@ -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: trunk/liblwgeom/lwgeom_geos.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos.c 2019-01-30 13:35:17 UTC (rev 17219)
+++ trunk/liblwgeom/lwgeom_geos.c 2019-01-30 19:13:47 UTC (rev 17220)
@@ -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: trunk/regress/core/clipbybox2d.sql
===================================================================
--- trunk/regress/core/clipbybox2d.sql 2019-01-30 13:35:17 UTC (rev 17219)
+++ trunk/regress/core/clipbybox2d.sql 2019-01-30 19:13:47 UTC (rev 17220)
@@ -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: trunk/regress/core/clipbybox2d_expected
===================================================================
--- trunk/regress/core/clipbybox2d_expected 2019-01-30 13:35:17 UTC (rev 17219)
+++ trunk/regress/core/clipbybox2d_expected 2019-01-30 19:13:47 UTC (rev 17220)
@@ -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: trunk/regress/core/mvt.sql
===================================================================
--- trunk/regress/core/mvt.sql 2019-01-30 13:35:17 UTC (rev 17219)
+++ trunk/regress/core/mvt.sql 2019-01-30 19:13:47 UTC (rev 17220)
@@ -579,6 +579,13 @@
ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
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);
+
-- Feature id encoding tests
SELECT 'FI1', encode(ST_AsMVT(q, 'test', 4096, 'geom', 'c1'), 'base64') FROM (
SELECT 1::smallint AS c1, 'abcd'::text AS c2,
Modified: trunk/regress/core/mvt_expected
===================================================================
--- trunk/regress/core/mvt_expected 2019-01-30 13:35:17 UTC (rev 17219)
+++ trunk/regress/core/mvt_expected 2019-01-30 19:13:47 UTC (rev 17220)
@@ -125,6 +125,7 @@
#3922|6.5
#4294_Horizontal|LINESTRING(0 10,0 5)
#4294_Vertical|LINESTRING(0 10,5 10)
+#4314|
FI1|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI=
FI2|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI=
FI3|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI=
More information about the postgis-tickets
mailing list