]> granicus.if.org Git - postgis/commitdiff
Added ST_Summary(raster). Ticket #2280
authorBborie Park <bkpark at ucdavis.edu>
Fri, 26 Apr 2013 14:47:40 +0000 (14:47 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Fri, 26 Apr 2013 14:47:40 +0000 (14:47 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@11326 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
doc/reference_raster.xml
raster/rt_pg/rtpostgis.sql.in
raster/test/regress/rt_utility-post.pl [new file with mode: 0755]
raster/test/regress/rt_utility-post.sh [new file with mode: 0755]
raster/test/regress/rt_utility-pre.pl [new file with mode: 0755]
raster/test/regress/rt_utility-pre.sh [new file with mode: 0755]
raster/test/regress/rt_utility.sql
raster/test/regress/rt_utility_expected

diff --git a/NEWS b/NEWS
index 3c5cc4a9dd38857a01270b1c2e624734cecddf77..1b82c7e3b07afa6593ae0af94441e428403f14e6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -80,6 +80,7 @@ PostGIS 2.1.0
   - #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 *
 
index e048894844b2701bf2f9242796ac1d086b8437fc..38bbb2240d161552e1dc0747c43eef21fb6ac363 100644 (file)
@@ -1986,7 +1986,54 @@ FROM dummy_rast;
                                <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>
@@ -2719,6 +2766,66 @@ srid
                                <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>
@@ -3036,52 +3143,6 @@ FROM dummy_rast;
                        </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">
index 691283df4e7dccb24b829780e2e805f7ad5412d3..66e605c0b4b5bf0aa974875a97ea7cb00b523ec8 100644 (file)
@@ -212,6 +212,59 @@ CREATE OR REPLACE FUNCTION st_metadata(
        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
 -----------------------------------------------------------------------
diff --git a/raster/test/regress/rt_utility-post.pl b/raster/test/regress/rt_utility-post.pl
new file mode 100755 (executable)
index 0000000..a48c932
--- /dev/null
@@ -0,0 +1,8 @@
+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';
diff --git a/raster/test/regress/rt_utility-post.sh b/raster/test/regress/rt_utility-post.sh
new file mode 100755 (executable)
index 0000000..e170758
--- /dev/null
@@ -0,0 +1,6 @@
+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"
diff --git a/raster/test/regress/rt_utility-pre.pl b/raster/test/regress/rt_utility-pre.pl
new file mode 100755 (executable)
index 0000000..772877d
--- /dev/null
@@ -0,0 +1,61 @@
+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);
diff --git a/raster/test/regress/rt_utility-pre.sh b/raster/test/regress/rt_utility-pre.sh
new file mode 100755 (executable)
index 0000000..6102ed0
--- /dev/null
@@ -0,0 +1,55 @@
+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"
index 813822d3b5084179e044fadf794d4ffb67f1ccce..f1c11ca2e8ded9c6dfdf4171487289e8707ddd91 100644 (file)
@@ -394,3 +394,31 @@ SELECT 'test 11.10', st_minpossiblevalue('32BF') < 0.;
 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;
index 6b9155b543b4a0d6fd6769357712f246a463589f..ec528479ba81e8c64d9a436748b09dc3735f417f 100644 (file)
@@ -31,3 +31,23 @@ test 11.8|t
 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