<paramdef><type>geometry </type> <parameter>g</parameter></paramdef>
</funcprototype>
+ <funcprototype>
+ <funcdef>boolean <function>ST_IsValid</function></funcdef>
+
+ <paramdef><type>geometry </type> <parameter>g</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>flags</parameter></paramdef>
+ </funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<para>Test if an ST_Geometry value is well formed. For geometries that are invalid,
the PostgreSQL NOTICE will provide details of why it is not valid. For more
information on the OGC's definition of geometry simplicity and validity, refer
- to <link linkend="OGC_Validity">"Ensuring OpenGIS compliancy of geometries"</link></para>
+ to <link linkend="OGC_Validity">"Ensuring OpenGIS compliancy of geometries"</link>
+ </para>
<note>
<para>SQL-MM defines the result of ST_IsValid(NULL) to be 0, while
PostGIS returns NULL.</para>
</note>
+ <para>
+The version accepting flags is available starting with 2.0.0
+and requires GEOS >= 3.3.0. Such version does not print a NOTICE
+explaining the invalidity.
+Allowed <varname>flags</varname> are documented in <xref linkend="ST_IsValidDetail" />.
+ </para>
+
<para>&sfs_compliant;</para>
<para>&sqlmm_compliant; SQL-MM 3: 5.1.9</para>
+
</refsection>
<refsection>
<funcdef>text <function>ST_IsValidReason</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
</funcprototype>
+ <funcprototype>
+ <funcdef>text <function>ST_IsValidReason</function></funcdef>
+ <paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>flags</parameter></paramdef>
+ </funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<para>Returns text stating if a geometry is valid or not an if not valid, a reason why.</para>
<para>Useful in combination with ST_IsValid to generate a detailed report of invalid geometries and reasons.</para>
+
+ <para>
+Allowed <varname>flags</varname> are documented in <xref linkend="ST_IsValidDetail" />.
+ </para>
+
<para>Availability: 1.4 - requires GEOS >= 3.1.0.</para>
+ <para>Availability: 2.0 - requires GEOS >= 3.3.0 for the version taking flags.</para>
</refsection>
LANGUAGE 'C' IMMUTABLE STRICT
COST 100;
+#if POSTGIS_GEOS_VERSION >= 33
+-- Requires GEOS >= 3.3.0
+-- Availability: 2.0.0
+CREATE OR REPLACE FUNCTION ST_IsValidReason(geometry, int4)
+ RETURNS text
+ AS $$
+SELECT CASE WHEN valid THEN 'Valid Geometry' ELSE reason END FROM (
+ SELECT (ST_isValidDetail($1, $2)).*
+) foo
+ $$
+ LANGUAGE 'sql' IMMUTABLE STRICT
+ COST 100;
+#endif
+
+#if POSTGIS_GEOS_VERSION >= 33
+-- Requires GEOS >= 3.3.0
+-- Availability: 2.0.0
+CREATE OR REPLACE FUNCTION ST_IsValid(geometry, int4)
+ RETURNS boolean
+ AS 'SELECT (ST_isValidDetail($1, $2)).valid'
+ LANGUAGE 'sql' IMMUTABLE STRICT
+ COST 100;
+#endif
+
+
#if POSTGIS_GEOS_VERSION >= 32
-- Requires GEOS >= 3.2.0
-- Availability: 1.5.0
0 -- No flags
)).*
) foo;
+select '5s', ST_IsValid(
+'POLYGON ((70 250, 40 500, 100 400, 70 250, 80 350, 60 350, 70 250))' , 0);
+select '5r', ST_IsValidReason(
+'POLYGON ((70 250, 40 500, 100 400, 70 250, 80 350, 60 350, 70 250))' , 0);
-- Self-touching ring forming hole with ESRI flag
select 6, valid, reason, st_astext(location) FROM (
1 -- ESRI flag
)).*
) foo;
+select '6s', ST_IsValid(
+'POLYGON ((70 250, 40 500, 100 400, 70 250, 80 350, 60 350, 70 250))' , 1);
+select '5r', ST_IsValidReason(
+'POLYGON ((70 250, 40 500, 100 400, 70 250, 80 350, 60 350, 70 250))' , 1);
+
+
3|f|Self-intersection|POINT(70 400)
4|f|Self-intersection|POINT(70 400)
5|f|Ring Self-intersection|POINT(70 250)
+5s|f
+5r|Ring Self-intersection
6|t||
+6s|t
+5r|Valid Geometry