From: Bborie Park Date: Fri, 26 Apr 2013 14:47:40 +0000 (+0000) Subject: Added ST_Summary(raster). Ticket #2280 X-Git-Tag: 2.1.0beta2~81 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af3836ec5231089a85915ba74adf2f271d45ef22;p=postgis Added ST_Summary(raster). Ticket #2280 git-svn-id: http://svn.osgeo.org/postgis/trunk@11326 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 3c5cc4a9d..1b82c7e3b 100644 --- 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 * diff --git a/doc/reference_raster.xml b/doc/reference_raster.xml index e04889484..38bbb2240 100644 --- a/doc/reference_raster.xml +++ b/doc/reference_raster.xml @@ -1986,7 +1986,54 @@ FROM dummy_rast; + + + + ST_IsEmpty + Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false. + + + + + boolean ST_IsEmpty + raster rast + + + + + + Description + + Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false. + + Availability: 2.0.0 + + + + Examples + + 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 | + + + + + + + See Also + + + + ST_MetaData @@ -2719,6 +2766,66 @@ srid , + + + + ST_Summary + Returns a text summary of the contents of the raster. + + + + + + text ST_Summary + raster rast + + + + + + Description + + Returns a text summary of the contents of the raster. + + Availability: 2.1.0 + + + + Examples + +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) + + + + + See Also + + , + , + + + + + @@ -3036,52 +3143,6 @@ FROM dummy_rast; - - - ST_IsEmpty - Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false. - - - - - - boolean ST_IsEmpty - raster rast - - - - - - Description - - Returns true if the raster is empty (width = 0 and height = 0). Otherwise, returns false. - - Availability: 2.0.0 - - - - Examples - - 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 | - - - - - - - See Also - - - diff --git a/raster/rt_pg/rtpostgis.sql.in b/raster/rt_pg/rtpostgis.sql.in index 691283df4..66e605c0b 100644 --- a/raster/rt_pg/rtpostgis.sql.in +++ b/raster/rt_pg/rtpostgis.sql.in @@ -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 index 000000000..a48c932ff --- /dev/null +++ b/raster/test/regress/rt_utility-post.pl @@ -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 index 000000000..e17075809 --- /dev/null +++ b/raster/test/regress/rt_utility-post.sh @@ -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 index 000000000..772877df5 --- /dev/null +++ b/raster/test/regress/rt_utility-pre.pl @@ -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 index 000000000..6102ed058 --- /dev/null +++ b/raster/test/regress/rt_utility-pre.sh @@ -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" diff --git a/raster/test/regress/rt_utility.sql b/raster/test/regress/rt_utility.sql index 813822d3b..f1c11ca2e 100644 --- a/raster/test/regress/rt_utility.sql +++ b/raster/test/regress/rt_utility.sql @@ -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; diff --git a/raster/test/regress/rt_utility_expected b/raster/test/regress/rt_utility_expected index 6b9155b54..ec528479b 100644 --- a/raster/test/regress/rt_utility_expected +++ b/raster/test/regress/rt_utility_expected @@ -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