]> granicus.if.org Git - postgis/commitdiff
ST_ClipByBox2D: Do not throw when the geometry is invalid
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Wed, 30 Jan 2019 19:17:05 +0000 (19:17 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Wed, 30 Jan 2019 19:17:05 +0000 (19:17 +0000)
Closes #4314

git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@17221 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/cunit/cu_clip_by_rect.c
liblwgeom/lwgeom_geos.c
regress/clipbybox2d.sql
regress/clipbybox2d_expected
regress/mvt.sql
regress/mvt_expected

diff --git a/NEWS b/NEWS
index b35e82d7067f94799ee90bdf11820b7124a26755..d934b6b96ceaa7e7e4e53ea76711bde5ff0d661d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,7 @@ XXXX/XX/XX
   - #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)
 
 
 
index 95e93ae8a7b204626d13ef95855d0ded41f4e21a..c4cf8b1098e87179f07dcc91c841d7516bf47141 100644 (file)
@@ -64,6 +64,13 @@ static void test_lwgeom_clip_by_rect(void)
        //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);
 }
 
 /*
index 96dc8cea85706a2ab38fb2406eb61f2de8ef8fb5..69a8a3a5e9826e9eb4748994b09d7c2aab029cff 100644 (file)
@@ -65,12 +65,27 @@ do { \
        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__); \
        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,17 +885,17 @@ lwgeom_clip_by_rect(const LWGEOM *geom1, double x1, double y1, double x2, double
        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);
        GEOS_FREE(g3);
 
        if (!result)
-               GEOS_FAIL();
+               GEOS_FAIL_DEBUG();
 
        result->srid = geom1->srid;
 
index 56fa87cfab329694b39d12a8257489f40fd5d093..87d774675f1d781cf5cfaf5403dcc2502405ab1c 100644 (file)
@@ -22,3 +22,5 @@ CREATE TEMPORARY TABLE t AS SELECT
 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
index 8986b641e7219b46c5299dee650f1fed70bb8b6b..7588472e1bfa9a3afbbb5a563706bebfead68ceb 100644 (file)
@@ -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|
index ebd933ab51b2d0e83a51efcf86225f4ce5d61060..7aca92dc7aeea9649500f921ffd6751242e6bf82 100644 (file)
@@ -561,3 +561,10 @@ SELECT '#3922', St_Area(ST_AsMVTGeom(
                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
index 466e7ee79b76b4f88889baed1604fd06daec8641..c9fe91d47db333b631af9cf260050e4e07cfd4ca 100644 (file)
@@ -118,3 +118,4 @@ TU2
 ERROR:  pgis_asmvt_transfn: parameter row cannot be other than a rowtype
 TU3|
 #3922|6.5
+#4314|