From 2c0396820154b65a7d505e75b71f8b3ce1614ebb Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Sun, 28 Feb 2010 19:09:00 +0000 Subject: [PATCH] Simplify code git-svn-id: http://svn.osgeo.org/postgis/trunk@5354 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/lwgeom_geos_clean.c | 69 ++++++------------------------------- 1 file changed, 10 insertions(+), 59 deletions(-) diff --git a/postgis/lwgeom_geos_clean.c b/postgis/lwgeom_geos_clean.c index 222901315..9bb014fea 100644 --- a/postgis/lwgeom_geos_clean.c +++ b/postgis/lwgeom_geos_clean.c @@ -413,7 +413,7 @@ static GEOSGeometry* LWGEOM_GEOS_makeValidPolygon(const GEOSGeometry* gin) { GEOSGeom gout; - GEOSGeom geos_bound, geos_bound_noded; + GEOSGeom geos_bound; GEOSGeom geos_cut_edges, geos_area; GEOSGeometry *vgeoms[2]; /* One for area, one for cut-edges */ @@ -431,72 +431,25 @@ LWGEOM_GEOS_makeValidPolygon(const GEOSGeometry* gin) lwgeom_to_ewkt(GEOS2LWGEOM(geos_bound, 0), PARSER_CHECK_NONE)); - /* Node boundaries */ + /* Use noded boundaries as initial "cut" edges */ - geos_bound_noded = LWGEOM_GEOS_nodeLines(geos_bound); - if ( NULL == geos_bound_noded ) + geos_cut_edges = LWGEOM_GEOS_nodeLines(geos_bound); + GEOSGeom_destroy(geos_bound); + if ( NULL == geos_cut_edges ) { lwnotice("LWGEOM_GEOS_nodeLines(): %s", loggederror); - GEOSGeom_destroy(geos_bound); return NULL; } - GEOSGeom_destroy(geos_bound); - - POSTGIS_DEBUGF(3, - "Noded: %s", - lwgeom_to_ewkt(GEOS2LWGEOM(geos_bound_noded, 0), - PARSER_CHECK_NONE)); - - geos_area = LWGEOM_GEOS_buildArea(geos_bound_noded); - if ( ! geos_area ) /* must be an exception ... */ + /* And use an empty geometry as initial "area" */ + geos_area = GEOSGeom_createEmptyPolygon(); + if ( ! geos_area ) { - /* cleanup */ - GEOSGeom_destroy(geos_bound_noded); - lwnotice("LWGEOM_GEOS_buildArea() threw an error: %s", - loggederror); - return NULL; - } - - if ( GEOSisEmpty(geos_area) ) - { - /* no area, it's all boundary */ - POSTGIS_DEBUG(3, "No area found, returning noded bounds"); - GEOSGeom_destroy(geos_area); - return geos_bound_noded; - } - - /* Compute what's left out from original boundary - * (this would be the so called 'cut lines' */ - geos_bound = GEOSBoundary(geos_area); - if ( ! geos_bound ) - { - /* Empty area most likely, - * noded original bounds are the result */ - lwnotice("GEOSBoundary('%s') threw an error: %s", - lwgeom_to_ewkt(GEOS2LWGEOM(geos_area, 0), - PARSER_CHECK_NONE), - loggederror); - GEOSGeom_destroy(geos_area); - return geos_bound_noded; - } - - geos_cut_edges = GEOSDifference(geos_bound_noded, geos_bound); - GEOSGeom_destroy(geos_bound); - if ( ! geos_cut_edges ) /* an exception ? */ - { - /* cleanup and throw */ - GEOSGeom_destroy(geos_bound_noded); - GEOSGeom_destroy(geos_area); - lwnotice("GEOSDifference() threw an error: %s", - loggederror); + lwnotice("GEOSGeom_createEmptyPolygon(): %s", loggederror); + GEOSGeom_destroy(geos_cut_edges); return NULL; } - POSTGIS_DEBUGF(3, - "Cut-edges: %s", - lwgeom_to_ewkt(GEOS2LWGEOM(geos_cut_edges, 0), - PARSER_CHECK_NONE)); /* * See if an area can be build with the remaining edges @@ -594,8 +547,6 @@ LWGEOM_GEOS_makeValidPolygon(const GEOSGeometry* gin) geos_cut_edges = new_cut_edges; } - GEOSGeom_destroy(geos_bound_noded); /* TODO: move up */ - /* Collect areas and lines (if any line) */ if ( ! GEOSisEmpty(geos_cut_edges) ) { -- 2.40.0