</refsection>
</refentry>
+ <refentry id="RT_ST_SetValues">
+ <refnamediv>
+ <refname>ST_SetValues</refname>
+ <refpurpose>Returns modified raster resulting from setting the values of a given band.</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>raster <function>ST_SetValues</function></funcdef>
+ <paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
+ <paramdef><type>double precision[][] </type> <parameter>newvalueset</parameter></paramdef>
+ <paramdef><type>boolean[][] </type> <parameter>noset=NULL</parameter></paramdef>
+ <paramdef><type>boolean </type> <parameter>keepnodata=FALSE</parameter></paramdef>
+ </funcprototype>
+
+ <funcprototype>
+ <funcdef>raster <function>ST_SetValues</function></funcdef>
+ <paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>nband</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>columnx</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>rowy</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>width</parameter></paramdef>
+ <paramdef><type>integer </type> <parameter>height</parameter></paramdef>
+ <paramdef><type>double precision </type> <parameter>newvalue</parameter></paramdef>
+ <paramdef><type>boolean </type> <parameter>keepnodata=FALSE</parameter></paramdef>
+ </funcprototype>
+
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+ <para>
+ Returns modified raster resulting from setting specified pixels to new value(s) for the designated band.
+ </para>
+
+ <para>
+ For variant 1, the specific pixels to be set are determined by the <varname>columnx</varname>, <varname>rowy</varname> pixel coordinates and the dimensions of the <varname>newvalueset</varname> array. <varname>noset</varname> can be used to prevent pixels with values present in <varname>newvalueset</varname> from being set (due to PostgreSQL not permitting ragged/jagged arrays). If <varname>keepnodata</varname> is TRUE, those pixels whose values are NODATA will not be set with the corresponding value in <varname>newvalueset</varname>. See example Variant 1.
+ </para>
+
+ <para>
+ For variant 2, the specific pixels to be set are determined by the <varname>columnx</varname>, <varname>rowy</varname> pixel coordinates, <varname>width</varname> and <varname>height</varname>. If <varname>keepnodata</varname> is TRUE, those pixels whose values are NODATA will not be set with the corresponding value in <varname>newvalueset</varname>. See example Variant 2.
+ </para>
+
+ </refsection>
+
+ <refsection>
+ <title>Examples: Variant 1</title>
+
+ <programlisting>
+/*
+The ST_SetValues() does the following...
+
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 1 | 1 | 1 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | => | 1 | 9 | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 1 | 9 | 9 |
++ - + - + - + + - + - + - +
+*/
+SELECT
+ (poly).x,
+ (poly).y,
+ (poly).val
+FROM (
+SELECT
+ ST_PixelAsPolygons(
+ ST_SetValues(
+ ST_AddBand(
+ ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
+ 1, '8BUI', 1, 0
+ ),
+ 1, 2, 2, ARRAY[[9, 9], [9, 9]]::double precision[][]
+ )
+ ) AS poly
+) foo
+ORDER BY 1, 2;
+
+ x | y | val
+---+---+-----
+ 1 | 1 | 1
+ 1 | 2 | 1
+ 1 | 3 | 1
+ 2 | 1 | 1
+ 2 | 2 | 9
+ 2 | 3 | 9
+ 3 | 1 | 1
+ 3 | 2 | 9
+ 3 | 3 | 9
+ </programlisting>
+
+ <programlisting>
+/*
+The ST_SetValues() does the following...
+
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 9 | 9 | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | => | 9 | | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 9 | 9 | 9 |
++ - + - + - + + - + - + - +
+*/
+SELECT
+ (poly).x,
+ (poly).y,
+ (poly).val
+FROM (
+SELECT
+ ST_PixelAsPolygons(
+ ST_SetValues(
+ ST_AddBand(
+ ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
+ 1, '8BUI', 1, 0
+ ),
+ 1, 1, 1, ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][]
+ )
+ ) AS poly
+) foo
+ORDER BY 1, 2;
+
+ x | y | val
+---+---+-----
+ 1 | 1 | 9
+ 1 | 2 | 9
+ 1 | 3 | 9
+ 2 | 1 | 9
+ 2 | 2 |
+ 2 | 3 | 9
+ 3 | 1 | 9
+ 3 | 2 | 9
+ 3 | 3 | 9
+ </programlisting>
+
+ <programlisting>
+/*
+The ST_SetValues() does the following...
+
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 9 | 9 | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | => | 1 | | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 9 | 9 | 9 |
++ - + - + - + + - + - + - +
+*/
+SELECT
+ (poly).x,
+ (poly).y,
+ (poly).val
+FROM (
+SELECT
+ ST_PixelAsPolygons(
+ ST_SetValues(
+ ST_AddBand(
+ ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
+ 1, '8BUI', 1, 0
+ ),
+ 1, 1, 1,
+ ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][],
+ ARRAY[[false], [true]]::boolean[][]
+ )
+ ) AS poly
+) foo
+ORDER BY 1, 2;
+
+ x | y | val
+---+---+-----
+ 1 | 1 | 9
+ 1 | 2 | 1
+ 1 | 3 | 9
+ 2 | 1 | 9
+ 2 | 2 |
+ 2 | 3 | 9
+ 3 | 1 | 9
+ 3 | 2 | 9
+ 3 | 3 | 9
+ </programlisting>
+
+ <programlisting>
+/*
+The ST_SetValues() does the following...
+
++ - + - + - + + - + - + - +
+| | 1 | 1 | | | 9 | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | => | 1 | | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 9 | 9 | 9 |
++ - + - + - + + - + - + - +
+*/
+SELECT
+ (poly).x,
+ (poly).y,
+ (poly).val
+FROM (
+SELECT
+ ST_PixelAsPolygons(
+ ST_SetValues(
+ ST_SetValue(
+ ST_AddBand(
+ ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
+ 1, '8BUI', 1, 0
+ ),
+ 1, 1, 1, NULL
+ ),
+ 1, 1, 1,
+ ARRAY[[9, 9, 9], [9, NULL, 9], [9, 9, 9]]::double precision[][],
+ ARRAY[[false], [true]]::boolean[][],
+ TRUE
+ )
+ ) AS poly
+) foo
+ORDER BY 1, 2;
+
+ x | y | val
+---+---+-----
+ 1 | 1 |
+ 1 | 2 | 1
+ 1 | 3 | 9
+ 2 | 1 | 9
+ 2 | 2 |
+ 2 | 3 | 9
+ 3 | 1 | 9
+ 3 | 2 | 9
+ 3 | 3 | 9
+ </programlisting>
+
+ </refsection>
+
+ <refsection>
+ <title>Examples: Variant 2</title>
+
+ <programlisting>
+/*
+The ST_SetValues() does the following...
+
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 1 | 1 | 1 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | => | 1 | 9 | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 1 | 9 | 9 |
++ - + - + - + + - + - + - +
+*/
+SELECT
+ (poly).x,
+ (poly).y,
+ (poly).val
+FROM (
+SELECT
+ ST_PixelAsPolygons(
+ ST_SetValues(
+ ST_AddBand(
+ ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
+ 1, '8BUI', 1, 0
+ ),
+ 1, 2, 2, 2, 2, 9
+ )
+ ) AS poly
+) foo
+ORDER BY 1, 2;
+
+ x | y | val
+---+---+-----
+ 1 | 1 | 1
+ 1 | 2 | 1
+ 1 | 3 | 1
+ 2 | 1 | 1
+ 2 | 2 | 9
+ 2 | 3 | 9
+ 3 | 1 | 1
+ 3 | 2 | 9
+ 3 | 3 | 9
+ </programlisting>
+
+ <programlisting>
+/*
+The ST_SetValues() does the following...
+
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 1 | 1 | 1 |
++ - + - + - + + - + - + - +
+| 1 | | 1 | => | 1 | | 9 |
++ - + - + - + + - + - + - +
+| 1 | 1 | 1 | | 1 | 9 | 9 |
++ - + - + - + + - + - + - +
+*/
+SELECT
+ (poly).x,
+ (poly).y,
+ (poly).val
+FROM (
+SELECT
+ ST_PixelAsPolygons(
+ ST_SetValues(
+ ST_SetValue(
+ ST_AddBand(
+ ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),
+ 1, '8BUI', 1, 0
+ ),
+ 1, 2, 2, NULL
+ ),
+ 1, 2, 2, 2, 2, 9, TRUE
+ )
+ ) AS poly
+) foo
+ORDER BY 1, 2;
+
+ x | y | val
+---+---+-----
+ 1 | 1 | 1
+ 1 | 2 | 1
+ 1 | 3 | 1
+ 2 | 1 | 1
+ 2 | 2 |
+ 2 | 3 | 9
+ 3 | 1 | 1
+ 3 | 2 | 9
+ 3 | 3 | 9
+ </programlisting>
+
+ </refsection>
+
+ <refsection>
+ <title>See Also</title>
+ <para>
+ <xref linkend="RT_ST_Value" />,
+ <xref linkend="RT_ST_SetValue" />,
+ <xref linkend="RT_ST_PixelAsPolygons" />
+ </para>
+ </refsection>
+ </refentry>
+
<refentry id="RT_ST_PixelOfValue">
<refnamediv>
<refname>ST_PixelOfValue</refname>
--- /dev/null
+SET client_min_messages TO warning;
+
+DROP TABLE IF EXISTS raster_setvalues_rast;
+DROP TABLE IF EXISTS raster_setvalues_out;
+CREATE TABLE raster_setvalues_rast (
+ rid integer,
+ rast raster
+);
+CREATE TABLE raster_setvalues_out (
+ rid integer,
+ rast raster
+);
+CREATE OR REPLACE FUNCTION make_test_raster(rid integer, width integer DEFAULT 2, height integer DEFAULT 2, ul_x double precision DEFAULT 0, ul_y double precision DEFAULT 0, skew_x double precision DEFAULT 0, skew_y double precision DEFAULT 0)
+ RETURNS void
+ AS $$
+ DECLARE
+ x int;
+ y int;
+ rast raster;
+ BEGIN
+ rast := ST_MakeEmptyRaster(width, height, ul_x, ul_y, 1, 1, skew_x, skew_y, 0);
+ rast := ST_AddBand(rast, 1, '8BUI', 1, 0);
+
+ INSERT INTO raster_setvalues_rast VALUES (rid, rast);
+
+ RETURN;
+ END;
+ $$ LANGUAGE 'plpgsql';
+SELECT make_test_raster(0, 5, 3);
+DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision);
+
+INSERT INTO raster_setvalues_out VALUES (
+ 1, (
+ SELECT ST_SetValues(
+ rast, 1, 1, 1,
+ ARRAY[10]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 2, (
+ SELECT ST_SetValues(
+ rast, 1, 2, 1,
+ ARRAY[10]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 3, (
+ SELECT ST_SetValues(
+ rast, 1, 3, 1,
+ ARRAY[10]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 4, (
+ SELECT ST_SetValues(
+ rast, 1, 1, 1,
+ ARRAY[10, 10]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 5, (
+ SELECT ST_SetValues(
+ rast, 1, 2, 2,
+ ARRAY[10, 10]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 6, (
+ SELECT ST_SetValues(
+ rast, 1, 3, 3,
+ ARRAY[10, 10, 10]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 7, (
+ SELECT ST_SetValues(
+ rast, 1, 4, 3,
+ ARRAY[10, 10, 10]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 8, (
+ SELECT ST_SetValues(
+ rast, 1, 2, 1,
+ ARRAY[[5, 5, 5, 5], [6, 6, 6, 6]]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 9, (
+ SELECT ST_SetValues(
+ rast, 1, 2, 1,
+ ARRAY[[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, NULL]]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 10, (
+ SELECT ST_SetValues(
+ rast, 1, 2, 1,
+ ARRAY[[5, 5, 5, 5, 10], [6, 6, 6, 6, 10], [7, 7, 7, NULL, 10]]::double precision[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 11, (
+ SELECT ST_SetValues(
+ rast, 1, 1, 1,
+ ARRAY[10, 10, 10]::double precision[],
+ ARRAY[false, true]::boolean[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 12, (
+ SELECT ST_SetValues(
+ rast, 1, 1, 1,
+ ARRAY[NULL, 10, 0]::double precision[],
+ ARRAY[false, NULL, false]::boolean[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 13, (
+ SELECT ST_SetValues(
+ rast, 1, 1, 1,
+ ARRAY[NULL, 10, 0]::double precision[],
+ ARRAY[false, NULL, true]::boolean[]
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 21, (
+ SELECT ST_SetValues(
+ rast, 1,
+ 1, 1,
+ 5, 3,
+ 100
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 22, (
+ SELECT ST_SetValues(
+ rast, 1,
+ 1, 1,
+ 5, 3,
+ NULL
+ )
+ FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+ 23, (
+ SELECT ST_SetValues(
+ rast, 1,
+ 1, 1,
+ 5, 3,
+ 0
+ )
+ FROM raster_setvalues_rast
+));
+
+SELECT
+ rid,
+ (poly).x,
+ (poly).y,
+ (poly).val
+FROM (
+ SELECT
+ rid,
+ ST_PixelAsPolygons(rast) AS poly
+ FROM raster_setvalues_out
+) AS foo
+ORDER BY 1, 2, 3;
+
+DROP TABLE IF EXISTS raster_setvalues_rast;
+DROP TABLE IF EXISTS raster_setvalues_out;