From: Regina Obe Date: Thu, 2 Jun 2011 21:13:47 +0000 (+0000) Subject: example how to use variadic version of ST_Reclass raster function, finish off reclass... X-Git-Tag: 2.0.0alpha1~1504 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e04d0404aad50ac8298e684574559e14504da598;p=postgis example how to use variadic version of ST_Reclass raster function, finish off reclassarg type description, add summarystats type git-svn-id: http://svn.osgeo.org/postgis/trunk@7310 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/reference_raster.xml b/doc/reference_raster.xml index e8e5d59be..f37f9cf84 100644 --- a/doc/reference_raster.xml +++ b/doc/reference_raster.xml @@ -344,23 +344,72 @@ VALUES (1, reclassexpr text - Mathemetical expression defining how to map band to new band. + range expression consisting of - (define range) and : to define mapping that defines how to map old band values to new band values. ( means >, ) means less than, ] < or equal, [ means > or equal pixeltype text One of defined pixel types as described in + + nodataval double precision + Value to treat as no data. For image outputs that support transparency, these will be blank. + Example: Reclassify band 2 as an 8BUI where 255 is nodata value SELECT ROW(2, '0-100:1-10, 101-500:11-150,501 - 10000: 151-254', '8BUI', 255)::reclassarg; + + + Example: Reclassify band 1 as an 1BB and no nodata value defined + SELECT ROW(2, '0-100]:0, (100-255:1', '1BB', NULL)::reclassarg; See Also + + + + summarystats + A composite type used as output the ST_SummaryStats function. + + + Description + A composite type used as output the ST_SummaryStats function. Note that depending on exclude_nodata_value of function, may or may not contain nodata pixels. + + + count bigint + count of pixels in raster band. Depending on arguments may or many not include nodata pixel values. + + + sum double precision + sum of all pixel values in band + + + mean double precision + Mean of pixel values + + + stddev double precision + Standard deviation of pixel values. + + + min double precision + Minimum pixel value + + + max double precision + Maximum pixel value + + + + + See Also + + + Raster Management Functions @@ -3524,7 +3573,7 @@ FROM (SELECT band, ST_SummaryStats('o_4_boston','rast', band,true,0.25) As stats See Also - + , @@ -4534,19 +4583,19 @@ POLYGON((3427928 5793243.85,3427928 5793243.8,3427928 5793243.75,3427927.85 5793 - Examples + Examples Basic Create a new raster from the original where band 2 is converted from 8BUI to 4BUI and all values from 251-255 are set to nodata value. ALTER TABLE dummy_rast ADD COLUMN reclass_rast raster; UPDATE dummy_rast SET reclass_rast = ST_Reclass(rast,2,'0-87:1-10, 88-100:11-15, 101-254:0-0', '4BUI',0) WHERE rid = 2; -SELECT i as row, j as col, ST_Value(rast,2,i,j) As origval, +SELECT i as col, j as row, ST_Value(rast,2,i,j) As origval, ST_Value(reclass_rast, 2, i, j) As reclassval, ST_Value(reclass_rast, 2, i, j, false) As reclassval_include_nodata FROM dummy_rast CROSS JOIN generate_series(1, 3) AS i CROSS JOIN generate_series(1,3) AS j WHERE rid = 2; - row | col | origval | reclassval | reclassval_include_nodata + col | row | origval | reclassval | reclassval_include_nodata -----+-----+---------+------------+--------------------------- 1 | 1 | 78 | 9 | 9 2 | 1 | 98 | 14 | 14 @@ -4559,10 +4608,41 @@ WHERE rid = 2; 3 | 3 | 169 | | 0 + + + Example: Advanced using multiple reclassargs + + Create a new raster from the original where band 1,2,3 is converted to 1BB,4BUI, 4BUI respectively and reclassified. + Note this uses the variadic reclassarg argument which can take as input an indefinite number of reclassargs (theoretically as many bands as you have) + UPDATE dummy_rast SET reclass_rast = + ST_Reclass(rast, + ROW(2,'0-87]:1-10, (87-100]:11-15, (101-254]:0-0', '4BUI',NULL)::reclassarg, + ROW(1,'0-253]:1, 254:0', '1BB', NULL)::reclassarg, + ROW(3,'0-70]:1, (70-86:2, [86-150):3, [150-255:4', '4BUI', NULL)::reclassarg + ) WHERE rid = 2; + +SELECT i as col, j as row,ST_Value(rast,1,i,j) As ov1, ST_Value(reclass_rast, 1, i, j) As rv1, + ST_Value(rast,2,i,j) As ov2, ST_Value(reclass_rast, 2, i, j) As rv2, + ST_Value(rast,3,i,j) As ov3, ST_Value(reclass_rast, 3, i, j) As rv3 +FROM dummy_rast CROSS JOIN generate_series(1, 3) AS i CROSS JOIN generate_series(1,3) AS j +WHERE rid = 2; + +col | row | ov1 | rv1 | ov2 | rv2 | ov3 | rv3 +----+-----+-----+-----+-----+-----+-----+----- + 1 | 1 | 253 | 1 | 78 | 9 | 70 | 1 + 2 | 1 | 254 | 0 | 98 | 14 | 86 | 3 + 3 | 1 | 253 | 1 | 122 | 0 | 100 | 3 + 1 | 2 | 253 | 1 | 96 | 14 | 80 | 2 + 2 | 2 | 254 | 0 | 118 | 0 | 108 | 3 + 3 | 2 | 254 | 0 | 180 | 0 | 162 | 4 + 1 | 3 | 250 | 1 | 99 | 15 | 90 | 3 + 2 | 3 | 254 | 0 | 112 | 0 | 108 | 3 + 3 | 3 | 254 | 0 | 169 | 0 | 175 | 4 + See Also - , + , ,