From: Regina Obe Date: Wed, 14 Apr 2010 12:52:02 +0000 (+0000) Subject: Provide yet more common use case examples of ST_Value X-Git-Tag: 2.0.0alpha1~3034 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d7bfed76c2906f1bab39e748fd3b6d4a4d4e5e9;p=postgis Provide yet more common use case examples of ST_Value git-svn-id: http://svn.osgeo.org/postgis/trunk@5545 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/reference_wktraster.xml b/doc/reference_wktraster.xml index 7df433198..9fa00f3cf 100644 --- a/doc/reference_wktraster.xml +++ b/doc/reference_wktraster.xml @@ -1010,6 +1010,18 @@ FROM dummy_rast; Description Returns the value of a given band in a given columnx, rowy pixel. Band numbers start at 1. + Note that although the X and Ys of these are not in coordinates of the spatial system, + you can get that by the following relationship. + Coordinate upper left of a row column + is: + ST_SetSRID(ST_Point(ST_UpperLeftX(rast) + ST_PixelSizeX(rast)*columnx, ST_UpperRightY(rast) + ST_PixelSizeX(rast)*columny), ST_SRID(rast)) + + If you want the pixel box instead of the upper left point, you can use the ST_MakeEnvelop function and + translate it every x,y. + Also note that many of these examples particular the intersection example can be more + simply done with the planned functions that are not currently available. + + @@ -1046,12 +1058,68 @@ WHERE rid = 2 AND x <= ST_Width(rast) AND y <= ST_Height(rast); : : - + + +--- Get all values in bands 1,2,3 of each pixel same as above but returning the upper left point point of each pixel -- +SELECT ST_AsText(ST_SetSRID( + ST_Point(ST_UpperLeftX(rast) + ST_PixelSizeX(rast)*x, + ST_UpperLeftY(rast) + ST_PixelSizeX(rast)*y), + ST_SRID(rast))) As uplpt + , ST_Value(rast, 1, x, y) As b1val, + ST_Value(rast, 2, x, y) As b2val, ST_Value(rast, 3, x, y) As b3val +FROM dummy_rast CROSS JOIN +generate_series(1,1000) As x CROSS JOIN generate_series(1,1000) As y +WHERE rid = 2 AND x <= ST_Width(rast) AND y <= ST_Height(rast); + + uplpt | b1val | b2val | b3val +-----------------------------+-------+-------+------- + POINT(3427929.25 5793245.5) | 253 | 78 | 70 + POINT(3427929.25 5793247) | 253 | 96 | 80 + POINT(3427929.25 5793248.5) | 250 | 99 | 90 +: + + +--- Get a polygon formed by union of all pixels + that fall in a particular value range and intersect particular polygon -- +SELECT ST_AsText(ST_Union(pixpolyg)) As shadow +FROM (SELECT ST_Translate(ST_MakeEnvelope( + ST_UpperLeftX(rast), ST_UpperLeftY(rast), + ST_UpperLeftX(rast) + ST_PixelSizeX(rast), + ST_UpperLeftY(rast) + ST_PixelSizeY(rast), 0 + ), ST_PixelSizeX(rast)*x, ST_PixelSizeY(rast)*y + ) As pixpolyg, ST_Value(rast, 1, x, y) As b1val + FROM dummy_rast CROSS JOIN +generate_series(1,1000) As x CROSS JOIN generate_series(1,1000) As y +WHERE rid = 2 + AND x <= ST_Width(rast) AND y <= ST_Height(rast)) As foo +WHERE + ST_Intersects( + pixpolyg, + ST_GeomFromText('POLYGON ((3427935.6902608695 5793250.889478261, + 3427932.0770434784 5793251.682173912, + 3427931.9295652173 5793250.400956522, + 3427933.0576086957 5793248.985, 3427933.518478261 5793249.192391304, + 3427934.611826087 5793248.999913043, 3427935.6902608695 5793250.889478261))',0) + ) AND b1val != 254; + + shadow +------------------------------------------------------------------------------------ + MULTIPOLYGON(((3427933.75 5793248.5,3427933.75 5793250,3427935.25 5793250, + 3427935.25 5793248.5,3427933.75 5793248.5)), + ((3427930.75 5793250,3427930.75 5793251.5,3427930.75 5793253,3427932.25 5793253, +3427932.25 5793251.5,3427932.25 5793250,3427930.75 5793250)), +((3427935.25 5793250,3427935.25 5793251.5,3427936.75 5793251.5, +3427936.75 5793250,3427935.25 5793250))) + See Also - + , , + , , , + , , , + , , , +