From: Sandro Santilli Date: Fri, 30 Mar 2012 08:36:17 +0000 (+0000) Subject: Have BuildArea catch exception from GEOSSymDifference (#1738) X-Git-Tag: 2.0.0rc2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd783e7b6ba2d6483fcc4f27ea28964dbffd2eb5;p=postgis Have BuildArea catch exception from GEOSSymDifference (#1738) git-svn-id: http://svn.osgeo.org/postgis/trunk@9581 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/Makefile.in b/liblwgeom/cunit/Makefile.in index cf24a49e1..36d4d4833 100644 --- a/liblwgeom/cunit/Makefile.in +++ b/liblwgeom/cunit/Makefile.in @@ -23,6 +23,7 @@ CUNIT_CPPFLAGS=@CUNIT_CPPFLAGS@ -I.. # ADD YOUR NEW TEST FILE HERE (1/1) OBJS= \ cu_algorithm.o \ + cu_clean.o \ cu_print.o \ cu_misc.o \ cu_ptarray.o \ diff --git a/liblwgeom/cunit/cu_clean.c b/liblwgeom/cunit/cu_clean.c new file mode 100644 index 000000000..367659509 --- /dev/null +++ b/liblwgeom/cunit/cu_clean.c @@ -0,0 +1,59 @@ +/********************************************************************** + * + * PostGIS - Spatial Types for PostgreSQL + * http://postgis.refractions.net + * + * Copyright (C) 2012 Sandro Santilli + * + * This is free software; you can redistribute and/or modify it under + * the terms of the GNU General Public Licence. See the COPYING file. + * + **********************************************************************/ + +#include "CUnit/Basic.h" +#include "cu_tester.h" + +#include "liblwgeom.h" +#include "liblwgeom_internal.h" + +static void test_lwgeom_make_valid(void) +{ +#if POSTGIS_GEOS_VERSION >= 33 + LWGEOM *gin, *gout; + int ret; + + /* Because i don't trust that much prior tests... ;) */ + cu_error_msg_reset(); + + gin = lwgeom_from_wkt( +"MULTIPOLYGON(((1725063 4819121, 1725104 4819067, 1725060 4819087, 1725064.14183882 4819094.70208557,1725064.13656044 4819094.70235069,1725064.14210359 4819094.70227252,1725064.14210362 4819094.70227252,1725064.13656043 4819094.70235069,1725055. 4819094, 1725055 4819094, 1725055 4819094, 1725063 4819121)))", + LW_PARSER_CHECK_NONE); + CU_ASSERT(gin); + + gout = lwgeom_make_valid(gin); + + /* We're really only interested in avoiding a crash in here. + * See http://trac.osgeo.org/postgis/ticket/1738 + * TODO: enhance the test if we find a workaround + * to the excepion: + * See http://trac.osgeo.org/postgis/ticket/1735 + */ + + lwgeom_free(gout); + lwgeom_free(gin); + +#endif /* POSTGIS_GEOS_VERSION >= 33 */ +} + +/* TODO: add more tests ! */ + + +/* +** Used by test harness to register the tests in this file. +*/ +static CU_TestInfo clean_tests[] = +{ + PG_TEST(test_lwgeom_make_valid), + CU_TEST_INFO_NULL +}; +CU_SuiteInfo clean_suite = {"clean", NULL, NULL, clean_tests}; diff --git a/liblwgeom/cunit/cu_tester.c b/liblwgeom/cunit/cu_tester.c index 612d3be7e..49816443e 100644 --- a/liblwgeom/cunit/cu_tester.c +++ b/liblwgeom/cunit/cu_tester.c @@ -19,6 +19,7 @@ /* ADD YOUR SUITE HERE (1 of 2) */ extern CU_SuiteInfo print_suite; extern CU_SuiteInfo algorithms_suite; +extern CU_SuiteInfo clean_suite; extern CU_SuiteInfo misc_suite; extern CU_SuiteInfo ptarray_suite; extern CU_SuiteInfo measures_suite; @@ -54,6 +55,7 @@ int main(int argc, char *argv[]) misc_suite, ptarray_suite, algorithms_suite, + clean_suite, measures_suite, node_suite, wkt_out_suite, diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index deb5593f3..fdf0c9f14 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -825,6 +825,11 @@ LWGEOM_GEOS_buildArea(const GEOSGeometry* geom_in) else { tmp = GEOSSymDifference(shp, extring); + if ( tmp == NULL ) /* exception */ + { + lwerror("GEOSSymDifference threw an exception: %s", lwgeom_geos_errmsg); + return NULL; + } LWDEBUGF(3, "GEOSpolygonize: SymDifference(%s, %s):%s", lwgeom_to_ewkt(GEOS2LWGEOM(shp, 0)), lwgeom_to_ewkt(GEOS2LWGEOM(extring, 0)),