]> granicus.if.org Git - postgis/commitdiff
Add lwgeom_is_simple method in liblwgeom, use from postgis module
authorSandro Santilli <strk@keybit.net>
Mon, 29 Jun 2015 15:28:37 +0000 (15:28 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 29 Jun 2015 15:28:37 +0000 (15:28 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13740 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/liblwgeom.h.in
liblwgeom/lwgeom_geos.c
postgis/lwgeom_geos.c

diff --git a/NEWS b/NEWS
index fdf642a48c6df92a96e1de9e26b867611db32848..bab64e53384af6913a964e181b3bc80fabc75d9b 100644 (file)
--- 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+
index 1e381e4b2f4bf0bb0033866a1a68c7d5aca9bd5f..c56107ef3dd0dbdb88a60039374c8e83578fe3a9 100644 (file)
@@ -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
index 893c8d32c4c94263ee519715b74ee6b93b32af43..9fd8827ca917a83ffe839f0a10a40e1cdfe386d2 100644 (file)
@@ -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*
index 789030b287a8875c1eb0ae04393b75a7d6ce6f8e..c3d1e90039f7c7e665f1acf864ee18bede5404d0 100644 (file)
@@ -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);
 }