[SCM] PostGIS branch master updated. 3.7.0rc3-22-gee8fcf7f2

git at osgeo.org git at osgeo.org
Sat Nov 14 23:40:36 PST 2026


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  ee8fcf7f2505fae42c2a505987cdcc6c17ef57ba (commit)
       via  8068073a3fc6455cbc2a98a1fee31efcd935c592 (commit)
       via  c6aa14f35f2dfc5731c2375ba077937fc90f6fe0 (commit)
       via  346c6bef644a4e6f4a682d674aad985f36dab631 (commit)
       via  51a9c367f5670bcd1e927ee735114be4bd8d5bc2 (commit)
      from  fde3f7fa570d8aa1b48190dc6896e9a3527b0326 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ee8fcf7f2505fae42c2a505987cdcc6c17ef57ba
Merge: fde3f7fa5 8068073a3
Author: Darafei Praliaskouski <me at komzpa.net>
Date:   Sun Nov 15 09:04:29 2026 +0400

    Add SFCGAL validity and simplicity predicates
    
    Expose validity and detail checks for 2D and 3D geometries, with
    simplicity predicates on SFCGAL 2.3 and newer. Register the new APIs
    for PostGIS 3.8.0 and document their behavior.
    
    Closes #4363
    Closes https://github.com/postgis/postgis/pull/1070

diff --cc NEWS
index 87861a5dd,3cd3e2220..916a9c4b2
--- a/NEWS
+++ b/NEWS
@@@ -1,253 -1,5 +1,259 @@@
 -PostGIS 3.7.0rc1
 +PostGIS 3.8.0dev
  2026/xx/xx
 +
++* New Features *
++
++ - #4363, GH-1070, [sfcgal] Add CG_IsValid, CG_IsValidDetail, and SFCGAL 2.3+
++          CG_IsSimple and CG_IsSimpleDetail predicates
++          (Darafei Praliaskouski)
++
 +* Enhancements *
 +
 + - GT-811, Remove pointer addresses from error and notice messages
 +          (Andrew Kroh)
 + - #1558, GT-419, Document RETURNS TABLE signatures with returned columns
 +          (Darafei Praliaskouski)
 +
 +
 +PostGIS 3.7.0rc3
 +2026/10/20
 +
 +This version requires GEOS 3.10+, PostgreSQL 14-19beta3, Proj 6.1+, and libgmp.
 +To take advantage of all postgis extension features, GEOS 3.15+ is needed.
 +To take advantage of all postgis_sfcgal extension features SFCGAL 2.3+ is needed.
 +Python 3 is a new requirement to build the documentation.
 +
 +Visual examples in the docs are off by default. To build docs with them,
 +configure with `--with-visual-examples` and make sure you have a running
 +PostgreSQL instance; they are then generated automatically when building
 +the docs (or explicitly with `make -C regress visual-examples`).
 +
 +
 +* Breaking Changes *
 +
 + - #5688, [topology] topology building functions now interpret tolerance 0
 +          (old default) to really mean 0 and want -1 (new default) to mean
 +          "use topology precision" (Sandro Santilli)
 + - #6024, Remove support for PostgreSQL 12 and 13 (Regina Obe)
 + - #6040, ST_GeoHash round trip through ST_GeomFromGeoHash (Paul Ramsey)
 + - #6053, [address_standardizer] Extension removed and moved to
 +          https://github.com/postgis/address_standardizer (Paul Ramsey)
 + - #6052, [tiger_geocoder] Extension removed and moved to
 +          https://git.osgeo.org/postgis/postgis_tiger_geocoder (Regina Obe)
 + - #6079, Remove support for GEOS < 3.10 (Sandro Santilli)
 + - #1793, Remove ST_MemCollect aggregate (Darafei Praliaskouski)
 + - GH-848, CG_AlphaShape now returns a MultiPolygon (Jean Felder)
 + - [docs] Python 3 and an SVG rasterizer (rsvg-convert preferred,
 +          GraphicsMagick or ImageMagick supported) now required for doc
 +          dynamic image rendering (Darafei Praliaskouski)
 +
 +* New Features *
 +
 + - #6132, ST_IsSimpleDetail (Sandro Santilli)
 + - #1124, #2935, #3033, #4658, #4659, [loader] Rework loader arguments:
 +          shp2pgsql can create UNLOGGED tables and choose the feature id column
 +          name, shp2pgsql --drop-table can emit DROP TABLE before prepare
 +          output, raster2pgsql/shp2pgsql expose loader actions as long options,
 +          both loaders accept long aliases for existing options, and
 +          --if-not-exists makes creation actions idempotent
 +          (Darafei Praliaskouski)
 + - #4208, Add single-geometry variants of ST_MaxDistance and ST_LongestLine
 +          (Darafei Praliaskouski)
 + - [topology] FindVertexSegmentPairsBelowDistance function (Sandro Santilli)
 + - ST_CoverageEdges, returns MultiLinestring of distinct shared edges in
 +          polygonal coverage (Paul Ramsey)
 + - ST_MinimumSpanningTree, window function to calculate MST (Paul Ramsey)
 + - #5993, [topology] Add max_edges parameter to TopoGeo_AddLinestring
 +          (Sandro Santilli)
 + - #6001, support MultiLineString in ST_MakeLine (Paul Ramsey)
 + - #2858, ST_MMin and ST_MMax (Paul Ramsey)
 + - #5941, [raster] Support GDT_Float16 pixel type (Darafei Praliaskouski)
 + - #5992, Optimize GiST index for repeated edge subdivision in topology (Darafei Praliaskouski)
 + - #5702, Allow the compiler to detect the parallelism -flto=auto (Darafei Praliaskouski)
 + - #4798, ST_AsGeoJSON warns about duplicate property keys (Darafei Praliaskouski)
 + - #4222, [raster] ST_DumpAsPolygons honours PostgreSQL interrupts (Darafei Praliaskouski)
 + - #5889, [topology] Include representative locations in topology build errors (Darafei Praliaskouski)
 + - #2614, Use GEOSPreparedDistance and caching to accelerate ST_DWithin (Paul Ramsey)
 + - GH-839, ST_Multi support for TIN and surfaces (Loïc Bartoletti)
 + - #4398, Add ST_CatmullSmoothing smoothes but retains original vertices (Paul Ramsey)
 + - #4560, ST_3DInterpolatePoint for M interpolation from XYZ inputs (Paul Ramsey)
 + - #1291, ST_MakePolygon support for curved rings (Darafei Praliaskouski)
 + - GT-270, Add NURBSCurve (Loïc Bartoletti)
 + - #2863, Add ST_XSize, ST_YSize, ST_ZSize, and ST_MSize dimension helpers
 +          (Darafei Praliaskouski)
 + - GH-870, CG_ApproximateMedialAxis: Add an overload to project the medial
 +           axis to the boundary. (Loïc Bartoletti)
 + - GH-871, Add CG_PolygonRepair (Loïc Bartoletti)
 + - GH-872, SFCGAL roof generation algorithms (Loïc Bartoletti)
 + - GT-806, #6124 --with-visual-examples opt-in
 +           configure switch to build dynamic images (Regina Obe)
 +
 +* Enhancements *
 +
 + - #6140, #6138, #6129, [topology] improve topology building and checking
 +          robustness (Sandro Santilli)
 + - #2045, pgsql2shp query dumps no longer require temporary table
 +          privileges (Darafei Praliaskouski)
 + - #1577, [loader] Report unsupported .zip archive input before trying
 +          to open shapefile sidecar files (Darafei Praliaskouski)
 + - #3158, Move geometry and geography typmod bit helpers out of the
 +          public liblwgeom header (Darafei Praliaskouski)
 + - #3776, [raster] Keep distinct 32-bit integer pixel values separate in
 +          ST_DumpAsPolygons (Darafei Praliaskouski)
 + - #4678, [raster] Move st_sum4ma neighborhood callback to C
 +          (Darafei Praliaskouski)
 + - #2116, [raster] Add ST_Value nearest-neighbor boundary options
 +          (Darafei Praliaskouski)
 + - #2804, #4315, [raster] Support two-argument ST_MapAlgebra callbacks
 +          and pass callback call data as actual arguments (Darafei Praliaskouski)
 + - #6062, [topology] Stop using recursive snapping, for improved robustness (Sandro Santilli)
 + - #6065, Improved winding order computation robustness for rings having collapsed elements
 +          (Sandro Santilli)
 + - #2137, [raster] Reuse matching source raster overviews in raster2pgsql -l
 +          (Darafei Praliaskouski)
 + - #4749, Use point-in-polygon predicate fast paths for point-only
 +          GeometryCollections (Darafei Praliaskouski)
 + - #2807, [raster] Preserve missing NODATA values in ST_MapAlgebra outputs
 +          (Darafei Praliaskouski)
 + - #2832, [raster] Avoid padding single-tile raster2pgsql overviews
 +          when padding is not requested (Darafei Praliaskouski)
 + - #2623, Generate a pgsql2shp GID field when exporting geometry-only
 +          shapefiles (Darafei Praliaskouski)
 + - #2850, Preserve pgsql2shp numeric precision and scale in DBF metadata
 +          (Darafei Praliaskouski)
 + - Build PostgreSQL extension modules with `-fno-semantic-interposition` when
 +          available so LTO can optimize same-DSO calls to exported PostGIS
 +          entry points directly instead of routing through the module PLT; in
 +          a local PostgreSQL 18 `pgbench` microbenchmark over 100k four-point
 +          groups this reduced `ST_Collect` aggregate latency by about 4%
 +          (Darafei Praliaskouski)
 + - #5973, Install PostGIS utilities under `pg_config --bindir` by default
 +          and document `pg_config`-derived install paths more accurately
 +          (Darafei Praliaskouski)
 + - #2808, Clarify postgis_full_version() output when installed component
 +          scripts are newer than core scripts (Darafei Praliaskouski)
 + - #2838, Emit valid X3D Coordinate nodes for 2D polygon output
 +          (Darafei Praliaskouski)
 + - GH-899, [raster] Honor PostgreSQL interrupts in long-running GDAL
 +          progress callbacks (Darafei Praliaskouski)
 + - #6073, #6074, Stabilize geography LRS endpoint interpolation and pole
 +          centroid regressions on 32-bit systems (Darafei Praliaskouski)
 + - #2583, Preserve Z/ZM dimensional qualifiers in ST_AsEWKT output for TIN
 +          (Darafei Praliaskouski)
 + - #4616, Detect pgsql2shp query keywords case-insensitively
 +          (Darafei Praliaskouski)
 + - #1986, ST_GeomFromGML support for GML ArcString and curved polygon rings
 +          (Darafei Praliaskouski)
 + - #4749, Use point-in-polygon predicate fast paths for point-only
 +          GeometryCollections, including ST_Disjoint (Darafei Praliaskouski)
 + - #3676, Mark geometry and geography btree comparison support functions
 +          as leakproof (Darafei Praliaskouski)
 + - GH-875, Allow ST_OrderingEquals joins to use hash and merge join plans
 +          (Darafei Praliaskouski)
 + - #1168, [raster] Support curved geometry inputs in ST_AsRaster
 +          (Darafei Praliaskouski)
 + - #1416, ST_AsX3D outputs NURBSCURVE as X3D NurbsCurve
 +          and linearizes other curve geometries
 +          (Darafei Praliaskouski)
 + - #3705, ST_AsX3D outputs valid coordinate nodes for 2D multi-geometries
 +          and GeometryCollections (Darafei Praliaskouski)
 + - GT-484, Use column-level SELECT privileges for metadata views
 +          (Arthur Bazin)
 + - #1408, #2386, #2557, #2805, #2898, #3743, #4323, #4332, #4385, #5109,
 +          #5532, #5593, #5638, #5645, #5950, #6022, #6082, GH-1161, GT-584,
 +          Numerous doc enhancements (Darafei Praliaskouski)
 +
 +* Bug Fixes *
 +
 + - [raster] Make postgis.enable_outdb_rasters=off enforce offline-band
 +          metadata and pixel-read restrictions after upgrade
 +          (reported by Sarath Kumar, IITM Pravartak Security Team;
 +          fixed by Darafei Praliaskouski)
 + - GH-1175, Guard missing operands before reading node tags in
 +          spatial selectivity estimation (Maksim Korotkov)
 +
 + - #6118, Reject empty geometry type modifiers without an out-of-bounds read
 +          (Egor Ivkov)
 + - Fix WKB and TWKB parser resource exhaustion on malformed input
 +          (Darafei Praliaskouski)
 + - #6038, Avoid stale relation lookups in geometry_columns after topology
 +          objects are dropped (Darafei Praliaskouski)
 + - #5487, Improve error detail for repeated upgrades after an incomplete
 +          deprecated-function cleanup (Darafei Praliaskouski)
 + - #5975, Initialize skipped union-find cluster ids deterministically
 +          (Darafei Praliaskouski)
 + - #5904, [topology] Avoid MinGW format warnings when logging topology ids
 +          (Darafei Praliaskouski)
 + - GH-888, [sfcgal] Avoid stale detoasted geometry access in
 +          CG_Visibility empty-input handling for SFCGAL < 2.2
 +          (Darafei Praliaskouski)
 + - #3179, Mark truncated libpgcommon PostgreSQL messages instead of silently
 +          dropping the tail (Darafei Praliaskouski)
 + - #6003, Avoid size_t formats in liblwgeom logging/error wrappers for
 +          MinGW builds (Darafei Praliaskouski)
 + - GH-886, ST_ClusterRelateWin validates NULL relate matrices before
 +          detoasting them (Darafei Praliaskouski)
 + - GH-889, ST_Relate pattern inversion avoids out-of-bounds access on
 +          short DE-9IM patterns (Darafei Praliaskouski)
 + - GH-890, Avoid GIDX BRIN summary merges across mismatched dimensions
 +          (Darafei Praliaskouski)
 + - #5959, Prevent histogram target overflow when analysing massive tables (Darafei Praliaskouski)
 + - #6080, Avoid out-of-bounds hex WKB lookup for high-bit input bytes
 +          (Darafei Praliaskouski)
 + - #4828, geometry_columns handles NOT VALID SRID checks without errors (Darafei Praliaskouski)
 + - #6048, [raster] ST_Clip no longer crashes when clipping sparse band
 +          selections (Darafei Praliaskouski)
 + - GH-894, [raster] Fix Float16 import, mixed nodata warping,
 +          band replacement cleanup, GDAL credential redaction, and Python
 +          GDAL compatibility (Darafei Praliaskouski)
 +
 +
 +PostGIS 3.7.0rc1
 +2026/08/24
 +This version requires GEOS 3.10+, PostgreSQL 14-19beta2, Proj 6.1+, libgmp.
 +To take advantage of all features postgis extension features, GEOS 3.15+ is needed.
 +To take advantage of all postgis_sfcgal extension features SFCGAL 2.3+ is needed.
 +
 +These are only changes since 3.7.0beta2.
 +
 +* Bug Fixes *
 +
 + - GH-1172, GH-1173, GH-1174, guard lwgeom_wrapx and raster OOM cleanup paths
 +          against NULL dereferences (Maksim Korotkov, Postgres Pro)
 + - Codex security scan, guard the recursive NURBSCURVE bounding box
 +          against non-finite control points to stop a backend CPU denial
 +          of service reachable from WKT input (Darafei Praliaskouski)
 + - GT-755, OSSFuzz 547330051, stream NURBSCURVE bounding box Bezier extraction
 +          to avoid repeated full-array knot insertion on large valid curves
 +          (Darafei Praliaskouski)
 + - Fix geometry input parsing to stop malformed SRID prefixes before the
 +          end of the input string
 +          (Dennis Tighe, Google)
 + - OSSFuzz 545658571, compare GSERIALIZED bytea fuzzer SRIDs after
 +          normalizing out-of-range values (Darafei Praliaskouski)
 + - OSSFuzz 5607611131822080, keep GSERIALIZED bytea fuzzer allocations
 +          consistent with hostile varlena size headers (Darafei Praliaskouski)
 + - #6111, Skip NEWS unit tests outside Git worktrees, fixing source
 +          package documentation checks without git (Bas Couwenberg)
 + - #6112, Document GMP and current build dependency requirements in
 +          README.postgis (Darafei Praliaskouski)
 + - OSSFuzz 544800490, reject malformed GSERIALIZED polygon rings before
 +          deserializing geometry data (Darafei Praliaskouski)
 + - OSSFuzz 544936363, keep GSERIALIZED LWGEOM fuzzer bbox
 +          comparisons aligned with serialized bbox flags (Darafei Praliaskouski)
 + - Reject truncated GSERIALIZED NURBS vector payloads before validating vector
 +          contents (Darafei Praliaskouski)
 + - Include detected NURBS coordinate extrema in curve bounding boxes
 +          (Darafei Praliaskouski)
 + - OSSFuzz 6152109301760000, reject overlong encoded polyline coordinate
 +          varints (Darafei Praliaskouski)
 + - OSSFuzz 4743900859006976, reject encoded polyline coordinate deltas
 +          that overflow accumulated int32 coordinates (Darafei Praliaskouski)
 +
 +
 +
 +PostGIS 3.7.0beta2
 +2026/08/09
  This version requires GEOS 3.10+, PostgreSQL 14-19beta2, Proj 6.1+, libgmp.
  To take advantage of all features postgis extension features, GEOS 3.15+ is needed.
  To take advantage of all postgis_sfcgal extension features SFCGAL 2.3+ is needed.
diff --cc doc/reference_sfcgal.xml
index 9b61927f2,24a2a2fc7..eb7dbc62c
--- a/doc/reference_sfcgal.xml
+++ b/doc/reference_sfcgal.xml
@@@ -169,6 -169,182 +169,182 @@@ FROM data;</programlisting
  
          </refentry>
  
+         <refentry xml:id="CG_IsValid">
+             <refnamediv>
+                 <refname>CG_IsValid</refname>
+ 
+                 <refpurpose>Tests whether a geometry is valid according to SFCGAL</refpurpose>
+             </refnamediv>
+ 
+             <refsynopsisdiv>
+                 <funcsynopsis>
+                     <funcprototype>
+                         <funcdef>boolean <function>CG_IsValid</function></funcdef>
+                         <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+                     </funcprototype>
+                 </funcsynopsis>
+             </refsynopsisdiv>
+ 
+             <refsection>
+                 <title>Description</title>
+ 
+                 <para>Returns true if the input geometry is valid according to SFCGAL.</para>
+                 <para>This differs from <xref linkend="ST_IsValid"/>, which checks OGC validity through GEOS.</para>
+ 
 -                <para role="availability" conformance="3.7.0">Availability: 3.7.0</para>
++                <para role="availability" conformance="3.8.0">Availability: 3.8.0</para>
+                 <para>&sfcgal_required;</para>
+                 <para>&Z_support;</para>
+                 <para>&P_support;</para>
+                 <para>&T_support;</para>
+             </refsection>
+ 
+             <refsection>
+                 <title>Examples</title>
+ 
+                 <programlisting>SELECT CG_IsValid('LINESTRING Z (0 0 0,0 0 1)'::geometry);</programlisting>
+                 <screen>t</screen>
+             </refsection>
+ 
+             <refsection>
+                 <title>See Also</title>
+ 
+                 <para><xref linkend="CG_IsValidDetail"/>, <xref linkend="CG_IsSimple"/>, <xref linkend="ST_IsValid"/>, <xref linkend="CG_IsSolid"/></para>
+             </refsection>
+ 
+         </refentry>
+ 
+         <refentry xml:id="CG_IsValidDetail">
+             <refnamediv>
+                 <refname>CG_IsValidDetail</refname>
+ 
+                 <refpurpose>Returns a <varname>valid_detail</varname> row stating whether a geometry is valid according to SFCGAL, and if not a reason and a location.</refpurpose>
+             </refnamediv>
+ 
+             <refsynopsisdiv>
+                 <funcsynopsis>
+                     <funcprototype>
+                         <funcdef>valid_detail <function>CG_IsValidDetail</function></funcdef>
+                         <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+                     </funcprototype>
+                 </funcsynopsis>
+             </refsynopsisdiv>
+ 
+             <refsection>
+                 <title>Description</title>
+ 
+                 <para>Returns a <varname>valid_detail</varname> row with a boolean validity flag, a reason for invalidity, and the invalidity location when SFCGAL reports one.</para>
+                 <para>This differs from <xref linkend="ST_IsValidDetail"/>, which checks OGC validity through GEOS.</para>
+ 
 -                <para role="availability" conformance="3.7.0">Availability: 3.7.0</para>
++                <para role="availability" conformance="3.8.0">Availability: 3.8.0</para>
+                 <para>&sfcgal_required;</para>
+                 <para>&Z_support;</para>
+                 <para>&P_support;</para>
+                 <para>&T_support;</para>
+             </refsection>
+ 
+             <refsection>
+                 <title>Examples</title>
+ 
+                 <programlisting>SELECT valid, reason, ST_AsText(location) AS location
+ FROM CG_IsValidDetail('POLYGON((0 0,2 2,2 0,0 2,0 0))'::geometry);</programlisting>
+                 <screen>f | ring 0 self intersects |</screen>
+             </refsection>
+ 
+             <refsection>
+                 <title>See Also</title>
+ 
+                 <para><xref linkend="CG_IsValid"/>, <xref linkend="CG_IsSimpleDetail"/>, <xref linkend="ST_IsValidDetail"/></para>
+             </refsection>
+ 
+         </refentry>
+ 
+         <refentry xml:id="CG_IsSimple">
+             <refnamediv>
+                 <refname>CG_IsSimple</refname>
+ 
+                 <refpurpose>Tests whether a geometry is simple according to SFCGAL</refpurpose>
+             </refnamediv>
+ 
+             <refsynopsisdiv>
+                 <funcsynopsis>
+                     <funcprototype>
+                         <funcdef>boolean <function>CG_IsSimple</function></funcdef>
+                         <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+                     </funcprototype>
+                 </funcsynopsis>
+             </refsynopsisdiv>
+ 
+             <refsection>
+                 <title>Description</title>
+ 
+                 <para>Returns true if the input geometry is simple according to SFCGAL.</para>
+                 <para>This differs from <xref linkend="ST_IsSimple"/>, which checks simplicity through liblwgeom.</para>
+ 
 -                <para role="availability" conformance="3.7.0">Availability: 3.7.0 - requires SFCGAL >= 2.3.0.</para>
++                <para role="availability" conformance="3.8.0">Availability: 3.8.0 - requires SFCGAL >= 2.3.0.</para>
+                 <para>&sfcgal_required;</para>
+                 <para>&Z_support;</para>
+                 <para>&P_support;</para>
+                 <para>&T_support;</para>
+             </refsection>
+ 
+             <refsection>
+                 <title>Examples</title>
+ 
+                 <programlisting>SELECT CG_IsSimple('LINESTRING(0 0,2 2,2 0,0 2)'::geometry);</programlisting>
+                 <screen>f</screen>
+             </refsection>
+ 
+             <refsection>
+                 <title>See Also</title>
+ 
+                 <para><xref linkend="CG_IsSimpleDetail"/>, <xref linkend="CG_IsValid"/>, <xref linkend="ST_IsSimple"/></para>
+             </refsection>
+ 
+         </refentry>
+ 
+         <refentry xml:id="CG_IsSimpleDetail">
+             <refnamediv>
+                 <refname>CG_IsSimpleDetail</refname>
+ 
+                 <refpurpose>Returns a reason when a geometry is not simple according to SFCGAL</refpurpose>
+             </refnamediv>
+ 
+             <refsynopsisdiv>
+                 <funcsynopsis>
+                     <funcprototype>
+                         <funcdef>text <function>CG_IsSimpleDetail</function></funcdef>
+                         <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+                     </funcprototype>
+                 </funcsynopsis>
+             </refsynopsisdiv>
+ 
+             <refsection>
+                 <title>Description</title>
+ 
+                 <para>Returns SFCGAL's reason when the input geometry is not simple. Returns <varname>NULL</varname> for simple geometries.</para>
+ 
 -                <para role="availability" conformance="3.7.0">Availability: 3.7.0 - requires SFCGAL >= 2.3.0.</para>
++                <para role="availability" conformance="3.8.0">Availability: 3.8.0 - requires SFCGAL >= 2.3.0.</para>
+                 <para>&sfcgal_required;</para>
+                 <para>&Z_support;</para>
+                 <para>&P_support;</para>
+                 <para>&T_support;</para>
+             </refsection>
+ 
+             <refsection>
+                 <title>Examples</title>
+ 
+                 <programlisting>SELECT CG_IsSimpleDetail('LINESTRING(0 0,2 2,2 0,0 2)'::geometry);</programlisting>
+                 <screen>linestring self intersects</screen>
+             </refsection>
+ 
+             <refsection>
+                 <title>See Also</title>
+ 
+                 <para><xref linkend="CG_IsSimple"/>, <xref linkend="CG_IsValidDetail"/>, <xref linkend="ST_IsSimple"/></para>
+             </refsection>
+ 
+         </refentry>
+ 
          <refentry xml:id="CG_IsSolid">
              <refnamediv>
                  <refname>CG_IsSolid</refname>
diff --cc sfcgal/sfcgal.sql.in
index cfec2cefc,4fcabea06..d1e54f615
--- a/sfcgal/sfcgal.sql.in
+++ b/sfcgal/sfcgal.sql.in
@@@ -334,6 -334,36 +334,36 @@@ CREATE OR REPLACE FUNCTION CG_IsPlanar(
         LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
         COST 100;
  
 --- Availability: 3.7.0
++-- Availability: 3.8.0
+ CREATE OR REPLACE FUNCTION CG_IsValid(geometry)
+        RETURNS boolean
+        AS 'MODULE_PATHNAME','CG_IsValid'
+        LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+        COST 100;
+ 
 --- Availability: 3.7.0
++-- Availability: 3.8.0
+ CREATE OR REPLACE FUNCTION CG_IsValidDetail(geometry)
+        RETURNS valid_detail
+        AS 'MODULE_PATHNAME','CG_IsValidDetail'
+        LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+        COST 100;
+ 
 --- Availability: 3.7.0 - requires SFCGAL >= 2.3.0
++-- Availability: 3.8.0 - requires SFCGAL >= 2.3.0
+ #if POSTGIS_SFCGAL_VERSION >= 20300
+ CREATE OR REPLACE FUNCTION CG_IsSimple(geometry)
+        RETURNS boolean
+        AS 'MODULE_PATHNAME','CG_IsSimple'
+        LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+        COST 100;
+ 
 --- Availability: 3.7.0 - requires SFCGAL >= 2.3.0
++-- Availability: 3.8.0 - requires SFCGAL >= 2.3.0
+ CREATE OR REPLACE FUNCTION CG_IsSimpleDetail(geometry)
+        RETURNS text
+        AS 'MODULE_PATHNAME','CG_IsSimpleDetail'
+        LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+        COST 100;
+ #endif
+ 
  -- Availability: 2.2.0
  -- Deprecation in 3.5.0
  CREATE OR REPLACE FUNCTION ST_IsPlanar(geometry)

commit 8068073a3fc6455cbc2a98a1fee31efcd935c592
Author: Darafei Praliaskouski <me at komzpa.net>
Date:   Sun Jul 26 21:39:12 2026 +0400

    Move NEWS entries to 3.7.0rc1

diff --git a/NEWS b/NEWS
index f6c9590ea..3cd3e2220 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,10 @@ These are only changes since 3.7.0beta1.
 
  - Add Woodpecker linux/arm64 build and regression coverage under
           QEMU to match the Jenkins Berrie64 platform (Darafei Praliaskouski)
+ - #4363, [sfcgal] Add CG_IsValid, CG_IsValidDetail, and SFCGAL 2.3+
+          CG_IsSimple and CG_IsSimpleDetail checks
+          (Darafei Praliaskouski)
+
 
 PostGIS 3.7.0beta1
 2026/07/20
@@ -91,11 +95,6 @@ These are only changes since 3.7.0alpha1.
 * Enhancements *
 * New Features *
 
- - #4363, [sfcgal] Add CG_IsValid, CG_IsValidDetail, and SFCGAL 2.3+
-          CG_IsSimple and CG_IsSimpleDetail checks
-          (Darafei Praliaskouski)
-
-
  - #1986, ST_GeomFromGML support for GML ArcString and curved polygon rings
           (Darafei Praliaskouski)
 

commit c6aa14f35f2dfc5731c2375ba077937fc90f6fe0
Author: Darafei Praliaskouski <me at komzpa.net>
Date:   Sat Jul 18 19:43:54 2026 +0400

    doc: separate example output from SQL

diff --git a/doc/reference_sfcgal.xml b/doc/reference_sfcgal.xml
index 85519f200..24a2a2fc7 100644
--- a/doc/reference_sfcgal.xml
+++ b/doc/reference_sfcgal.xml
@@ -201,10 +201,8 @@ FROM data;</programlisting>
             <refsection>
                 <title>Examples</title>
 
-                <programlisting>SELECT CG_IsValid('LINESTRING Z (0 0 0,0 0 1)'::geometry);
- cg_isvalid
---------------
- t</programlisting>
+                <programlisting>SELECT CG_IsValid('LINESTRING Z (0 0 0,0 0 1)'::geometry);</programlisting>
+                <screen>t</screen>
             </refsection>
 
             <refsection>
@@ -248,10 +246,8 @@ FROM data;</programlisting>
                 <title>Examples</title>
 
                 <programlisting>SELECT valid, reason, ST_AsText(location) AS location
-FROM CG_IsValidDetail('POLYGON((0 0,2 2,2 0,0 2,0 0))'::geometry);
- valid |         reason         | location
--------+------------------------+----------
- f     | ring 0 self intersects |</programlisting>
+FROM CG_IsValidDetail('POLYGON((0 0,2 2,2 0,0 2,0 0))'::geometry);</programlisting>
+                <screen>f | ring 0 self intersects |</screen>
             </refsection>
 
             <refsection>
@@ -294,10 +290,8 @@ FROM CG_IsValidDetail('POLYGON((0 0,2 2,2 0,0 2,0 0))'::geometry);
             <refsection>
                 <title>Examples</title>
 
-                <programlisting>SELECT CG_IsSimple('LINESTRING(0 0,2 2,2 0,0 2)'::geometry);
- cg_issimple
--------------
- f</programlisting>
+                <programlisting>SELECT CG_IsSimple('LINESTRING(0 0,2 2,2 0,0 2)'::geometry);</programlisting>
+                <screen>f</screen>
             </refsection>
 
             <refsection>
@@ -339,10 +333,8 @@ FROM CG_IsValidDetail('POLYGON((0 0,2 2,2 0,0 2,0 0))'::geometry);
             <refsection>
                 <title>Examples</title>
 
-                <programlisting>SELECT CG_IsSimpleDetail('LINESTRING(0 0,2 2,2 0,0 2)'::geometry);
-     cg_issimpledetail
----------------------------
- linestring self intersects</programlisting>
+                <programlisting>SELECT CG_IsSimpleDetail('LINESTRING(0 0,2 2,2 0,0 2)'::geometry);</programlisting>
+                <screen>linestring self intersects</screen>
             </refsection>
 
             <refsection>

commit 346c6bef644a4e6f4a682d674aad985f36dab631
Author: Darafei Praliaskouski <me at komzpa.net>
Date:   Mon Jul 6 17:46:51 2026 +0400

    NEWS: move entry to 3.7.0beta1
    
    Closes #4363

diff --git a/NEWS b/NEWS
index 2c89075ec..f6c9590ea 100644
--- a/NEWS
+++ b/NEWS
@@ -89,6 +89,12 @@ These are only changes since 3.7.0alpha1.
             (Bas Couwenberg)
 
 * Enhancements *
+* New Features *
+
+ - #4363, [sfcgal] Add CG_IsValid, CG_IsValidDetail, and SFCGAL 2.3+
+          CG_IsSimple and CG_IsSimpleDetail checks
+          (Darafei Praliaskouski)
+
 
  - #1986, ST_GeomFromGML support for GML ArcString and curved polygon rings
           (Darafei Praliaskouski)
@@ -162,9 +168,6 @@ To take advantage of all postgis_sfcgal extension features SFCGAL 2.3+ is needed
  - GH-839, ST_Multi support for TIN and surfaces (Loïc Bartoletti)
  - #4398, Add ST_CatmullSmoothing smoothes but retains original vertices (Paul Ramsey)
  - #4560, ST_3DInterpolatePoint for M interpolation from XYZ inputs (Paul Ramsey)
- - #4363, [sfcgal] Add CG_IsValid, CG_IsValidDetail, and SFCGAL 2.3+
-          CG_IsSimple and CG_IsSimpleDetail checks
-          (Darafei Praliaskouski)
  - #1291, ST_MakePolygon support for curved rings (Darafei Praliaskouski)
  - GT-270, Add NURBSCurve (Loïc Bartoletti)
  - #2863, Add ST_XSize, ST_YSize, ST_ZSize, and ST_MSize dimension helpers

commit 51a9c367f5670bcd1e927ee735114be4bd8d5bc2
Author: Darafei Praliaskouski <me at komzpa.net>
Date:   Sun Jun 21 00:18:07 2026 +0400

    Add SFCGAL validity predicate
    
    Expose SFCGAL validity checks as CG_IsValid, backed by sfcgal_geometry_is_valid.
    
    Avoid adding an ST_3DIsValid alias only to deprecate it, since the SFCGAL predicate applies to both 2D and 3D inputs.
    
    Closes #4363

diff --git a/NEWS b/NEWS
index 1443dee89..2c89075ec 100644
--- a/NEWS
+++ b/NEWS
@@ -162,6 +162,9 @@ To take advantage of all postgis_sfcgal extension features SFCGAL 2.3+ is needed
  - GH-839, ST_Multi support for TIN and surfaces (Loïc Bartoletti)
  - #4398, Add ST_CatmullSmoothing smoothes but retains original vertices (Paul Ramsey)
  - #4560, ST_3DInterpolatePoint for M interpolation from XYZ inputs (Paul Ramsey)
+ - #4363, [sfcgal] Add CG_IsValid, CG_IsValidDetail, and SFCGAL 2.3+
+          CG_IsSimple and CG_IsSimpleDetail checks
+          (Darafei Praliaskouski)
  - #1291, ST_MakePolygon support for curved rings (Darafei Praliaskouski)
  - GT-270, Add NURBSCurve (Loïc Bartoletti)
  - #2863, Add ST_XSize, ST_YSize, ST_ZSize, and ST_MSize dimension helpers
diff --git a/doc/Makefile.in b/doc/Makefile.in
index 7353f9a51..ad5ad80c2 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -43,6 +43,7 @@ htmldir = @htmldir@
 POSTGIS_MAJOR_VERSION=@POSTGIS_MAJOR_VERSION@
 POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@
 POSTGIS_MICRO_VERSION=@POSTGIS_MICRO_VERSION@
+POSTGIS_SFCGAL_VERSION=@POSTGIS_SFCGAL_VERSION@
 
 DOCSUFFIX=-en
 
@@ -93,6 +94,9 @@ XSLTPROC_CUSTOM_VARS = \
 	--stringparam postgis_version $(POSTGIS_MAJOR_VERSION).$(POSTGIS_MINOR_VERSION) \
 	--stringparam postgis_language $(patsubst -%,%,$(DOCSUFFIX))/
 
+XSLTPROC_COMMENT_VARS = \
+	--stringparam postgis_sfcgal_version $(POSTGIS_SFCGAL_VERSION)
+
 XSLTPROC_COMMONOPTS= \
 	$(XSLTPROC_PATH_OPT) \
 	--param section.autolabel 1 \
@@ -432,7 +436,7 @@ $(TAG_GENERATED_SOURCES): xsl/node_by_xpath.xsl xsl-config.xml | Makefile
 endif
 
 $(GENERATED_COMMENT_FILES): %.sql: xsl/%.sql.xsl postgis-out.xml xsl/common_utils.xsl xsl/common_comments.xsl
-	$(XSLTPROC) --novalid $(XSLTPROCFLAGS) $(XSLTPROC_PATH_OPT) -o $@ $< postgis-out.xml
+	$(XSLTPROC) --novalid $(XSLTPROCFLAGS) $(XSLTPROC_PATH_OPT) $(XSLTPROC_COMMENT_VARS) -o $@ $< postgis-out.xml
 
 $(GENERATED_CHEATSHEET_FILES): $(html_builddir)/%$(DOCSUFFIX).html: xsl/%.html.xsl postgis-out.xml xsl/common_cheatsheet.xsl xsl/common_utils.xsl
 	$(XSLTPROC) --novalid $(XSLTPROCFLAGS) $(XSLTPROC_PATH_OPT) $(XSLTPROC_CUSTOM_VARS) -o $@ $< postgis-out.xml
diff --git a/doc/reference_sfcgal.xml b/doc/reference_sfcgal.xml
index 9b61927f2..85519f200 100644
--- a/doc/reference_sfcgal.xml
+++ b/doc/reference_sfcgal.xml
@@ -169,6 +169,190 @@ FROM data;</programlisting>
 
         </refentry>
 
+        <refentry xml:id="CG_IsValid">
+            <refnamediv>
+                <refname>CG_IsValid</refname>
+
+                <refpurpose>Tests whether a geometry is valid according to SFCGAL</refpurpose>
+            </refnamediv>
+
+            <refsynopsisdiv>
+                <funcsynopsis>
+                    <funcprototype>
+                        <funcdef>boolean <function>CG_IsValid</function></funcdef>
+                        <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+                    </funcprototype>
+                </funcsynopsis>
+            </refsynopsisdiv>
+
+            <refsection>
+                <title>Description</title>
+
+                <para>Returns true if the input geometry is valid according to SFCGAL.</para>
+                <para>This differs from <xref linkend="ST_IsValid"/>, which checks OGC validity through GEOS.</para>
+
+                <para role="availability" conformance="3.7.0">Availability: 3.7.0</para>
+                <para>&sfcgal_required;</para>
+                <para>&Z_support;</para>
+                <para>&P_support;</para>
+                <para>&T_support;</para>
+            </refsection>
+
+            <refsection>
+                <title>Examples</title>
+
+                <programlisting>SELECT CG_IsValid('LINESTRING Z (0 0 0,0 0 1)'::geometry);
+ cg_isvalid
+--------------
+ t</programlisting>
+            </refsection>
+
+            <refsection>
+                <title>See Also</title>
+
+                <para><xref linkend="CG_IsValidDetail"/>, <xref linkend="CG_IsSimple"/>, <xref linkend="ST_IsValid"/>, <xref linkend="CG_IsSolid"/></para>
+            </refsection>
+
+        </refentry>
+
+        <refentry xml:id="CG_IsValidDetail">
+            <refnamediv>
+                <refname>CG_IsValidDetail</refname>
+
+                <refpurpose>Returns a <varname>valid_detail</varname> row stating whether a geometry is valid according to SFCGAL, and if not a reason and a location.</refpurpose>
+            </refnamediv>
+
+            <refsynopsisdiv>
+                <funcsynopsis>
+                    <funcprototype>
+                        <funcdef>valid_detail <function>CG_IsValidDetail</function></funcdef>
+                        <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+                    </funcprototype>
+                </funcsynopsis>
+            </refsynopsisdiv>
+
+            <refsection>
+                <title>Description</title>
+
+                <para>Returns a <varname>valid_detail</varname> row with a boolean validity flag, a reason for invalidity, and the invalidity location when SFCGAL reports one.</para>
+                <para>This differs from <xref linkend="ST_IsValidDetail"/>, which checks OGC validity through GEOS.</para>
+
+                <para role="availability" conformance="3.7.0">Availability: 3.7.0</para>
+                <para>&sfcgal_required;</para>
+                <para>&Z_support;</para>
+                <para>&P_support;</para>
+                <para>&T_support;</para>
+            </refsection>
+
+            <refsection>
+                <title>Examples</title>
+
+                <programlisting>SELECT valid, reason, ST_AsText(location) AS location
+FROM CG_IsValidDetail('POLYGON((0 0,2 2,2 0,0 2,0 0))'::geometry);
+ valid |         reason         | location
+-------+------------------------+----------
+ f     | ring 0 self intersects |</programlisting>
+            </refsection>
+
+            <refsection>
+                <title>See Also</title>
+
+                <para><xref linkend="CG_IsValid"/>, <xref linkend="CG_IsSimpleDetail"/>, <xref linkend="ST_IsValidDetail"/></para>
+            </refsection>
+
+        </refentry>
+
+        <refentry xml:id="CG_IsSimple">
+            <refnamediv>
+                <refname>CG_IsSimple</refname>
+
+                <refpurpose>Tests whether a geometry is simple according to SFCGAL</refpurpose>
+            </refnamediv>
+
+            <refsynopsisdiv>
+                <funcsynopsis>
+                    <funcprototype>
+                        <funcdef>boolean <function>CG_IsSimple</function></funcdef>
+                        <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+                    </funcprototype>
+                </funcsynopsis>
+            </refsynopsisdiv>
+
+            <refsection>
+                <title>Description</title>
+
+                <para>Returns true if the input geometry is simple according to SFCGAL.</para>
+                <para>This differs from <xref linkend="ST_IsSimple"/>, which checks simplicity through liblwgeom.</para>
+
+                <para role="availability" conformance="3.7.0">Availability: 3.7.0 - requires SFCGAL >= 2.3.0.</para>
+                <para>&sfcgal_required;</para>
+                <para>&Z_support;</para>
+                <para>&P_support;</para>
+                <para>&T_support;</para>
+            </refsection>
+
+            <refsection>
+                <title>Examples</title>
+
+                <programlisting>SELECT CG_IsSimple('LINESTRING(0 0,2 2,2 0,0 2)'::geometry);
+ cg_issimple
+-------------
+ f</programlisting>
+            </refsection>
+
+            <refsection>
+                <title>See Also</title>
+
+                <para><xref linkend="CG_IsSimpleDetail"/>, <xref linkend="CG_IsValid"/>, <xref linkend="ST_IsSimple"/></para>
+            </refsection>
+
+        </refentry>
+
+        <refentry xml:id="CG_IsSimpleDetail">
+            <refnamediv>
+                <refname>CG_IsSimpleDetail</refname>
+
+                <refpurpose>Returns a reason when a geometry is not simple according to SFCGAL</refpurpose>
+            </refnamediv>
+
+            <refsynopsisdiv>
+                <funcsynopsis>
+                    <funcprototype>
+                        <funcdef>text <function>CG_IsSimpleDetail</function></funcdef>
+                        <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+                    </funcprototype>
+                </funcsynopsis>
+            </refsynopsisdiv>
+
+            <refsection>
+                <title>Description</title>
+
+                <para>Returns SFCGAL's reason when the input geometry is not simple. Returns <varname>NULL</varname> for simple geometries.</para>
+
+                <para role="availability" conformance="3.7.0">Availability: 3.7.0 - requires SFCGAL >= 2.3.0.</para>
+                <para>&sfcgal_required;</para>
+                <para>&Z_support;</para>
+                <para>&P_support;</para>
+                <para>&T_support;</para>
+            </refsection>
+
+            <refsection>
+                <title>Examples</title>
+
+                <programlisting>SELECT CG_IsSimpleDetail('LINESTRING(0 0,2 2,2 0,0 2)'::geometry);
+     cg_issimpledetail
+---------------------------
+ linestring self intersects</programlisting>
+            </refsection>
+
+            <refsection>
+                <title>See Also</title>
+
+                <para><xref linkend="CG_IsSimple"/>, <xref linkend="CG_IsValidDetail"/>, <xref linkend="ST_IsSimple"/></para>
+            </refsection>
+
+        </refentry>
+
         <refentry xml:id="CG_IsSolid">
             <refnamediv>
                 <refname>CG_IsSolid</refname>
diff --git a/doc/xsl/sfcgal_comments.sql.xsl b/doc/xsl/sfcgal_comments.sql.xsl
index e7032a7ad..aedccafd6 100644
--- a/doc/xsl/sfcgal_comments.sql.xsl
+++ b/doc/xsl/sfcgal_comments.sql.xsl
@@ -2,6 +2,7 @@
 <xsl:stylesheet version="1.0"
 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 	xmlns:db="http://docbook.org/ns/docbook"
+	xmlns:xml="http://www.w3.org/XML/1998/namespace"
 >
 <!-- ********************************************************************
      ********************************************************************
@@ -15,6 +16,7 @@
 	<xsl:include href="common_comments.xsl" />
 
 	<xsl:output method="text" />
+	<xsl:param name="postgis_sfcgal_version">0</xsl:param>
 
 	<!-- We deal only with the reference chapter -->
         <xsl:template match="/">
@@ -26,6 +28,15 @@
 		<xsl:variable name="apesc"><xsl:text>''</xsl:text></xsl:variable>
 <!-- Pull out the purpose section for each ref entry and strip whitespace and put in a variable to be tagged unto each function comment  -->
 		<xsl:for-each select="db:section[not(contains(@xml:id,'Operator'))]/db:refentry">
+		  <!--
+		    CG_IsSimple and CG_IsSimpleDetail are not declared in sfcgal.sql
+		    when PostGIS is built against SFCGAL before 2.3.0, because the
+		    required SFCGAL C entry points do not exist there. Other documented
+		    SFCGAL 2.3 features keep SQL-visible stubs that raise a version
+		    error at execution time, so their COMMENT statements must remain.
+		  -->
+		  <xsl:variable name="skip-comment" select="number($postgis_sfcgal_version) < 20300 and (@xml:id='CG_IsSimple' or @xml:id='CG_IsSimpleDetail')" />
+		  <xsl:if test="not($skip-comment)">
 		  <xsl:variable name='plaincomment'>
 		  	<xsl:value-of select="normalize-space(translate(translate(db:refnamediv/db:refpurpose,'&#x0d;&#x0a;', ' '), '	', ' '))"/>
 		  </xsl:variable>
@@ -45,6 +56,7 @@ COMMENT ON <xsl:choose><xsl:when test="contains(db:paramdef/db:type,'geometry se
 <xsl:choose><xsl:when test="contains(db:parameter,'OUT')"></xsl:when><xsl:when test="contains(db:type,'geometry set')">geometry</xsl:when><xsl:otherwise><xsl:value-of select="db:type" /></xsl:otherwise></xsl:choose><xsl:if test="position()<last() and not(contains(db:parameter,'OUT')) and not(contains(following-sibling::paramdef[1],'OUT'))"><xsl:text>, </xsl:text></xsl:if></xsl:when>
 </xsl:choose></xsl:for-each>) IS '<xsl:call-template name="listparams"><xsl:with-param name="func" select="." /></xsl:call-template> <xsl:value-of select='$comment' />';
 			</xsl:for-each>
+		  </xsl:if>
 		</xsl:for-each>
 	</xsl:template>
 
diff --git a/postgis/uninstall_sfcgal.sql.in b/postgis/uninstall_sfcgal.sql.in
index 4ec220cc9..ebd6f037c 100644
--- a/postgis/uninstall_sfcgal.sql.in
+++ b/postgis/uninstall_sfcgal.sql.in
@@ -20,6 +20,11 @@ DROP FUNCTION IF EXISTS postgis_sfcgal_full_version();
 
 DROP FUNCTION IF EXISTS ST_3DIntersection(geom1 geometry, geom2 geometry);
 
+DROP FUNCTION IF EXISTS CG_IsValid(geometry);
+DROP FUNCTION IF EXISTS CG_IsValidDetail(geometry);
+DROP FUNCTION IF EXISTS CG_IsSimple(geometry);
+DROP FUNCTION IF EXISTS CG_IsSimpleDetail(geometry);
+
 DROP FUNCTION IF EXISTS ST_Tesselate(geometry);
 
 DROP FUNCTION IF EXISTS ST_3DArea(geometry);
diff --git a/sfcgal/lwgeom_sfcgal.c b/sfcgal/lwgeom_sfcgal.c
index 11a581e7d..10befc825 100644
--- a/sfcgal/lwgeom_sfcgal.c
+++ b/sfcgal/lwgeom_sfcgal.c
@@ -26,7 +26,9 @@
 #include "SFCGAL/capi/sfcgal_c.h"
 
 #include "postgres.h"
+#include "access/htup_details.h"
 #include "fmgr.h"
+#include "funcapi.h"
 #include "libpq/pqsignal.h"
 #include "utils/builtins.h"
 #include "utils/elog.h"
@@ -73,6 +75,12 @@ Datum sfcgal_volume(PG_FUNCTION_ARGS);
 Datum sfcgal_extrude(PG_FUNCTION_ARGS);
 Datum sfcgal_straight_skeleton(PG_FUNCTION_ARGS);
 Datum sfcgal_approximate_medial_axis(PG_FUNCTION_ARGS);
+Datum CG_IsValid(PG_FUNCTION_ARGS);
+Datum CG_IsValidDetail(PG_FUNCTION_ARGS);
+#if POSTGIS_SFCGAL_VERSION >= 20300
+Datum CG_IsSimple(PG_FUNCTION_ARGS);
+Datum CG_IsSimpleDetail(PG_FUNCTION_ARGS);
+#endif
 Datum sfcgal_is_planar(PG_FUNCTION_ARGS);
 Datum sfcgal_orientation(PG_FUNCTION_ARGS);
 Datum sfcgal_force_lhr(PG_FUNCTION_ARGS);
@@ -276,6 +284,147 @@ sfcgal_is_planar(PG_FUNCTION_ARGS)
 	PG_RETURN_BOOL(result);
 }
 
+PG_FUNCTION_INFO_V1(CG_IsValid);
+Datum
+CG_IsValid(PG_FUNCTION_ARGS)
+{
+	GSERIALIZED *input;
+	sfcgal_geometry_t *geom;
+	int result;
+
+	sfcgal_postgis_init();
+
+	input = PG_GETARG_GSERIALIZED_P(0);
+	geom = POSTGIS2SFCGALGeometry(input);
+
+	result = sfcgal_geometry_is_valid(geom);
+	sfcgal_geometry_delete(geom);
+
+	PG_FREE_IF_COPY(input, 0);
+
+	PG_RETURN_BOOL(result);
+}
+
+static void
+sfcgal_detail_reason_free(char *reason)
+{
+	/*
+	 * SFCGAL's detail APIs return reason strings allocated by the C++
+	 * validity/simplicity layer, not by the C API buffer helper. Releasing
+	 * these with lwfree() or sfcgal_free_buffer() corrupts memory with
+	 * SFCGAL 2.3, even after sfcgal_set_alloc_handlers().
+	 */
+	free(reason);
+}
+
+PG_FUNCTION_INFO_V1(CG_IsValidDetail);
+Datum
+CG_IsValidDetail(PG_FUNCTION_ARGS)
+{
+	GSERIALIZED *input;
+	GSERIALIZED *location = NULL;
+	sfcgal_geometry_t *geom;
+	sfcgal_geometry_t *invalidity_location = NULL;
+	char *invalidity_reason = NULL;
+	Datum values[3];
+	bool nulls[3] = {false, true, true};
+	int result;
+	HeapTuple tuple;
+	TupleDesc tupdesc;
+
+	sfcgal_postgis_init();
+
+	input = PG_GETARG_GSERIALIZED_P(0);
+	geom = POSTGIS2SFCGALGeometry(input);
+
+	result = sfcgal_geometry_is_valid_detail(geom, &invalidity_reason, &invalidity_location);
+	sfcgal_geometry_delete(geom);
+
+	if (invalidity_reason)
+	{
+		values[1] = CStringGetTextDatum(invalidity_reason);
+		nulls[1] = false;
+		sfcgal_detail_reason_free(invalidity_reason);
+	}
+
+	if (invalidity_location)
+	{
+		location = SFCGALGeometry2POSTGIS(
+		    invalidity_location, FLAGS_GET_Z(input->gflags), gserialized_get_srid(input));
+		sfcgal_geometry_delete(invalidity_location);
+		values[2] = PointerGetDatum(location);
+		nulls[2] = false;
+	}
+
+	PG_FREE_IF_COPY(input, 0);
+
+	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
+		ereport(ERROR,
+			(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+			 errmsg("function returning record called in context that cannot accept type record")));
+	BlessTupleDesc(tupdesc);
+
+	values[0] = BoolGetDatum(result);
+	tuple = heap_form_tuple(tupdesc, values, nulls);
+
+	PG_RETURN_DATUM(HeapTupleGetDatum(tuple));
+}
+
+#if POSTGIS_SFCGAL_VERSION >= 20300
+PG_FUNCTION_INFO_V1(CG_IsSimple);
+Datum
+CG_IsSimple(PG_FUNCTION_ARGS)
+{
+	GSERIALIZED *input;
+	sfcgal_geometry_t *geom;
+	int result;
+
+	sfcgal_postgis_init();
+
+	input = PG_GETARG_GSERIALIZED_P(0);
+	geom = POSTGIS2SFCGALGeometry(input);
+
+	result = sfcgal_geometry_is_simple(geom);
+	sfcgal_geometry_delete(geom);
+
+	PG_FREE_IF_COPY(input, 0);
+
+	PG_RETURN_BOOL(result);
+}
+
+PG_FUNCTION_INFO_V1(CG_IsSimpleDetail);
+Datum
+CG_IsSimpleDetail(PG_FUNCTION_ARGS)
+{
+	GSERIALIZED *input;
+	sfcgal_geometry_t *geom;
+	char *complexity_reason = NULL;
+	int result;
+	text *text_result;
+
+	sfcgal_postgis_init();
+
+	input = PG_GETARG_GSERIALIZED_P(0);
+	geom = POSTGIS2SFCGALGeometry(input);
+
+	result = sfcgal_geometry_is_simple_detail(geom, &complexity_reason);
+	sfcgal_geometry_delete(geom);
+
+	PG_FREE_IF_COPY(input, 0);
+
+	if (result || !complexity_reason)
+	{
+		if (complexity_reason)
+			sfcgal_detail_reason_free(complexity_reason);
+		PG_RETURN_NULL();
+	}
+
+	text_result = cstring_to_text(complexity_reason);
+	sfcgal_detail_reason_free(complexity_reason);
+	PG_RETURN_TEXT_P(text_result);
+}
+#endif
+
 PG_FUNCTION_INFO_V1(sfcgal_orientation);
 Datum
 sfcgal_orientation(PG_FUNCTION_ARGS)
diff --git a/sfcgal/regress/is_simple.sql b/sfcgal/regress/is_simple.sql
new file mode 100644
index 000000000..1ac3860c4
--- /dev/null
+++ b/sfcgal/regress/is_simple.sql
@@ -0,0 +1,4 @@
+SELECT 'CG_IsSimple.simple_line', CG_IsSimple('LINESTRING(0 0,1 1)');
+SELECT 'CG_IsSimple.crossing_line', CG_IsSimple('LINESTRING(0 0,2 2,2 0,0 2)');
+SELECT 'CG_IsSimpleDetail.simple_line', CG_IsSimpleDetail('LINESTRING(0 0,1 1)') IS NULL;
+SELECT 'CG_IsSimpleDetail.crossing_line', CG_IsSimpleDetail('LINESTRING(0 0,2 2,2 0,0 2)') IS NOT NULL;
diff --git a/sfcgal/regress/is_simple_expected b/sfcgal/regress/is_simple_expected
new file mode 100644
index 000000000..3c2d7b407
--- /dev/null
+++ b/sfcgal/regress/is_simple_expected
@@ -0,0 +1,4 @@
+CG_IsSimple.simple_line|t
+CG_IsSimple.crossing_line|f
+CG_IsSimpleDetail.simple_line|t
+CG_IsSimpleDetail.crossing_line|t
diff --git a/sfcgal/regress/regress_sfcgal.sql b/sfcgal/regress/regress_sfcgal.sql
index bc9e61a11..e32ae4ed5 100644
--- a/sfcgal/regress/regress_sfcgal.sql
+++ b/sfcgal/regress/regress_sfcgal.sql
@@ -9,6 +9,13 @@ SELECT 'postgis_sfcgal_version', count(*) FROM (SELECT postgis_sfcgal_version())
 SELECT 'postgis_sfcgal_noop', ST_NPoints(postgis_sfcgal_noop(ST_Buffer('POINT(0 0)', 5)));
 SELECT 'CG_Tesselate', ST_AsText(CG_Tesselate('GEOMETRYCOLLECTION(POINT(4 4),POLYGON((0 0,1 0,1 1,0 1,0 0)))'));
 SELECT 'CG_3DArea', CG_3DArea('POLYGON((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0))');
+SELECT 'CG_IsValid.2d_polygon', CG_IsValid('POLYGON((0 0,1 0,1 1,0 0))');
+SELECT 'CG_IsValid.invalid_polygon', CG_IsValid('POLYGON((0 0,2 2,2 0,0 2,0 0))');
+SELECT 'CG_IsValid.3d_vertical_line', CG_IsValid('LINESTRING Z (0 0 0,0 0 1)');
+SELECT 'CG_IsValid.polyhedralsurface', CG_IsValid('POLYHEDRALSURFACE Z (((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))');
+SELECT 'CG_IsValid.solid', CG_IsValid(CG_MakeSolid('POLYHEDRALSURFACE Z (((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))'));
+SELECT 'CG_IsValidDetail.valid_polygon', valid, reason IS NULL, location IS NULL FROM CG_IsValidDetail('POLYGON((0 0,1 0,1 1,0 0))');
+SELECT 'CG_IsValidDetail.invalid_polygon', valid, reason IS NOT NULL, location IS NULL FROM CG_IsValidDetail('POLYGON((0 0,2 2,2 0,0 2,0 0))');
 SELECT 'CG_Extrude_point', ST_AsText(CG_Extrude('POINT(0 0)', 1, 0, 0));
 SELECT 'CG_Extrude_line', ST_AsText(CG_Extrude(CG_Extrude('POINT(0 0)', 1, 0, 0), 0, 1, 0));
 -- In the first SFCGAL versions, the extruded face was wrongly oriented
diff --git a/sfcgal/regress/regress_sfcgal_expected b/sfcgal/regress/regress_sfcgal_expected
index ea9616bb2..4ad54a8f0 100644
--- a/sfcgal/regress/regress_sfcgal_expected
+++ b/sfcgal/regress/regress_sfcgal_expected
@@ -2,6 +2,13 @@ postgis_sfcgal_version|1
 postgis_sfcgal_noop|33
 CG_Tesselate|GEOMETRYCOLLECTION(POINT(4 4),TIN(((0 1,1 0,1 1,0 1)),((0 1,0 0,1 0,0 1))))
 CG_3DArea|1
+CG_IsValid.2d_polygon|t
+CG_IsValid.invalid_polygon|f
+CG_IsValid.3d_vertical_line|t
+CG_IsValid.polyhedralsurface|t
+CG_IsValid.solid|t
+CG_IsValidDetail.valid_polygon|t|t|t
+CG_IsValidDetail.invalid_polygon|f|t|t
 CG_Extrude_point|LINESTRING Z (0 0 0,1 0 0)
 CG_Extrude_line|POLYHEDRALSURFACE Z (((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)))
 CG_Extrude_surface|POLYHEDRALSURFACE Z (((1 1 0,1 0 0,0 1 0,1 1 0)),((0 1 1,1 0 1,1 1 1,0 1 1)),((1 0 0,0 0 0,0 1 0,1 0 0)),((0 1 1,0 0 1,1 0 1,0 1 1)),((1 0 0,1 1 0,1 1 1,1 0 1,1 0 0)),((1 1 0,0 1 0,0 1 1,1 1 1,1 1 0)),((0 1 0,0 0 0,0 0 1,0 1 1,0 1 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)))
diff --git a/sfcgal/regress/tests.mk.in b/sfcgal/regress/tests.mk.in
index c1c39d069..dbffae324 100644
--- a/sfcgal/regress/tests.mk.in
+++ b/sfcgal/regress/tests.mk.in
@@ -50,6 +50,7 @@ ifeq ($(shell expr "$(POSTGIS_SFCGAL_VERSION)" ">=" 20300),1)
 		$(top_srcdir)/sfcgal/regress/alphashape_components.sql \
 		$(top_srcdir)/sfcgal/regress/roofgeneration.sql \
 		$(top_srcdir)/sfcgal/regress/approximatemedialaxis_projected.sql \
+		$(top_srcdir)/sfcgal/regress/is_simple.sql \
 		$(top_srcdir)/sfcgal/regress/nurbs.sql
 	ifeq ($(shell expr "$(POSTGIS_CGAL_VERSION)" ">=" 600),1)
 		TESTS += $(top_srcdir)/sfcgal/regress/polygonrepair.sql
diff --git a/sfcgal/sfcgal.sql.in b/sfcgal/sfcgal.sql.in
index cfec2cefc..4fcabea06 100644
--- a/sfcgal/sfcgal.sql.in
+++ b/sfcgal/sfcgal.sql.in
@@ -334,6 +334,36 @@ CREATE OR REPLACE FUNCTION CG_IsPlanar(geometry)
        LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
        COST 100;
 
+-- Availability: 3.7.0
+CREATE OR REPLACE FUNCTION CG_IsValid(geometry)
+       RETURNS boolean
+       AS 'MODULE_PATHNAME','CG_IsValid'
+       LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+       COST 100;
+
+-- Availability: 3.7.0
+CREATE OR REPLACE FUNCTION CG_IsValidDetail(geometry)
+       RETURNS valid_detail
+       AS 'MODULE_PATHNAME','CG_IsValidDetail'
+       LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+       COST 100;
+
+-- Availability: 3.7.0 - requires SFCGAL >= 2.3.0
+#if POSTGIS_SFCGAL_VERSION >= 20300
+CREATE OR REPLACE FUNCTION CG_IsSimple(geometry)
+       RETURNS boolean
+       AS 'MODULE_PATHNAME','CG_IsSimple'
+       LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+       COST 100;
+
+-- Availability: 3.7.0 - requires SFCGAL >= 2.3.0
+CREATE OR REPLACE FUNCTION CG_IsSimpleDetail(geometry)
+       RETURNS text
+       AS 'MODULE_PATHNAME','CG_IsSimpleDetail'
+       LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+       COST 100;
+#endif
+
 -- Availability: 2.2.0
 -- Deprecation in 3.5.0
 CREATE OR REPLACE FUNCTION ST_IsPlanar(geometry)

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                   |   6 ++
 doc/Makefile.in                        |   6 +-
 doc/reference_sfcgal.xml               | 176 +++++++++++++++++++++++++++++++++
 doc/xsl/sfcgal_comments.sql.xsl        |  12 +++
 postgis/uninstall_sfcgal.sql.in        |   5 +
 sfcgal/lwgeom_sfcgal.c                 | 149 ++++++++++++++++++++++++++++
 sfcgal/regress/is_simple.sql           |   4 +
 sfcgal/regress/is_simple_expected      |   4 +
 sfcgal/regress/regress_sfcgal.sql      |   7 ++
 sfcgal/regress/regress_sfcgal_expected |   7 ++
 sfcgal/regress/tests.mk.in             |   1 +
 sfcgal/sfcgal.sql.in                   |  30 ++++++
 12 files changed, 406 insertions(+), 1 deletion(-)
 create mode 100644 sfcgal/regress/is_simple.sql
 create mode 100644 sfcgal/regress/is_simple_expected


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list