]> granicus.if.org Git - postgis/commitdiff
ST_IsValidReason(geometry) returns text reason for validity failure.
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 26 Nov 2008 19:04:15 +0000 (19:04 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 26 Nov 2008 19:04:15 +0000 (19:04 +0000)
Requires GEOS >= 3.1.
GBT#51

git-svn-id: http://svn.osgeo.org/postgis/trunk@3341 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_geos.c
lwgeom/lwpostgis.sql.in.c

index bc75710f9da8b040c64561212edefcd1d90f9b3f..60ff0d6e560e4db5f0c034561096a696e7acb466 100644 (file)
@@ -37,6 +37,7 @@ Datum containsproperly(PG_FUNCTION_ARGS);
 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);
@@ -1080,6 +1081,44 @@ Datum isvalid(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
index 9f4d942f4ae00f8a510c09f35d0395a6eebfa217..7cc0ac61e49cc6cba16f7278f40910070e56d781 100644 (file)
@@ -2352,7 +2352,7 @@ LANGUAGE 'SQL' _IMMUTABLE;
 -----------------------------------------------------------------------
 -- 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
@@ -3939,6 +3939,15 @@ CREATEFUNCTION ST_SimplifyPreserveTopology(geometry, float8)
     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