[postgis-tickets] [SCM] PostGIS branch master updated. 3.3.0alpha1-20-g50af3f351
git at osgeo.org
git at osgeo.org
Thu Jun 9 11:40:24 PDT 2022
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 50af3f3512f2f57a719b0fcfb2b5e5a0b7227cfb (commit)
from 99cfcff5671882e202a14b56449868e7b88a42b2 (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 50af3f3512f2f57a719b0fcfb2b5e5a0b7227cfb
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Thu Jun 9 11:38:46 2022 -0700
Add ST_SimplifyPolygonHull() function for use with GEOS 3.11
Builds an inner or outer full that is either fully containing
or contained, respectively. Hull is built by removing edges
until target percentage of remaining vertices is met.
diff --git a/doc/html/image_src/Makefile.in b/doc/html/image_src/Makefile.in
index 175685c2e..c1eb3c7b3 100644
--- a/doc/html/image_src/Makefile.in
+++ b/doc/html/image_src/Makefile.in
@@ -155,6 +155,7 @@ IMAGES= \
../images/st_split02.png \
../images/st_split03.png \
../images/st_split04.png \
+ ../images/st_simplifypolygonhull01.png \
../images/st_straightskeleton01.png \
../images/st_approximatemedialaxis01.png \
../images/st_subdivide01.png \
diff --git a/doc/html/image_src/generator.c b/doc/html/image_src/generator.c
index 6ad1b04b8..d1a0ece2a 100644
--- a/doc/html/image_src/generator.c
+++ b/doc/html/image_src/generator.c
@@ -409,7 +409,7 @@ int main( int argc, const char* argv[] )
{
FILE *pfile;
LWGEOM *lwgeom;
- char line [2048];
+ char line [65536];
char *filename;
int layerCount;
LAYERSTYLE *styles;
diff --git a/doc/html/image_src/st_simplifypolygonhull01.wkt b/doc/html/image_src/st_simplifypolygonhull01.wkt
new file mode 100644
index 000000000..a1ba14b10
--- /dev/null
+++ b/doc/html/image_src/st_simplifypolygonhull01.wkt
@@ -0,0 +1,2 @@
+Result;MULTIPOLYGON(((110.8 135.2,87.7 81.2,113.2 20,79 20,59.6 32.6,56.9 26.3,55.6 23.2,54.2 20,20 20,21.7 23.6,41.9 66.8,47 77.6,22.6 135.2,110.8 135.2)),((187 52,187 18.2,165 20,162.2 20.4,160.8 20.6,158 21.2,155.4 22.2,154 22.8,151.4 24,148.8 25.6,147.6 26.4,145.2 28.2,143 30.4,141 32.8,139 35.6,138.2 37.2,136.6 40.8,135.8 42.6,135.2 44.6,122.2 103.6,122.2 137.8,133 170.8,168.8 170.8,185 137.8,187 52)))
+ArgA-thin;MULTIPOLYGON(((56.6 135.2,57.8 131.9,59 128.6,60.2 125.3,61.4 122,62.4 118.4,63.5 114.7,64.5 111.1,65.6 107.4,66.6 103.8,67.7 107.4,68.8 111.1,69.8 114.7,70.9 118.4,72 122,73.2 125.3,74.4 128.6,75.6 131.9,76.8 135.2,80.6 135.2,84.4 135.2,88.1 135.2,91.9 135.2,95.7 135.2,99.5 135.2,103.2 135.2,107 135.2,110.8 135.2,109.3 131.6,107.7 128,106.2 124.4,104.6 120.8,103.1 117.2,101.6 113.6,100 110,98.5 106.4,97 102.8,95.4 99.2,93.9 95.6,92.4 92,90.8 88.4,89.3 84.8,87.7 81.2,86.2 77.6,87.9 74,89.6 70.4,91.3 66.8,93 63.2,94.6 59.6,96.3 56,98 52.4,99.7 48.8,101.4 45.2,103.1 41.6,104.8 38,106.4 34.4,108.1 30.8,109.8 27.2,111.5 23.6,113.2 20,109.4 20,105.6 20,101.8 20,98 20,94.2 20,90.4 20,86.6 20,82.8 20,79 20,77.6 23.4,76.1 26.7,74.6 30,73.2 33.4,72.1 36.6,71 39.8,69.9 43,68.8 46.2,67.7 49.4,66.6 52.6,65.4 49.3,64.3 45.9,63.1 42.6,61.9 39.3,60.8 35.9,59.6 32.6,58.2 29.5,56.9 26.3,55.6 23.2,54.2 20,50.4 20,46.6 20,42.8 20,39 20,35.2 20,31.4 20,27.6 20,23.8 20,20 20,21.7 23.6,23.4 27.
2,25.1 30.8,26.8 34.4,28.4 38,30.1 41.6,31.8 45.2,33.5 48.8,35.2 52.4,36.9 56,38.6 59.6,40.2 63.2,41.9 66.8,43.6 70.4,45.3 74,47 77.6,45.5 81.2,44 84.8,42.4 88.4,40.9 92,39.4 95.6,37.8 99.2,36.3 102.8,34.8 106.4,33.3 110,31.8 113.6,30.2 117.2,28.7 120.8,27.2 124.4,25.7 128,24.1 131.6,22.6 135.2,26.4 135.2,30.2 135.2,33.9 135.2,37.7 135.2,41.5 135.2,45.3 135.2,49 135.2,52.8 135.2,56.6 135.2)),((175.6 50.4,178.6 50.4,181.5 50.4,184.4 50.4,187 52,187 48.2,187 44.5,187 40.7,187 37,187 33.2,187 29.5,187 25.7,187 22,187 18.2,184.2 19.6,180.7 19.6,177.2 19.6,173.6 19.6,172.2 19.6,170.8 19.6,169.2 19.8,167.8 19.8,166.4 20,165 20,163.6 20.2,162.2 20.4,160.8 20.6,159.4 21,158 21.2,156.8 21.8,155.4 22.2,154 22.8,152.8 23.4,151.4 24,150.2 24.8,148.8 25.6,147.6 26.4,146.4 27.4,145.2 28.2,144.2 29.4,143 30.4,142 31.6,141 32.8,140 34.2,139 35.6,138.2 37.2,137.4 39,136.6 40.8,135.8 42.6,135.2 44.6,135.2 48.4,135.2 52.2,135.2 56,135.2 59.8,135.2 63.6,135.2 67.4,135.2 71.2,135.2 75,135.2 78.8,135.2 8
2.6,135.2 86.4,135.2 90.2,135.2 94,135.2 97.8,135.2 101.6,135.2 105.4,131.6 105.4,128 105.4,124.4 105.4,122.2 103.6,122.2 107.4,122.2 111.2,122.2 115,122.2 118.8,122.2 122.6,122.2 126.4,122.2 130.2,122.2 134,122.2 137.8,124.4 135.8,128 135.8,131.6 135.8,135.2 135.8,135.2 139.5,135.2 143.1,135.2 146.8,135.2 150.5,135.2 154.1,135.2 157.8,135.2 161.5,135.2 165.1,135.2 168.8,133 170.8,137 170.8,141 170.8,145 170.8,148.9 170.8,152.9 170.8,156.9 170.8,160.9 170.8,164.8 170.8,168.8 170.8,166.6 168.4,166.6 164.8,166.6 161.2,166.6 157.5,166.6 153.9,166.6 150.3,166.6 146.7,166.6 143,166.6 139.4,166.6 135.8,169.9 135.8,173.1 135.8,176.3 135.8,179.6 135.8,182.8 135.8,185 137.8,185 134,185 130.2,185 126.4,185 122.6,185 118.8,185 115,185 111.2,185 107.4,185 103.6,182.8 105.4,179.6 105.4,176.3 105.4,173.1 105.4,169.9 105.4,166.6 105.4,166.6 101.6,166.6 97.7,166.6 93.9,166.6 90,166.6 86.2,166.6 82.3,166.6 78.5,166.6 74.6,166.6 70.8,166.6 66.9,166.6 63.1,166.6 59.2,166.6 55.4,166.8 54.8,167.2 54.4,1
67.6 53.8,168 53.4,168.4 53,168.8 52.6,169.4 52.2,170 51.8,170.6 51.4,171.2 51.2,172 51,172.6 50.8,173.4 50.6,174 50.4,174.8 50.4,175.6 50.4)))
diff --git a/doc/reference_processing.xml b/doc/reference_processing.xml
index d30300b68..e4d422edb 100644
--- a/doc/reference_processing.xml
+++ b/doc/reference_processing.xml
@@ -2405,6 +2405,58 @@ FROM (SELECT 'POLYGON((0 0, 8 8, 0 16, 0 0))'::geometry geom) As foo;
</refsection>
</refentry>
+
+ <refentry id="ST_SimplifyPolygonHull">
+ <refnamediv>
+ <refname>ST_SimplifyPolygonHull</refname>
+ <refpurpose>Computes a boundary-respecting fully exterior or fully interior hull of a polygonal geometry.</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>geometry <function>ST_SimplifyPolygonHull</function></funcdef>
+ <paramdef><type>geometry </type> <parameter>param_geom</parameter></paramdef>
+ <paramdef><type>float </type> <parameter>vertex_fraction</parameter></paramdef>
+ <paramdef choice="opt"><type>boolean </type> <parameter>is_outer = true</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+
+ <para>Computes a boundary-respecting hull of a polygonal geometry. An "outer" hull completely covers the input geometry. An "inner" hull is completely contained by the input geometry. The degree of reduction in vertices is controlled by the <varname>vertex_fraction</varname> parameter. Larger values produce less concave results. A vertex fraction of 1.0 produces a convex hull; a value of 0.0 produces the original geometry.</para>
+
+ <para>The simplification operates by removing the line segments that generate the least amount of extra area, progressively, until the vertex target is reached. To get "nice" results with geometries that have long lines without vertices, it might be necessary to first "pre-segmentize" before running the process, as shown below.</para>
+ </refsection>
+ <refsection>
+ <title>Examples</title>
+
+ <para>
+ <informalfigure>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/st_simplifypolygonhull01.png" />
+ </imageobject>
+ <caption><para>Polygonal simplification of a MultiPolygon</para></caption>
+ </mediaobject>
+ </informalfigure>
+ <programlisting>SELECT ST_SimplifyPolygonHull(
+ ST_Segmentize(ST_Letters('xt'), 2.0),
+ 0.1);
+ </programlisting>
+ </para>
+
+ </refsection>
+
+ <refsection>
+ <title>See Also</title>
+ <para><xref linkend="ST_ConvexHull" />, <xref linkend="ST_SimplifyVW" />, <xref linkend="ST_ConcaveHull" /></para>
+ </refsection>
+ </refentry>
+
+
<refentry id="ST_SetEffectiveArea">
<refnamediv>
<refname>ST_SetEffectiveArea</refname>
diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in
index d1a1e4974..5c3417716 100644
--- a/liblwgeom/liblwgeom.h.in
+++ b/liblwgeom/liblwgeom.h.in
@@ -2535,6 +2535,7 @@ LWGEOM* lwgeom_delaunay_triangulation(const LWGEOM *geom, double tolerance, int3
*/
LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double tolerance, int output_edges);
+#if POSTGIS_GEOS_VERSION >= 31100
/**
* Take a geometry and build the concave hull. The concave
* hull is smaller than the convex hull, but still encompasses all the points
@@ -2545,8 +2546,21 @@ LWGEOM* lwgeom_voronoi_diagram(const LWGEOM* g, const GBOX* env, double toleranc
* @param ratio proportion of output vs input
* @param allow_holes can there be holes in the output. large performance penalty.
*/
-#if POSTGIS_GEOS_VERSION >= 31100
LWGEOM* lwgeom_concavehull(const LWGEOM* geom, double ratio, uint32_t allow_holes);
+
+/**
+ * Computes a boundary-respecting hull of a polygonal geometry,
+ * with hull shape determined by a target parameter
+ * specifying the fraction of the input vertices retained in the result.
+ * Larger values produce less concave results.
+ *
+ * @param geom the input geometry
+ * @param vertex_fraction proportion of vertices in output vs input.
+ * @param is_outer expand geometry while removing edges.
+ */
+LWGEOM*
+lwgeom_simplify_polygonal(const LWGEOM* geom, double vertex_fraction, uint32_t is_outer);
+
#endif
/**
diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c
index b0c7fe7b3..89dc07b53 100644
--- a/liblwgeom/lwgeom_geos.c
+++ b/liblwgeom/lwgeom_geos.c
@@ -2126,4 +2126,31 @@ lwgeom_concavehull(const LWGEOM* geom, double ratio, uint32_t allow_holes)
GEOS_FREE(g1, g3);
return result;
}
+
+LWGEOM*
+lwgeom_simplify_polygonal(const LWGEOM* geom, double vertex_fraction, uint32_t is_outer)
+{
+ LWGEOM* result;
+ int32_t srid = RESULT_SRID(geom);
+ uint8_t is3d = FLAGS_GET_Z(geom->flags);
+ GEOSGeometry *g1, *g3;
+
+ initGEOS(lwnotice, lwgeom_geos_error);
+
+ if (!(g1 = LWGEOM2GEOS(geom, AUTOFIX))) GEOS_FAIL();
+
+ g3 = GEOSPolygonHullSimplify(g1, is_outer, vertex_fraction);
+
+ if (!g3)
+ GEOS_FREE_AND_FAIL(g1);
+
+ GEOSSetSRID(g3, srid);
+
+ if (!(result = GEOS2LWGEOM(g3, is3d)))
+ GEOS_FREE_AND_FAIL(g1, g3);
+
+ GEOS_FREE(g1, g3);
+ return result;
+}
+
#endif
diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c
index 2b7a39105..9a7d59587 100644
--- a/postgis/lwgeom_geos.c
+++ b/postgis/lwgeom_geos.c
@@ -106,6 +106,7 @@ Datum ST_BuildArea(PG_FUNCTION_ARGS);
Datum ST_DelaunayTriangles(PG_FUNCTION_ARGS);
Datum ST_MaximumInscribedCircle(PG_FUNCTION_ARGS);
Datum ST_ConcaveHull(PG_FUNCTION_ARGS);
+Datum ST_SimplifyPolygonHull(PG_FUNCTION_ARGS);
Datum pgis_union_geometry_array(PG_FUNCTION_ARGS);
Datum pgis_geometry_union_finalfn(PG_FUNCTION_ARGS);
@@ -919,6 +920,34 @@ Datum ST_ConcaveHull(PG_FUNCTION_ARGS)
}
+PG_FUNCTION_INFO_V1(ST_SimplifyPolygonHull);
+Datum ST_SimplifyPolygonHull(PG_FUNCTION_ARGS)
+{
+#if POSTGIS_GEOS_VERSION < 31100
+
+ lwpgerror("The GEOS version this PostGIS binary "
+ "was compiled against (%d) doesn't support "
+ "'ST_SimplifyPolygonHull' function (3.11.0+ required)",
+ POSTGIS_GEOS_VERSION);
+ PG_RETURN_NULL();
+
+#else /* POSTGIS_GEOS_VERSION >= 31100 */
+ GSERIALIZED* geom = PG_GETARG_GSERIALIZED_P(0);
+ double vertex_fraction = PG_GETARG_FLOAT8(1);
+ uint32_t is_outer = PG_GETARG_BOOL(2);
+
+ LWGEOM* lwgeom = lwgeom_from_gserialized(geom);
+ LWGEOM* lwresult = lwgeom_simplify_polygonal(lwgeom, vertex_fraction, is_outer);
+ GSERIALIZED* result = geometry_serialize(lwresult);
+
+ lwgeom_free(lwgeom);
+ lwgeom_free(lwresult);
+ PG_FREE_IF_COPY(geom, 0);
+ PG_RETURN_POINTER(result);
+#endif
+}
+
+
PG_FUNCTION_INFO_V1(topologypreservesimplify);
Datum topologypreservesimplify(PG_FUNCTION_ARGS)
{
diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in
index 05fb550b3..ef6a0ad15 100644
--- a/postgis/postgis.sql.in
+++ b/postgis/postgis.sql.in
@@ -6458,9 +6458,14 @@ CREATE OR REPLACE FUNCTION ST_SquareGrid(size float8, bounds geometry, OUT geom
-- moved to separate file cause its involved
#include "postgis_brin.sql.in"
----------------------------------------------------------------
--- USER CONTRIBUTED
----------------------------------------------------------------
+
+-- Availability: 3.3.0
+CREATE OR REPLACE FUNCTION ST_SimplifyPolygonHull(geom geometry, vertex_fraction float8, is_outer boolean DEFAULT true)
+ RETURNS geometry
+ AS 'MODULE_PATHNAME', 'ST_SimplifyPolygonHull'
+ LANGUAGE 'c' IMMUTABLE STRICT
+ PARALLEL SAFE
+ _COST_HIGH;
#if POSTGIS_GEOS_VERSION >= 31100
diff --git a/regress/core/geos311.sql b/regress/core/geos311.sql
index 7e9b4aa49..cce4ae686 100644
--- a/regress/core/geos311.sql
+++ b/regress/core/geos311.sql
@@ -37,3 +37,17 @@ SELECT 'concavehull02-points' as test,
ST_Area(ST_ConcaveHull(ST_Points(geom), 0.5, true)) > 0.0 AS nohole_area_non_zero
FROM hull;
+-- ST_SimplifyPolygonHull
+SELECT 'simplifypolygonhull-1' AS test,
+ ST_AsText(ST_SimplifyPolygonHull('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))'::geometry, 0.5),1);
+
+SELECT 'simplifypolygonhull-2' AS test,
+ ST_AsText(ST_SimplifyPolygonHull(
+ 'POLYGON((0 0, 0 1, 0.5 0.1, 1 1, 1 0, 0 0))'::geometry,
+ 0.5),1);
+
+SELECT 'simplifypolygonhull-3' AS test,
+ ST_AsText(ST_SimplifyPolygonHull(
+ 'POLYGON((0 0, 0 1, 0.5 0.1, 0.5 0.1, 1 1, 1 0, 0 0))'::geometry,
+ 0.85),1);
+
diff --git a/regress/core/geos311_expected b/regress/core/geos311_expected
index 59c2e49af..01d9fbbfc 100644
--- a/regress/core/geos311_expected
+++ b/regress/core/geos311_expected
@@ -2,3 +2,6 @@ concavehull01-poly|t
concavehull02-poly|t|ST_Polygon|t
concavehull01-points|t
concavehull02-points|t|ST_Polygon|t
+simplifypolygonhull-1|POLYGON((0 0,0 1,1 1,1 0,0 0))
+simplifypolygonhull-2|POLYGON((0 0,0 1,1 1,1 0,0 0))
+simplifypolygonhull-3|POLYGON((0 0,0 1,0.5 0.1,1 1,1 0,0 0))
-----------------------------------------------------------------------
Summary of changes:
doc/html/image_src/Makefile.in | 1 +
doc/html/image_src/generator.c | 2 +-
doc/html/image_src/st_simplifypolygonhull01.wkt | 2 +
doc/reference_processing.xml | 52 +++++++++++++++++++++++++
liblwgeom/liblwgeom.h.in | 16 +++++++-
liblwgeom/lwgeom_geos.c | 27 +++++++++++++
postgis/lwgeom_geos.c | 29 ++++++++++++++
postgis/postgis.sql.in | 11 ++++--
regress/core/geos311.sql | 14 +++++++
regress/core/geos311_expected | 3 ++
10 files changed, 152 insertions(+), 5 deletions(-)
create mode 100644 doc/html/image_src/st_simplifypolygonhull01.wkt
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list