* 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+
*/
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
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*
Datum issimple(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom;
- GEOSGeometry *g1;
+ LWGEOM *lwgeom_in;
int result;
POSTGIS_DEBUG(2, "issimple called");
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);
}