Datum covers(PG_FUNCTION_ARGS);
Datum overlaps(PG_FUNCTION_ARGS);
Datum isvalid(PG_FUNCTION_ARGS);
+Datum isvalidreason(PG_FUNCTION_ARGS);
Datum buffer(PG_FUNCTION_ARGS);
Datum intersection(PG_FUNCTION_ARGS);
Datum convexhull(PG_FUNCTION_ARGS);
}
+PG_FUNCTION_INFO_V1(isvalidreason);
+Datum isvalidreason(PG_FUNCTION_ARGS)
+{
+ PG_LWGEOM *geom = NULL;
+ char *reason_str = NULL;
+ int len = 0;
+ char *result = NULL;
+ GEOSGeom g1 = NULL;
+
+ geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
+ initGEOS(lwnotice, lwnotice);
+
+ g1 = POSTGIS2GEOS(geom);
+ if ( ! g1 )
+ {
+ PG_RETURN_NULL();
+ }
+
+ reason_str = GEOSisValidReason(g1);
+ GEOSGeom_destroy(g1);
+
+ if (reason_str == NULL)
+ {
+ elog(ERROR,"GEOS isvalidreason() threw an error!");
+ PG_RETURN_NULL(); /* never get here */
+ }
+ len = strlen(reason_str);
+ result = palloc(VARHDRSZ + len);
+ SET_VARSIZE(result, VARHDRSZ + len);
+ memcpy(VARDATA(result), reason_str, len);
+ free(reason_str);
+
+ PG_FREE_IF_COPY(geom, 0);
+ PG_RETURN_POINTER(result);
+
+}
+
/*
* overlaps(PG_LWGEOM g1,PG_LWGEOM g2)
* returns if GEOS::g1->overlaps(g2) returns true
-----------------------------------------------------------------------
-- This function will:
--
--- o try to fix the schema of records with an invalid one
+-- o try to fix the schema of records with an integer one
-- (for PG>=73)
--
-- o link records to system tables through attrelid and varattnum
LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
#endif
+#if POSTGIS_GEOS_VERSION >= 31
+-- Requires GEOS >= 3.1.0
+-- Availability: 1.4.0
+CREATEFUNCTION ST_IsValidReason(geometry)
+ RETURNS text
+ AS 'MODULE_PATHNAME', 'isvalidreason'
+ LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict,iscachable);
+#endif
+
-- Deprecation in 1.2.3
CREATEFUNCTION difference(geometry,geometry)
RETURNS geometry