]> granicus.if.org Git - postgis/commitdiff
Copied from ST_MapAlgebra.sql
authorPierre Racine <Pierre.Racine@sbf.ulaval.ca>
Thu, 1 Dec 2011 01:11:28 +0000 (01:11 +0000)
committerPierre Racine <Pierre.Racine@sbf.ulaval.ca>
Thu, 1 Dec 2011 01:11:28 +0000 (01:11 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8272 b70326c6-7e19-0410-871a-916f4a2858ee

raster/scripts/plpgsql/st_minpossibleval.sql [new file with mode: 0644]

diff --git a/raster/scripts/plpgsql/st_minpossibleval.sql b/raster/scripts/plpgsql/st_minpossibleval.sql
new file mode 100644 (file)
index 0000000..5af03a5
--- /dev/null
@@ -0,0 +1,29 @@
+-----------------------------------------------------------------------\r
+-- ST_MinPossibleVal\r
+-- Return the smallest value for a given pixeltyp. \r
+-- Should be called like this:\r
+-- SELECT ST_MinPossibleVal(ST_BandPixelType(rast, band))\r
+-----------------------------------------------------------------------\r
+CREATE OR REPLACE FUNCTION ST_MinPossibleVal(pixeltype text)\r
+    RETURNS float8 AS\r
+    $$\r
+    DECLARE\r
+        newval int := 0;\r
+    BEGIN\r
+        newval := CASE \r
+            WHEN pixeltype = '1BB' THEN 0\r
+            WHEN pixeltype = '2BUI' THEN 0\r
+            WHEN pixeltype = '4BUI' THEN 0\r
+            WHEN pixeltype = '8BUI' THEN 0\r
+            WHEN pixeltype = '8BSI' THEN -128\r
+            WHEN pixeltype = '16BUI' THEN 0\r
+            WHEN pixeltype = '16BSI' THEN -32768\r
+            WHEN pixeltype = '32BUI' THEN 0\r
+            WHEN pixeltype = '32BSI' THEN -2147483648\r
+            WHEN pixeltype = '32BF' THEN -2147483648 -- Could not find a function returning the smallest real yet\r
+            WHEN pixeltype = '64BF' THEN -2147483648 -- Could not find a function returning the smallest float8 yet\r
+        END;\r
+        RETURN newval;\r
+    END;\r
+    $$\r
+    LANGUAGE 'plpgsql';\r