From 46025a47a12eb450a3cb96c16c53f42b77d0e9cf Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 29 Jun 2015 15:28:37 +0000 Subject: [PATCH] Add lwgeom_is_simple method in liblwgeom, use from postgis module git-svn-id: http://svn.osgeo.org/postgis/trunk@13740 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 4 +++- liblwgeom/liblwgeom.h.in | 8 ++++++++ liblwgeom/lwgeom_geos.c | 32 ++++++++++++++++++++++++++++++++ postgis/lwgeom_geos.c | 22 ++++++---------------- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index fdf642a48..bab64e533 100644 --- a/NEWS +++ b/NEWS @@ -31,7 +31,9 @@ PostGIS 2.2.0 * New Features * - - #3117, Add SFCGAL 1.1 support: add ST_3DDifference, ST_3DUnion, ST_Volume, ST_MakeSolid, ST_IsSolid (Vincent Mora / Oslandia) + - New lwgeom_is_simple method in liblwgeom + - #3117, Add SFCGAL 1.1 support: add ST_3DDifference, ST_3DUnion, + ST_Volume, ST_MakeSolid, ST_IsSolid (Vincent Mora / Oslandia) - #3169, ST_ApproximateMedialAxis (Sandro Santilli) - ST_CPAWithin (Sandro Santilli / Boundless) - Add |=| operator with CPA semantic and KNN support with PgSQL 9.5+ diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 1e381e4b2..c56107ef3 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -2064,6 +2064,14 @@ LWGEOM* lwgeom_sharedpaths(const LWGEOM* geom1, const LWGEOM* geom2); */ LWGEOM* lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyle, double mitreLimit); +/* + * Return true if the input geometry is "simple" as per OGC defn. + * + * @return 1 if simple, 0 if non-simple, -1 on exception (lwerror is called + * in that case) + */ +int lwgeom_is_simple(const LWGEOM *lwgeom); + /******************************************************************************* * PROJ4-dependent extra functions on LWGEOM diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index 893c8d32c..9fd8827ca 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -1195,6 +1195,38 @@ lwgeom_buildarea(const LWGEOM *geom) return geom_out; } +int +lwgeom_is_simple(const LWGEOM *geom) +{ + GEOSGeometry* geos_in; + int simple; + + /* Empty is always simple */ + if ( lwgeom_is_empty(geom) ) + { + return 1; + } + + initGEOS(lwnotice, lwgeom_geos_error); + + geos_in = LWGEOM2GEOS(geom, 0); + if ( 0 == geos_in ) /* exception thrown at construction */ + { + lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg); + return -1; + } + simple = GEOSisSimple(geos_in); + GEOSGeom_destroy(geos_in); + + if ( simple == 2 ) /* exception thrown */ + { + lwerror("lwgeom_is_simple: %s", lwgeom_geos_errmsg); + return -1; + } + + return simple ? 1 : 0; +} + /* ------------ end of BuildArea stuff ---------------------------------------------------------------------} */ LWGEOM* diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index 789030b28..c3d1e9003 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -3132,7 +3132,7 @@ PG_FUNCTION_INFO_V1(issimple); Datum issimple(PG_FUNCTION_ARGS) { GSERIALIZED *geom; - GEOSGeometry *g1; + LWGEOM *lwgeom_in; int result; POSTGIS_DEBUG(2, "issimple called"); @@ -3142,25 +3142,15 @@ Datum issimple(PG_FUNCTION_ARGS) if ( gserialized_is_empty(geom) ) PG_RETURN_BOOL(TRUE); - initGEOS(lwpgnotice, lwgeom_geos_error); - - g1 = (GEOSGeometry *)POSTGIS2GEOS(geom); - if ( 0 == g1 ) /* exception thrown at construction */ - { - HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS"); - PG_RETURN_NULL(); - } - result = GEOSisSimple(g1); - GEOSGeom_destroy(g1); + lwgeom_in = lwgeom_from_gserialized(geom); + result = lwgeom_is_simple(lwgeom_in); + lwgeom_free(lwgeom_in) ; + PG_FREE_IF_COPY(geom, 0); - if (result == 2) - { - HANDLE_GEOS_ERROR("GEOSisSimple"); + if (result == -1) { PG_RETURN_NULL(); /*never get here */ } - PG_FREE_IF_COPY(geom, 0); - PG_RETURN_BOOL(result); } -- 2.40.0