[SCM] PostGIS branch master updated. 3.5.0-322-gcc5ee17a9
git at osgeo.org
git at osgeo.org
Wed May 14 23:59:46 PDT 2025
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 cc5ee17a97e79b21ee5eea708127ef76a1173d63 (commit)
via f5a77f6ad3490d22e146e69965b6439e9fbfc2ca (commit)
via e3ad7eb306dddff0cf7b0c824654ba9dcb90724d (commit)
from a783dca52b99ebe976216ed6f37d7992ec300528 (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 cc5ee17a97e79b21ee5eea708127ef76a1173d63
Author: Loïc Bartoletti <loic.bartoletti at oslandia.com>
Date: Thu May 15 08:44:37 2025 +0200
docs(NEWS): SFCGAL: Add CG_Simplify
diff --git a/NEWS b/NEWS
index 2f80800e7..59f1f0c57 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ PostGIS 3.6.0
* New Features *
+ - GH-803, ADD CG_Simplify function (Loïc Bartoletti)
- GH-805, Add M support for SFCGAL >= 1.5.0 (Loïc Bartoletti)
- #5894, TotalTopologySize (Sandro Santilli)
- #5890, ValidateTopologyPrecision, MakeTopologyPrecise (Sandro Santilli)
commit f5a77f6ad3490d22e146e69965b6439e9fbfc2ca
Author: Loïc Bartoletti <loic.bartoletti at oslandia.com>
Date: Wed May 14 07:26:23 2025 +0200
docs(CG_Simplify): Add CG_Simplify documentation and examples
diff --git a/doc/html/images/Makefile.in b/doc/html/images/Makefile.in
index 1d638b7b0..f97fc278a 100644
--- a/doc/html/images/Makefile.in
+++ b/doc/html/images/Makefile.in
@@ -47,6 +47,9 @@ GENERATED_IMAGES= \
cg_ymonotonepartition01.png \
cg_ymonotonepartition02.png \
cg_straightskeletonpartition01.png \
+ cg_simplify00.png \
+ cg_simplify01.png \
+ cg_simplify02.png \
de9im01.png \
de9im02.png \
st_alphashape01.png \
diff --git a/doc/html/images/wkt/cg_simplify00.wkt b/doc/html/images/wkt/cg_simplify00.wkt
new file mode 100644
index 000000000..8d370893c
--- /dev/null
+++ b/doc/html/images/wkt/cg_simplify00.wkt
@@ -0,0 +1 @@
+ArgA;GEOMETRYCOLLECTION(POLYGON((88.46 158.85,90.77 171.54,147.31 173.85,146.15 145,173.85 119.62,146.15 103.46,112.69 118.46,91.92 93.08,65.38 101.15,34.23 121.92,41.15 142.69,49.23 143.85,88.46 158.85)),POLYGON((112.69 118.46,146.15 103.46,190 60.77,185.38 43.46,126.54 26.15,83.85 28.46,67.69 64.23,43.46 58.46,10 83.85,34.23 121.92,65.38 101.15,91.92 93.08,112.69 118.46)))
diff --git a/doc/html/images/wkt/cg_simplify01.wkt b/doc/html/images/wkt/cg_simplify01.wkt
new file mode 100644
index 000000000..e4a1d0e79
--- /dev/null
+++ b/doc/html/images/wkt/cg_simplify01.wkt
@@ -0,0 +1,2 @@
+Result;POLYGON((88.46 158.85,147.31 173.85,146.15 103.46,112.69 118.46,34.23 121.92,88.46 158.85))
+Result;POLYGON((112.69 118.46,146.15 103.46,185.38 43.46,10 83.85,34.23 121.92,112.69 118.46))
diff --git a/doc/html/images/wkt/cg_simplify02.wkt b/doc/html/images/wkt/cg_simplify02.wkt
new file mode 100644
index 000000000..6f1bc7a2c
--- /dev/null
+++ b/doc/html/images/wkt/cg_simplify02.wkt
@@ -0,0 +1,2 @@
+Result;POLYGON((88.46 158.85,173.85 119.62,34.23 121.92,88.46 158.85))
+Result;POLYGON((112.69 118.46,190 60.77,10 83.85,112.69 118.46))
diff --git a/doc/reference_sfcgal.xml b/doc/reference_sfcgal.xml
index 375344fe6..547788885 100644
--- a/doc/reference_sfcgal.xml
+++ b/doc/reference_sfcgal.xml
@@ -3122,7 +3122,7 @@ ERROR: straight skeleton of Polygon with point touching rings is not implemente
<programlisting><![CDATA[SELECT string_agg('<Shape>' || ST_AsX3D(cgbuffer3d_output) || '<Appearance>
<Material diffuseColor="0 0.8 0.2" specularColor="0 1 0"/>
</Appearance>
- </Shape>', '');]]></programlisting>
+ </Shape>', '');]]></programlisting>
<informaltable>
<tgroup cols="2">
<tbody>
@@ -3568,5 +3568,152 @@ ERROR: straight skeleton of Polygon with point touching rings is not implemente
</refsection>
</refentry>
+<refentry xml:id="CG_Simplify">
+ <refnamediv>
+ <refname>CG_Simplify</refname>
+ <refpurpose>Reduces the complexity of a geometry while preserving essential features and Z/M values.</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>geometry <function>CG_Simplify</function></funcdef>
+ <paramdef><type>geometry</type> <parameter>geom</parameter></paramdef>
+ <paramdef><type>double precision</type> <parameter>threshold</parameter></paramdef>
+ <paramdef choice="opt"><type>boolean</type> <parameter>preserveTopology = false</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+ <para>
+ Simplifies a geometry using SFCGAL's simplification algorithm, which reduces the number of points or vertices while preserving the essential features of the geometry. This function preserves Z and M values during simplification.
+ </para>
+ <para>
+ The algorithm is based on constrained triangulation and uses the <link xlink:href="https://doc.cgal.org/latest/Polyline_simplification_2/index.html">CGAL Polyline Simplification 2</link> library with additional handling to preserve Z and M coordinates.
+ When topology is preserved and geometries intersect, Z and M values are interpolated at intersection points.
+ </para>
+ <para>
+ This function works well with 3D terrain-like geometries (2.5D) but is not designed for vertical surfaces like walls.
+ </para>
+ <para role="availability" conformance="3.6.0">Availability: 3.6.0 - requires SFCGAL >= 2.1.0</para>
+ <para>&sfcgal_required;</para>
+ <para>&Z_support;</para>
+ <para>&M_support;</para>
+ </refsection>
+
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term><parameter>geom</parameter></term>
+ <listitem>
+ <para>Input geometry</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><parameter>threshold</parameter></term>
+ <listitem>
+ <para>Maximum distance threshold (in geometry unit) for simplification. The higher this value, the more simplified the resulting geometry will be.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><parameter>preserveTopology</parameter></term>
+ <listitem>
+ <para>If set to true, the function ensures that the topology of the geometry is preserved. When geometries intersect in this mode, Z and M values at intersection points are interpolated. The default value is false.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+
+ <refsection>
+ <title>Return Value</title>
+ <para>
+ Returns a simplified geometry with preserved Z and M values.
+ </para>
+ </refsection>
+
+ <refsection>
+ <title>Examples</title>
+ <para>
+ <programlisting>
+-- Simplify a polygon with a threshold of 0.5
+SELECT ST_AsText(CG_Simplify(ST_GeomFromText('POLYGON((0 0, 0 1, 0.1 1, 0.2 1, 0.3 1, 0.4 1, 0.5 1, 1 1, 1 0, 0 0))'), 0.5));
+
+-- Simplify a 3D terrain geometry while preserving topology and Z values
+SELECT ST_AsText(CG_Simplify(ST_GeomFromText('LINESTRING Z(0 0 0, 0 1 1, 0.1 1 1, 0.2 1 1, 0.3 1 1, 1 1 2)'), 0.2, true));
+
+-- Simplify a geometry with both Z and M values
+SELECT ST_AsText(CG_Simplify(ST_GeomFromText('LINESTRING ZM(0 0 0 1, 0 1 1 2, 0.1 1 1 3, 0.2 1 1 4, 0.3 1 1 5, 1 1 2 6)'), 0.2));
+
+-- Simplify two geometry together preserving Z and M values, without topology
+SELECT ST_AsText(CG_Simplify('GEOMETRYCOLLECTION ZM(LINESTRING ZM(-1 -1 3 4, 0 0 10 100, 1 1 20 200, 0 2 15 150, 0 5 30 300, 2 19 25 250, -4 20 15 150), POLYGON ZM((0 0 10 100, 1 1 20 200, 0 2 15 150, 0 5 30 300, 2 19 25 250, -4 20 15 150, 0 0 10 100)))', 2, false));
+
+-- Simplify two geometry together preserving Z and M values, with topology
+SELECT ST_AsText(CG_Simplify('GEOMETRYCOLLECTION ZM(LINESTRING ZM(-1 -1 3 4, 0 0 10 100, 1 1 20 200, 0 2 15 150, 0 5 30 300, 2 19 25 250, -4 20 15 150), POLYGON ZM((0 0 10 100, 1 1 20 200, 0 2 15 150, 0 5 30 300, 2 19 25 250, -4 20 15 150, 0 0 10 100)))', 2, true));
+ </programlisting>
+ </para>
+ <para>
+ <programlisting>
+WITH depts_pds as (SELECT ST_GeomFromText('GEOMETRYCOLLECTION(
+POLYGON((88.46 158.85,90.77 171.54,147.31 173.85,146.15 145,173.85 119.62,146.15 103.46,112.69 118.46,91.92 93.08,65.38 101.15,34.23 121.92,41.15 142.69,49.23 143.85,88.46 158.85)),
+POLYGON((112.69 118.46,146.15 103.46,190 60.77,185.38 43.46,126.54 26.15,83.85 28.46,67.69 64.23,43.46 58.46,10 83.85,34.23 121.92,65.38 101.15,91.92 93.08,112.69 118.46)))
+') as geom)
+SELECT geom FROM depts_pds;
+ </programlisting>
+ <informalfigure>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/cg_simplify00.png"/>
+ </imageobject>
+ <caption><para>Originals geometries</para></caption>
+ </mediaobject>
+ </informalfigure>
+ </para>
+ <para>
+ <programlisting>
+WITH depts_pds as (SELECT ST_GeomFromText('GEOMETRYCOLLECTION(
+POLYGON((88.46 158.85,90.77 171.54,147.31 173.85,146.15 145,173.85 119.62,146.15 103.46,112.69 118.46,91.92 93.08,65.38 101.15,34.23 121.92,41.15 142.69,49.23 143.85,88.46 158.85)),
+POLYGON((112.69 118.46,146.15 103.46,190 60.77,185.38 43.46,126.54 26.15,83.85 28.46,67.69 64.23,43.46 58.46,10 83.85,34.23 121.92,65.38 101.15,91.92 93.08,112.69 118.46)))
+') as geom)
+SELECT (ST_Dump(CG_Simplify(geom, 0.5, true))).geom FROM depts_pds;
+ </programlisting>
+ <informalfigure>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/cg_simplify01.png"/>
+ </imageobject>
+ <caption><para>Simplification with 0.5 and topology preserved</para></caption>
+ </mediaobject>
+ </informalfigure>
+ </para>
+ <para>
+ <programlisting>
+WITH depts_pds as (SELECT ST_GeomFromText('GEOMETRYCOLLECTION(
+POLYGON((88.46 158.85,90.77 171.54,147.31 173.85,146.15 145,173.85 119.62,146.15 103.46,112.69 118.46,91.92 93.08,65.38 101.15,34.23 121.92,41.15 142.69,49.23 143.85,88.46 158.85)),
+POLYGON((112.69 118.46,146.15 103.46,190 60.77,185.38 43.46,126.54 26.15,83.85 28.46,67.69 64.23,43.46 58.46,10 83.85,34.23 121.92,65.38 101.15,91.92 93.08,112.69 118.46)))
+') as geom)
+SELECT (ST_Dump(CG_Simplify(geom, 0.5, false))).geom FROM depts_pds;
+ </programlisting>
+ <informalfigure>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/cg_simplify02.png"/>
+ </imageobject>
+ <caption><para>Simplification with 0.5 without topology preservation</para></caption>
+ </mediaobject>
+ </informalfigure>
+ </para>
+ </refsection>
+
+ <refsection>
+ <title>See Also</title>
+ <para>
+ <xref linkend="ST_Simplify"/>, <xref linkend="ST_SimplifyPreserveTopology"/>
+ </para>
+ </refsection>
+</refentry>
+
</section>
</chapter>
commit e3ad7eb306dddff0cf7b0c824654ba9dcb90724d
Author: Loïc Bartoletti <loic.bartoletti at oslandia.com>
Date: Thu Mar 20 06:58:57 2025 +0100
feat(SFCGAL): Add CG_Simplify function
diff --git a/sfcgal/lwgeom_sfcgal.c b/sfcgal/lwgeom_sfcgal.c
index a73834701..2885d6995 100644
--- a/sfcgal/lwgeom_sfcgal.c
+++ b/sfcgal/lwgeom_sfcgal.c
@@ -77,6 +77,7 @@ Datum postgis_sfcgal_noop(PG_FUNCTION_ARGS);
Datum sfcgal_convexhull3D(PG_FUNCTION_ARGS);
Datum sfcgal_alphashape(PG_FUNCTION_ARGS);
Datum sfcgal_optimalalphashape(PG_FUNCTION_ARGS);
+Datum sfcgal_simplify(PG_FUNCTION_ARGS);
GSERIALIZED *geometry_serialize(LWGEOM *lwgeom);
char *text_to_cstring(const text *textptr);
@@ -1727,3 +1728,41 @@ sfcgal_buffer3d(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(output);
#endif
}
+
+PG_FUNCTION_INFO_V1(sfcgal_simplify);
+Datum
+sfcgal_simplify(PG_FUNCTION_ARGS)
+{
+#if POSTGIS_SFCGAL_VERSION < 20100
+ lwpgerror(
+ "The SFCGAL version this PostGIS binary was compiled against (%d) doesn't support "
+ "'sfcgal_geometry_simplify' function (requires SFCGAL 2.1.0+)",
+ POSTGIS_SFCGAL_VERSION);
+ PG_RETURN_NULL();
+#else /* POSTGIS_SFCGAL_VERSION >= 20100 */
+ GSERIALIZED *input, *output;
+ sfcgal_geometry_t *geom, *result;
+ double threshold;
+ bool preserveTopology;
+ srid_t srid;
+
+ sfcgal_postgis_init();
+
+ input = PG_GETARG_GSERIALIZED_P(0);
+ threshold = PG_GETARG_FLOAT8(1);
+ preserveTopology = PG_GETARG_BOOL(2);
+ srid = gserialized_get_srid(input);
+
+ geom = POSTGIS2SFCGALGeometry(input);
+ PG_FREE_IF_COPY(input, 0);
+
+ result = sfcgal_geometry_simplify(geom, threshold, preserveTopology);
+ sfcgal_geometry_delete(geom);
+
+ output = SFCGALGeometry2POSTGIS(result, 0, srid);
+ sfcgal_geometry_delete(result);
+
+ PG_RETURN_POINTER(output);
+#endif
+}
+
diff --git a/sfcgal/regress/simplify.sql b/sfcgal/regress/simplify.sql
new file mode 100644
index 000000000..8763e8524
--- /dev/null
+++ b/sfcgal/regress/simplify.sql
@@ -0,0 +1,2 @@
+SELECT 'CG_Simplify', ST_AsText(CG_Simplify('GEOMETRYCOLLECTION ZM(LINESTRING ZM(-1 -1 3 4, 0 0 10 100, 1 1 20 200, 0 2 15 150, 0 5 30 300, 2 19 25 250, -4 20 15 150), POLYGON ZM((0 0 10 100, 1 1 20 200, 0 2 15 150, 0 5 30 300, 2 19 25 250, -4 20 15 150, 0 0 10 100)))', 2, false));
+SELECT 'CG_Simplify With Topology', ST_AsText(CG_Simplify('GEOMETRYCOLLECTION ZM(LINESTRING ZM(-1 -1 3 4, 0 0 10 100, 1 1 20 200, 0 2 15 150, 0 5 30 300, 2 19 25 250, -4 20 15 150), POLYGON ZM((0 0 10 100, 1 1 20 200, 0 2 15 150, 0 5 30 300, 2 19 25 250, -4 20 15 150, 0 0 10 100)))', 2, true));
diff --git a/sfcgal/regress/simplify_expected b/sfcgal/regress/simplify_expected
new file mode 100644
index 000000000..b5f119f0c
--- /dev/null
+++ b/sfcgal/regress/simplify_expected
@@ -0,0 +1,2 @@
+CG_Simplify|GEOMETRYCOLLECTION ZM (LINESTRING ZM (-1 -1 3 4,2 19 25 250,-4 20 15 150),POLYGON ZM ((0 0 10 100,2 19 25 250,-4 20 15 150,0 0 10 100)))
+CG_Simplify With Topology|GEOMETRYCOLLECTION ZM (LINESTRING ZM (-1 -1 3 4,0 0 10 100,2 19 25 250,-4 20 15 150),POLYGON ZM ((0 0 10 100,2 19 25 250,-4 20 15 150,0 0 10 100)))
diff --git a/sfcgal/regress/tests.mk.in b/sfcgal/regress/tests.mk.in
index d160823d3..241d274f2 100644
--- a/sfcgal/regress/tests.mk.in
+++ b/sfcgal/regress/tests.mk.in
@@ -37,3 +37,8 @@ ifeq ($(shell expr "$(POSTGIS_SFCGAL_VERSION)" ">=" 20000),1)
TESTS += \
$(top_srcdir)/sfcgal/regress/sfcgal_v2.sql
endif
+
+ifeq ($(shell expr "$(POSTGIS_SFCGAL_VERSION)" ">=" 20100),1)
+ TESTS += \
+ $(top_srcdir)/sfcgal/regress/simplify.sql
+endif
diff --git a/sfcgal/sfcgal.sql.in b/sfcgal/sfcgal.sql.in
index 2cee2c9fa..6764b2f18 100644
--- a/sfcgal/sfcgal.sql.in
+++ b/sfcgal/sfcgal.sql.in
@@ -595,4 +595,10 @@ AS 'MODULE_PATHNAME', 'sfcgal_translate_3d'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
_COST_LOW;
+-- Availability 3.6.0
+CREATE OR REPLACE FUNCTION CG_Simplify(geom geometry, threshold float8, preserveTopology boolean DEFAULT false )
+RETURNS geometry
+AS 'MODULE_PATHNAME', 'sfcgal_simplify'
+LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE
+_COST_LOW;
COMMIT;
-----------------------------------------------------------------------
Summary of changes:
NEWS | 1 +
doc/html/images/Makefile.in | 3 +
doc/html/images/wkt/cg_simplify00.wkt | 1 +
doc/html/images/wkt/cg_simplify01.wkt | 2 +
doc/html/images/wkt/cg_simplify02.wkt | 2 +
doc/reference_sfcgal.xml | 149 +++++++++++++++++++++++++++++++++-
sfcgal/lwgeom_sfcgal.c | 39 +++++++++
sfcgal/regress/simplify.sql | 2 +
sfcgal/regress/simplify_expected | 2 +
sfcgal/regress/tests.mk.in | 5 ++
sfcgal/sfcgal.sql.in | 6 ++
11 files changed, 211 insertions(+), 1 deletion(-)
create mode 100644 doc/html/images/wkt/cg_simplify00.wkt
create mode 100644 doc/html/images/wkt/cg_simplify01.wkt
create mode 100644 doc/html/images/wkt/cg_simplify02.wkt
create mode 100644 sfcgal/regress/simplify.sql
create mode 100644 sfcgal/regress/simplify_expected
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list