Commit 5f7f5ff1 authored by Raúl Marín's avatar Raúl Marín

ST_ClipByBox2D: Do not throw when the geometry is invalid

Closes #4314


git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@17221 b70326c6-7e19-0410-871a-916f4a2858ee
parent fa3163d5
Pipeline #45491961 passed with stage
in 23 minutes and 56 seconds
......@@ -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)
......
......@@ -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);
}
/*
......
......@@ -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;
......
......@@ -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
......@@ -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|
......@@ -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
......@@ -118,3 +118,4 @@ TU2
ERROR: pgis_asmvt_transfn: parameter row cannot be other than a rowtype
TU3|
#3922|6.5
#4314|
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment