#if POSTGIS_GEOS_VERSION >= 33
LWGEOM *gin, *gout;
int ret;
+ char *ewkt;
/* Because i don't trust that much prior tests... ;) */
cu_error_msg_reset();
lwgeom_free(gout);
lwgeom_free(gin);
+
+ gin = lwgeom_from_wkt(
+"GEOMETRYCOLLECTION(LINESTRING(0 0, 0 0), POLYGON((0 0, 10 10, 10 0, 0 10, 0 0)), LINESTRING(10 0, 10 10))",
+ LW_PARSER_CHECK_NONE);
+ CU_ASSERT(gin);
+
+ gout = lwgeom_make_valid(gin);
+ CU_ASSERT(gout);
+
+ ewkt = lwgeom_to_ewkt(gout);
+ printf("c = %s\n", ewkt);
+ CU_ASSERT_STRING_EQUAL(ewkt,
+"GEOMETRYCOLLECTION(POINT(0 0),MULTIPOLYGON(((5 5,0 0,0 10,5 5)),((5 5,10 10,10 0,5 5))),LINESTRING(10 0,10 10))");
+ lwfree(ewkt);
+
+ lwgeom_free(gout);
+ lwgeom_free(gin);
+
#endif /* POSTGIS_GEOS_VERSION >= 33 */
}
/* cleanup and throw */
GEOSGeom_destroy(geos_cut_edges);
GEOSGeom_destroy(geos_area);
+ /* TODO: Shouldn't this be an lwerror ? */
lwnotice("GEOSDifference() threw an error: %s",
lwgeom_geos_errmsg);
return NULL;
if ( ! gout ) /* an exception again */
{
/* cleanup and throw */
+ /* TODO: Shouldn't this be an lwerror ? */
lwnotice("GEOSGeom_createCollection() threw an error: %s",
lwgeom_geos_errmsg);
/* TODO: cleanup! */
return gout;
}
+static GEOSGeometry* LWGEOM_GEOS_makeValid(const GEOSGeometry*);
+
+/*
+ * We expect initGEOS being called already.
+ * Will return NULL on error (expect error handler being called by then)
+ */
+static GEOSGeometry*
+LWGEOM_GEOS_makeValidCollection(const GEOSGeometry* gin)
+{
+ int nvgeoms;
+ GEOSGeometry **vgeoms;
+ GEOSGeom gout;
+ unsigned int i;
+
+ nvgeoms = GEOSGetNumGeometries(gin);
+ if ( nvgeoms == -1 ) {
+ lwerror("GEOSGetNumGeometries: %s", lwgeom_geos_errmsg);
+ return 0;
+ }
+
+ vgeoms = lwalloc( sizeof(GEOSGeometry*) * nvgeoms );
+ if ( ! vgeoms ) {
+ lwerror("LWGEOM_GEOS_makeValidCollection: out of memory");
+ return 0;
+ }
+
+ for ( i=0; i<nvgeoms; ++i ) {
+ vgeoms[i] = LWGEOM_GEOS_makeValid( GEOSGetGeometryN(gin, i) );
+ if ( ! vgeoms[i] ) {
+ while (i--) GEOSGeom_destroy(vgeoms[i]);
+ lwfree(vgeoms);
+ /* we expect lwerror being called already by makeValid */
+ return NULL;
+ }
+ }
+
+ /* Collect areas and lines (if any line) */
+ gout = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, vgeoms, nvgeoms);
+ lwfree(vgeoms);
+ if ( ! gout ) /* an exception again */
+ {
+ /* cleanup and throw */
+ for ( i=0; i<nvgeoms; ++i ) GEOSGeom_destroy(vgeoms[i]);
+ lwerror("GEOSGeom_createCollection() threw an error: %s",
+ lwgeom_geos_errmsg);
+ return NULL;
+ }
+
+ return gout;
+
+}
+
static GEOSGeometry*
LWGEOM_GEOS_makeValid(const GEOSGeometry* gin)
break; /* we've done */
}
+ case GEOS_GEOMETRYCOLLECTION:
+ {
+ gout = LWGEOM_GEOS_makeValidCollection(gin);
+ if ( ! gout ) /* an exception or something */
+ {
+ /* cleanup and throw */
+ lwerror("%s", lwgeom_geos_errmsg);
+ return NULL;
+ }
+ break; /* we've done */
+ }
+
default:
{
char* typname = GEOSGeomType(gin);