- #2123, ST_FromGDALRaster
- #613, ST_SetGeoReference with numerical parameters instead of text
- #2276, ST_AddBand(raster) variant for out-db bands
+ - #2280, ST_Summary(raster)
* Enhancements *
<para><xref linkend="RT_ST_Width" /></para>
</refsection>
</refentry>
+
+ <refentry id="RT_ST_IsEmpty">
+ <refnamediv>
+ <refname>ST_IsEmpty</refname>
+ <refpurpose>Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false.</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>boolean <function>ST_IsEmpty</function></funcdef>
+ <paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+
+ <para>Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false.</para>
+
+ <para>Availability: 2.0.0</para>
+ </refsection>
+
+ <refsection>
+ <title>Examples</title>
+
+ <programlisting>SELECT ST_IsEmpty(ST_MakeEmptyRaster(100, 100, 0, 0, 0, 0, 0, 0))
+st_isempty |
+-----------+
+f |
+
+
+SELECT ST_IsEmpty(ST_MakeEmptyRaster(0, 0, 0, 0, 0, 0, 0, 0))
+st_isempty |
+-----------+
+t |
+
+ </programlisting>
+ </refsection>
+
+ <!-- Optionally add a "See Also" section -->
+ <refsection>
+ <title>See Also</title>
+ <para><xref linkend="RT_ST_HasNoBand" /></para>
+ </refsection>
+ </refentry>
+
<refentry id="RT_ST_MetaData">
<refnamediv>
<refname>ST_MetaData</refname>
<para><xref linkend="spatial_ref_sys" />, <xref linkend="ST_SRID" /></para>
</refsection>
</refentry>
+
+ <refentry id="RT_ST_Summary">
+ <refnamediv>
+ <refname>ST_Summary</refname>
+ <refpurpose>Returns a text summary of the contents of the raster.</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef>text <function>ST_Summary</function></funcdef>
+ <paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+
+ <refsection>
+ <title>Description</title>
+
+ <para>Returns a text summary of the contents of the raster.</para>
+
+ <para>Availability: 2.1.0</para>
+ </refsection>
+
+ <refsection>
+ <title>Examples</title>
+ <programlisting>
+SELECT ST_Summary(
+ ST_AddBand(
+ ST_AddBand(
+ ST_AddBand(
+ ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0)
+ , 1, '8BUI', 1, 0
+ )
+ , 2, '32BF', 0, -9999
+ )
+ , 3, '16BSI', 0, NULL
+ )
+);
+
+ st_summary
+------------------------------------------------------------------
+ Raster of 10x10 pixels has 3 bands and extent of BOX(0 -10,10 0)+
+ band 1 of pixtype 8BUI is in-db with NODATA value of 0 +
+ band 2 of pixtype 32BF is in-db with NODATA value of -9999 +
+ band 3 of pixtype 16BSI is in-db with no NODATA value
+(1 row)
+ </programlisting>
+ </refsection>
+
+ <refsection>
+ <title>See Also</title>
+ <para>
+ <xref linkend="RT_ST_MetaData" />,
+ <xref linkend="RT_ST_BandMetaData" />,
+ <xref linkend="ST_Summary" />
+ <xref linkend="ST_Extent" />
+ </para>
+ </refsection>
+ </refentry>
<refentry id="RT_ST_UpperLeftX">
<refnamediv>
</refsection>
</refentry>
- <refentry id="RT_ST_IsEmpty">
- <refnamediv>
- <refname>ST_IsEmpty</refname>
- <refpurpose>Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false.</refpurpose>
- </refnamediv>
-
- <refsynopsisdiv>
- <funcsynopsis>
- <funcprototype>
- <funcdef>boolean <function>ST_IsEmpty</function></funcdef>
- <paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
- </funcprototype>
- </funcsynopsis>
- </refsynopsisdiv>
-
- <refsection>
- <title>Description</title>
-
- <para>Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false.</para>
-
- <para>Availability: 2.0.0</para>
- </refsection>
-
- <refsection>
- <title>Examples</title>
-
- <programlisting>SELECT ST_IsEmpty(ST_MakeEmptyRaster(100, 100, 0, 0, 0, 0, 0, 0))
-st_isempty |
------------+
-f |
-
-
-SELECT ST_IsEmpty(ST_MakeEmptyRaster(0, 0, 0, 0, 0, 0, 0, 0))
-st_isempty |
------------+
-t |
-
- </programlisting>
- </refsection>
-
- <!-- Optionally add a "See Also" section -->
- <refsection>
- <title>See Also</title>
- <para><xref linkend="RT_ST_HasNoBand" /></para>
- </refsection>
- </refentry>
</sect1>
<sect1 id="RasterBand_Accessors">
AS 'MODULE_PATHNAME', 'RASTER_metadata'
LANGUAGE 'c' IMMUTABLE STRICT;
+CREATE OR REPLACE FUNCTION st_summary(rast raster)
+ RETURNS text
+ AS $$
+ DECLARE
+ extent box2d;
+ metadata record;
+ bandmetadata record;
+ msg text;
+ msgset text[];
+ BEGIN
+ extent := ST_Extent(rast::geometry);
+ metadata := ST_Metadata(rast);
+
+ msg := 'Raster of ' || metadata.width || 'x' || metadata.height || ' pixels has ' || metadata.numbands || ' ';
+
+ IF metadata.numbands = 1 THEN
+ msg := msg || 'band ';
+ ELSE
+ msg := msg || 'bands ';
+ END IF;
+ msg := msg || 'and extent of ' || extent;
+
+ IF
+ metadata.skewx::numeric(16, 10) <> 0::numeric(16, 10) OR
+ metadata.skewy::numeric(16, 10) <> 0::numeric(16, 10)
+ THEN
+ msg := 'Skewed ' || overlay(msg placing 'r' from 1 for 1);
+ END IF;
+
+ msgset := Array[]::text[] || msg;
+
+ FOR bandmetadata IN SELECT * FROM ST_BandMetadata(rast, ARRAY[]::int[]) LOOP
+ msg := 'band ' || bandmetadata.bandnum || ' of pixtype ' || bandmetadata.pixeltype || ' is ';
+ IF bandmetadata.isoutdb IS FALSE THEN
+ msg := msg || 'in-db ';
+ ELSE
+ msg := msg || 'out-db ';
+ END IF;
+
+ msg := msg || 'with ';
+ IF bandmetadata.nodatavalue IS NOT NULL THEN
+ msg := msg || 'NODATA value of ' || bandmetadata.nodatavalue;
+ ELSE
+ msg := msg || 'no NODATA value';
+ END IF;
+
+ msgset := msgset || (' ' || msg);
+ END LOOP;
+
+ RETURN array_to_string(msgset, E'\n');
+ END;
+ $$ LANGUAGE 'plpgsql' STABLE STRICT;
+
-----------------------------------------------------------------------
-- Constructor ST_MakeEmptyRaster
-----------------------------------------------------------------------
--- /dev/null
+use File::Basename;
+use Cwd 'abs_path';
+
+my $REGDIR = abs_path(dirname($0));
+my $RASTERDIR = abs_path($REGDIR . "/../raster/test/regress");
+
+unlink $RASTERDIR . '/' . $TEST . '-pre.sql';
+unlink $RASTERDIR . '/' . $TEST . '-post.sql';
--- /dev/null
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
+DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+
+rm -f "$DIR/$TEST-pre.sql"
+rm -f "$DIR/$TEST-post.sql"
--- /dev/null
+use File::Basename;
+use Cwd 'abs_path';
+
+my $REGDIR = abs_path(dirname($0));
+my $RASTERDIR = abs_path($REGDIR . "/../raster/test/regress");
+my $FILERASTER = $RASTERDIR . "/loader/testraster.tif";
+
+# special handling for msys
+if (lc($^O) eq "msys") {
+ $FILERASTER = `cmd //c echo "$FILERASTER"`;
+ $FILERASTER =~ s/^\s+//;
+ $FILERASTER =~ s/\s+$//;
+}
+
+my $sql = <<"END";
+DROP TABLE IF EXISTS raster_outdb_template;
+CREATE TABLE raster_outdb_template AS
+SELECT
+ 1 AS rid,
+ ST_AddBand(
+ ST_MakeEmptyRaster(90, 90, 0., 0., 1, -1, 0, 0, 0),
+ 1, '$FILERASTER'::text, NULL::int[]
+ ) AS rast
+UNION ALL
+SELECT
+ 2 AS rid,
+ ST_AddBand(
+ ST_MakeEmptyRaster(90, 90, 0., 0., 1, -1, 0, 0, 0),
+ '$FILERASTER'::text, NULL::int[]
+ ) AS rast
+UNION ALL
+SELECT
+ 3 AS rid,
+ ST_AddBand(
+ ST_AddBand(
+ ST_MakeEmptyRaster(90, 90, 0., 0., 1, -1, 0, 0, 0),
+ 1, '8BUI', 1, 0
+ ),
+ '$FILERASTER'::text, ARRAY[2]::int[]
+ ) AS rast
+UNION ALL
+SELECT
+ 4 AS rid,
+ ST_AddBand(
+ ST_AddBand(
+ ST_MakeEmptyRaster(90, 90, 0., 0., 1, -1, 0, 0, 0),
+ 1, '8BUI', 1, 0
+ ),
+ '$FILERASTER'::text, ARRAY[2]::int[],
+ 1,
+ 255
+ ) AS rast
+END
+
+open(PRESQL, '>', $RASTERDIR . '/' . $TEST . '-pre.sql');
+print PRESQL $sql;
+close(PRESQL);
+
+open(POSTSQL, '>', $RASTERDIR . '/' . $TEST . '-post.sql');
+print POSTSQL "DROP TABLE IF EXISTS raster_outdb_template;\n";
+close(POSTSQL);
--- /dev/null
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
+DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+
+FILERASTER="$DIR/loader/testraster.tif"
+
+# special handling for msys
+CSYS=`uname -o | tr '[:upper:]' '[:lower:]'`
+if [ "$CSYS" == "msys" ]; then
+ FILERASTER=`cmd //c echo "${FILERASTER}"`
+fi
+
+SQL=" \
+DROP TABLE IF EXISTS raster_outdb_template; \
+CREATE TABLE raster_outdb_template AS \
+SELECT \
+ 1 AS rid, \
+ ST_AddBand( \
+ ST_MakeEmptyRaster(90, 90, 0., 0., 1, -1, 0, 0, 0), \
+ 1, '$FILERASTER'::text, NULL::int[] \
+ ) AS rast \
+UNION ALL \
+SELECT \
+ 2 AS rid, \
+ ST_AddBand( \
+ ST_MakeEmptyRaster(90, 90, 0., 0., 1, -1, 0, 0, 0), \
+ '$FILERASTER'::text, NULL::int[] \
+ ) AS rast \
+UNION ALL \
+SELECT \
+ 3 AS rid, \
+ ST_AddBand( \
+ ST_AddBand( \
+ ST_MakeEmptyRaster(90, 90, 0., 0., 1, -1, 0, 0, 0), \
+ 1, '8BUI', 1, 0 \
+ ), \
+ '$FILERASTER'::text, ARRAY[2]::int[] \
+ ) AS rast \
+UNION ALL \
+SELECT \
+ 4 AS rid, \
+ ST_AddBand( \
+ ST_AddBand( \
+ ST_MakeEmptyRaster(90, 90, 0., 0., 1, -1, 0, 0, 0), \
+ 1, '8BUI', 1, 0 \
+ ), \
+ '$FILERASTER'::text, ARRAY[2]::int[], \
+ 1, \
+ 255 \
+ ) AS rast \
+"
+
+echo "$SQL" > "$DIR/$TEST-pre.sql"
+
+echo "DROP TABLE IF EXISTS raster_outdb_template;" > "$DIR/$TEST-post.sql"
SELECT 'test 11.11', st_minpossiblevalue('64BF') < 0.;
DROP TABLE rt_utility_test;
+
+-----------------------------------------------------------------------
+-- st_summary()
+-----------------------------------------------------------------------
+
+SELECT ST_Summary(
+ ST_AddBand(
+ ST_AddBand(
+ ST_AddBand(
+ ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0, 0)
+ , 1, '8BUI', 1, 0
+ )
+ , 2, '32BF', 0, -9999
+ )
+ , 3, '16BSI', 0, NULL
+ )
+);
+SELECT ST_Summary(
+ ST_AddBand(
+ ST_MakeEmptyRaster(10, 10, 0, 0, 1, -1, 0, 0.00001, 0)
+ , 1, '8BUI', 1, 0
+ )
+);
+SELECT
+ rid,
+ ST_Summary(rast)
+FROM raster_outdb_template
+ORDER BY rid;
test 11.9|t
test 11.10|t
test 11.11|t
+Raster of 10x10 pixels has 3 bands and extent of BOX(0 -10,10 0)
+ band 1 of pixtype 8BUI is in-db with NODATA value of 0
+ band 2 of pixtype 32BF is in-db with NODATA value of -9999
+ band 3 of pixtype 16BSI is in-db with no NODATA value
+Skewed raster of 10x10 pixels has 1 band and extent of BOX(0 -10,10 0.0001)
+ band 1 of pixtype 8BUI is in-db with NODATA value of 0
+1|Raster of 90x90 pixels has 3 bands and extent of BOX(0 -90,90 0)
+ band 1 of pixtype 8BUI is out-db with no NODATA value
+ band 2 of pixtype 8BUI is out-db with no NODATA value
+ band 3 of pixtype 8BUI is out-db with no NODATA value
+2|Raster of 90x90 pixels has 3 bands and extent of BOX(0 -90,90 0)
+ band 1 of pixtype 8BUI is out-db with no NODATA value
+ band 2 of pixtype 8BUI is out-db with no NODATA value
+ band 3 of pixtype 8BUI is out-db with no NODATA value
+3|Raster of 90x90 pixels has 2 bands and extent of BOX(0 -90,90 0)
+ band 1 of pixtype 8BUI is in-db with NODATA value of 0
+ band 2 of pixtype 8BUI is out-db with no NODATA value
+4|Raster of 90x90 pixels has 2 bands and extent of BOX(0 -90,90 0)
+ band 1 of pixtype 8BUI is out-db with NODATA value of 255
+ band 2 of pixtype 8BUI is in-db with NODATA value of 0