]> granicus.if.org Git - postgis/commitdiff
Have BuildArea catch exception from GEOSSymDifference (#1738)
authorSandro Santilli <strk@keybit.net>
Fri, 30 Mar 2012 08:36:17 +0000 (08:36 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 30 Mar 2012 08:36:17 +0000 (08:36 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9581 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/Makefile.in
liblwgeom/cunit/cu_clean.c [new file with mode: 0644]
liblwgeom/cunit/cu_tester.c
liblwgeom/lwgeom_geos.c

index cf24a49e1a63341015e47c417d10049aa9d48e35..36d4d4833bb76b7bbbd0493dcfb6229d6cbf682c 100644 (file)
@@ -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 (file)
index 0000000..3676595
--- /dev/null
@@ -0,0 +1,59 @@
+/**********************************************************************
+ *
+ * PostGIS - Spatial Types for PostgreSQL
+ * http://postgis.refractions.net
+ *
+ * Copyright (C) 2012 Sandro Santilli <strk@keybit.net>
+ *
+ * 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};
index 612d3be7e9480dd1e2c99ac40a949b5cde733c6f..49816443e76618b02cf18eb199ab228bc61703f5 100644 (file)
@@ -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,
index deb5593f34e8feffc6eb6def2e8f0b033f9bbf0e..fdf0c9f1403cf1ce9dcfb4e31634a2b32a295b12 100644 (file)
@@ -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)),