[SCM] PostGIS branch master updated. 3.5.0-51-g2b7380ec7
git at osgeo.org
git at osgeo.org
Mon Nov 11 07:47:00 PST 2024
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 2b7380ec7f2eb0f95b2cbd7bb81674cbda90bd75 (commit)
from 31a628d75450169ee7979799f2bed386609f2b31 (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 2b7380ec7f2eb0f95b2cbd7bb81674cbda90bd75
Author: Sandro Santilli <strk at kbt.io>
Date: Mon Nov 11 10:38:43 2024 +0100
Add ST_AsRasterAgg aggregate
Closes #1247
Includes regress test and documentation
diff --git a/NEWS b/NEWS
index 7040644c3..66c522a19 100644
--- a/NEWS
+++ b/NEWS
@@ -3,12 +3,13 @@ PostGIS 3.6.0
* Breaking Changes *
-#5799, make ST_TileEnvelope clips envelopes to tile plane extent (Paul Ramsey)
+ - #5799, make ST_TileEnvelope clips envelopes to tile plane extent (Paul Ramsey)
* Deprecated signatures *
* New Features *
-#5784, GT-223 Export circ_tree_distance_tree_internal for mobilitydb use
- (Maxime Schoemans)
+ - #1247, ST_AsRasterAgg (Sandro Santilli)
+ - #5784, GT-223 Export circ_tree_distance_tree_internal for mobilitydb use
+ (Maxime Schoemans)
diff --git a/doc/reference_raster.xml b/doc/reference_raster.xml
index ac94dd31f..b79b32dce 100644
--- a/doc/reference_raster.xml
+++ b/doc/reference_raster.xml
@@ -2064,6 +2064,88 @@ SELECT ST_AsPNG(
</refsection>
</refentry>
+<!-- { ST_AsRasterAgg -->
+
+ <refentry xml:id="RT_ST_AsRasterAgg">
+ <refnamediv>
+ <refname>ST_AsRasterAgg</refname>
+ <refpurpose>
+ Aggregate. Renders PostGIS geometries into a new raster.
+ </refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>raster <function>ST_AsRasterAgg</function></funcdef>
+ <paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
+ <paramdef><type>double precision </type> <parameter>val</parameter></paramdef>
+ <paramdef><type>raster </type> <parameter>ref</parameter></paramdef>
+ <paramdef><type>text </type> <parameter>pixeltype</parameter></paramdef>
+ <paramdef><type>double precision </type> <parameter>nodataval</parameter></paramdef>
+ <paramdef><type>text </type> <parameter>uniontype</parameter></paramdef>
+ <paramdef><type>boolean </type> <parameter>touched</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+
+ <para>
+Returns a single-band raster containing the rendered version of all incoming
+geometries, each with its associated value.
+ </para>
+
+ <para role="availability" conformance="3.6.0">Availability: 3.6.0 </para>
+ </refsection>
+
+ <refsection>
+ <title>Examples</title>
+ <programlisting>
+WITH inp(g,v) AS (
+ VALUES
+ ( ST_Buffer(ST_MakePoint(10,0), 10), 1 ),
+ ( ST_Buffer(ST_MakePoint(20,0), 10), 2 )
+),
+agg AS (
+ SELECT ST_AsRasterAgg(
+ g,
+ v,
+ ST_MakeEmptyRaster(0,0,0,0,1.0),
+ '8BUI',
+ 99,
+ 'SUM',
+ true
+ ) r
+ FROM inp
+)
+SELECT
+ ST_Width(r) w,
+ ST_Height(r) h,
+ ST_Value(r,'POINT(5 0)') v5_0,
+ ST_Value(r,'POINT(15 0)') v15_0,
+ ST_Value(r,'POINT(25 0)') v25_0
+FROM agg;
+ w | h | v5_0 | v15_0 | v25_0
+----+----+------+-------+-------
+ 30 | 20 | 1 | 3 | 2
+(1 row)
+ </programlisting>
+ </refsection>
+
+ <refsection>
+ <title>See Also</title>
+ <para>
+ <xref linkend="RT_ST_AsRaster"/>,
+ <xref linkend="RT_ST_DumpAsPolygons"/>,
+ <xref linkend="RT_ST_Union"/>
+ </para>
+ </refsection>
+ </refentry>
+
+<!-- ST_AsRasterAgg }-->
+
<refentry xml:id="RT_ST_Band">
<refnamediv>
<refname>ST_Band</refname>
@@ -14008,6 +14090,7 @@ ORDER BY val;
<title>See Also</title>
<para>
<xref linkend="geomval"/>,
+ <xref linkend="RT_ST_AsRasterAgg"/>,
<xref linkend="RT_ST_Value"/>,
<xref linkend="RT_ST_Polygon"/>,
<xref linkend="RT_ST_ValueCount"/>
diff --git a/raster/rt_pg/rtpostgis.sql.in b/raster/rt_pg/rtpostgis.sql.in
index c5e66c7a3..c4f897484 100644
--- a/raster/rt_pg/rtpostgis.sql.in
+++ b/raster/rt_pg/rtpostgis.sql.in
@@ -5,7 +5,7 @@
-- http://trac.osgeo.org/postgis/wiki/WKTRaster
--
-- Copyright (c) 2015-2017 Regina Obe <lr at pcorp.us>
--- Copyright (c) 2009-2023 Sandro Santilli <strk at kbt.io>
+-- Copyright (c) 2009-2024 Sandro Santilli <strk at kbt.io>
-- Copyright (c) 2009-2010 Pierre Racine <pierre.racine at sbf.ulaval.ca>
-- Copyright (c) 2009-2010 Jorge Arevalo <jorge.arevalo at deimos-space.com>
-- Copyright (c) 2009-2010 Mateusz Loskot <mateusz at loskot.net>
@@ -6570,6 +6570,51 @@ CREATE AGGREGATE st_union(raster, text) (
FINALFUNC = _st_union_finalfn
);
+-----------------------------------------------------------------------
+-- ST_AsRasterAgg aggregate
+----------------------------------------------------------------------{
+
+-- Availability: 3.6.0
+CREATE OR REPLACE FUNCTION _ST_AsRasterAgg_transfn(staterast raster, geom geometry, val float8, rast raster, pixeltype text, nodataval float8, uniontype text, touched boolean)
+RETURNS raster AS $BODY$
+DECLARE
+ tmprast RASTER;
+BEGIN
+ tmprast := @extschema at .ST_AsRaster(geom, rast,
+ pixeltype => pixeltype,
+ value => val,
+ nodataval => nodataval,
+ touched => touched
+ );
+
+ IF staterast IS NULL THEN
+ staterast = tmprast;
+ ELSE
+ SELECT @extschema at .ST_Union(r, uniontype)
+ FROM ( VALUES (staterast), (tmprast) ) AS foo(r)
+ INTO staterast;
+ END IF;
+
+ RETURN staterast;
+END;
+$BODY$ LANGUAGE 'plpgsql';
+
+-- Availability: 3.6.0
+CREATE OR REPLACE FUNCTION _ST_AsRasterAgg_finalfn(rast raster)
+RETURNS raster AS $BODY$
+BEGIN
+ RETURN rast;
+END;
+$BODY$ LANGUAGE 'plpgsql';
+
+-- Availability: 3.6.0
+CREATE AGGREGATE ST_AsRasterAgg(geom geometry, val float8, ref raster, pixeltype text, nodataval float8, uniontype text, touched boolean) (
+ SFUNC = _ST_AsRasterAgg_transfn,
+ STYPE = raster,
+ parallel = safe,
+ FINALFUNC = _ST_AsRasterAgg_finalfn
+);
+
-----------------------------------------------------------------------
-- ST_Clip
-----------------------------------------------------------------------
@@ -6638,7 +6683,7 @@ CREATE OR REPLACE FUNCTION st_clip(
-- Availability: 2.0.0
-- Changed: 3.5.0 - added touched parameter
--- Replaces st_clip(raster, geometry, float8[], boolean) deprecated in 3.5.0
+-- Replaces st_clip(raster, geometry, float8[], boolean) deprecated in 3.5.0
CREATE OR REPLACE FUNCTION st_clip(
rast raster,
geom geometry,
diff --git a/raster/test/regress/rt_asrasteragg.sql b/raster/test/regress/rt_asrasteragg.sql
new file mode 100644
index 000000000..61af174a3
--- /dev/null
+++ b/raster/test/regress/rt_asrasteragg.sql
@@ -0,0 +1,26 @@
+WITH inp(g,v) AS (
+ VALUES
+ ( ST_Buffer(ST_MakePoint(10,0), 10), 1 ),
+ ( ST_Buffer(ST_MakePoint(20,0), 10), 2 )
+),
+agg AS (
+ SELECT ST_AsRasterAgg(
+ g, -- geometry
+ v, -- value to render
+ ST_MakeEmptyRaster(0,0,0,0,1.0), -- reference raster, for alignment
+ '8BUI', -- pixel type
+ 99, -- nodata value
+ 'SUM', -- union operation
+ true -- touch
+ ) r
+ FROM inp
+)
+SELECT
+ 't1',
+ ST_Width(r) w,
+ ST_Height(r) h,
+ ST_Value(r,'POINT(0 10)', exclude_nodata_value=>false) v0_10,
+ ST_Value(r,'POINT(5 0)') v5_0,
+ ST_Value(r,'POINT(15 0)') v15_0,
+ ST_Value(r,'POINT(25 0)') v25_0
+FROM agg;
diff --git a/raster/test/regress/rt_asrasteragg_expected b/raster/test/regress/rt_asrasteragg_expected
new file mode 100644
index 000000000..f9ca7fb13
--- /dev/null
+++ b/raster/test/regress/rt_asrasteragg_expected
@@ -0,0 +1 @@
+t1|30|20|99|1|3|2
diff --git a/raster/test/regress/tests.mk b/raster/test/regress/tests.mk
index 00918e134..ac17fda9e 100644
--- a/raster/test/regress/tests.mk
+++ b/raster/test/regress/tests.mk
@@ -87,6 +87,7 @@ RASTER_TEST_UTILITY = \
$(top_srcdir)/raster/test/regress/rt_gdalwarp \
$(top_srcdir)/raster/test/regress/rt_gdalcontour \
$(top_srcdir)/raster/test/regress/rt_asraster \
+ $(top_srcdir)/raster/test/regress/rt_asrasteragg \
$(top_srcdir)/raster/test/regress/rt_dumpvalues \
$(top_srcdir)/raster/test/regress/rt_makeemptycoverage \
$(top_srcdir)/raster/test/regress/rt_createoverview
-----------------------------------------------------------------------
Summary of changes:
NEWS | 7 +--
doc/reference_raster.xml | 83 +++++++++++++++++++++++++++++
raster/rt_pg/rtpostgis.sql.in | 49 ++++++++++++++++-
raster/test/regress/rt_asrasteragg.sql | 26 +++++++++
raster/test/regress/rt_asrasteragg_expected | 1 +
raster/test/regress/tests.mk | 1 +
6 files changed, 162 insertions(+), 5 deletions(-)
create mode 100644 raster/test/regress/rt_asrasteragg.sql
create mode 100644 raster/test/regress/rt_asrasteragg_expected
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list