From: Sandro Santilli Date: Thu, 17 May 2012 11:45:26 +0000 (+0000) Subject: Add lwgeom_normalize in LIBLWGEOM, use in cu_buildarea tester X-Git-Tag: 2.0.1~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9ec4df52a72d0b3c91b6026894ae5dedbaffee5;p=postgis Add lwgeom_normalize in LIBLWGEOM, use in cu_buildarea tester git-svn-id: http://svn.osgeo.org/postgis/trunk@9742 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index ae36fc148..446198a5f 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,7 @@ PostGIS 2.0.1 - #1786, improved build dependencies - #1802, improved function interruptibility. - #1806, speedup of ST_BuildArea, ST_MakeValid and ST_GetFaceGeometry. + - Add lwgeom_normalize in LIBLWGEOM PostGIS 2.0.0 2012/04/03 diff --git a/liblwgeom/cunit/cu_buildarea.c b/liblwgeom/cunit/cu_buildarea.c index a8a090b2d..01df54e91 100644 --- a/liblwgeom/cunit/cu_buildarea.c +++ b/liblwgeom/cunit/cu_buildarea.c @@ -22,15 +22,22 @@ */ #define check_geom_equal(gobt, gexp) do { \ char *obt, *exp; \ - if ( ! lwgeom_same((gobt), (gexp)) ) { \ - obt = lwgeom_to_wkt((gobt), WKT_ISO, 8, NULL); \ - exp = lwgeom_to_wkt((gexp), WKT_ISO, 8, NULL); \ + LWGEOM *ngobt, *ngexp; \ + ngobt = lwgeom_normalize(gobt); \ + ngexp = lwgeom_normalize(gexp); \ + if ( ! lwgeom_same((ngobt), (ngexp)) ) { \ + obt = lwgeom_to_wkt((ngobt), WKT_ISO, 8, NULL); \ + exp = lwgeom_to_wkt((ngexp), WKT_ISO, 8, NULL); \ printf(" Failure at %s:%d\n", __FILE__, __LINE__); \ printf(" Exp: %s\n", exp); \ printf(" Obt: %s\n", obt); \ free(obt); free(exp); \ + lwgeom_free(ngobt); lwgeom_free(ngexp); \ CU_ASSERT(0); \ - } else CU_ASSERT(1); \ + } else { \ + lwgeom_free(ngobt); lwgeom_free(ngexp); \ + CU_ASSERT(1); \ + } \ } while (0) /* diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 70cd275e1..9c2293815 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -1808,6 +1808,7 @@ const char* lwgeom_geos_version(void); /** Convert an LWGEOM to a GEOS Geometry and convert back -- for debug only */ LWGEOM* lwgeom_geos_noop(const LWGEOM *geom) ; +LWGEOM *lwgeom_normalize(const LWGEOM *geom); LWGEOM *lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2); LWGEOM *lwgeom_difference(const LWGEOM *geom1, const LWGEOM *geom2); LWGEOM *lwgeom_symdifference(const LWGEOM* geom1, const LWGEOM* geom2); diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index 5edd3c433..88cfbce39 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -416,6 +416,46 @@ lwgeom_geos_version() return ver; } +LWGEOM * +lwgeom_normalize(const LWGEOM *geom1) +{ + LWGEOM *result ; + GEOSGeometry *g1; + int is3d ; + int srid ; + + srid = (int)(geom1->srid); + is3d = FLAGS_GET_Z(geom1->flags); + + initGEOS(lwnotice, lwgeom_geos_error); + + g1 = LWGEOM2GEOS(geom1); + if ( 0 == g1 ) /* exception thrown at construction */ + { + lwerror("First argument geometry could not be converted to GEOS."); + return NULL ; + } + + if ( -1 == GEOSNormalize(g1) ) + { + lwerror("Error in GEOSNormalize: %s", lwgeom_geos_errmsg); + return NULL; /* never get here */ + } + + GEOSSetSRID(g1, srid); /* needed ? */ + result = GEOS2LWGEOM(g1, is3d); + GEOSGeom_destroy(g1); + + if (result == NULL) + { + lwerror("Error performing intersection: GEOS2LWGEOM: %s", + lwgeom_geos_errmsg); + return NULL ; /* never get here */ + } + + return result ; +} + LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2) {