]> granicus.if.org Git - postgis/commitdiff
Added a note saying that those function now have a C implementation. Many TABs conver...
authorPierre Racine <Pierre.Racine@sbf.ulaval.ca>
Fri, 22 Jul 2011 20:20:55 +0000 (20:20 +0000)
committerPierre Racine <Pierre.Racine@sbf.ulaval.ca>
Fri, 22 Jul 2011 20:20:55 +0000 (20:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7664 b70326c6-7e19-0410-871a-916f4a2858ee

raster/scripts/plpgsql/st_histogram.sql
raster/scripts/plpgsql/st_reclass.sql

index ff760a0818fb63d7c47ff65502c1d05cd9abf108..3ca76a809cbcc29a34825fc6bbc893cc15b040ca 100644 (file)
@@ -1,4 +1,12 @@
 ----------------------------------------------------------------------
+--
+-- $Id: st_histogram.sql 6127 2010-10-25 16:06:00Z jorgearevalo $
+--
+-- Copyright (c) 2009-2010 Pierre Racine <pierre.racine@sbf.ulaval.ca>
+--
+----------------------------------------------------------------------
+-- NOTE: This function is now implemented as a C function and is provided solely as a plpgsql example.
+----------------------------------------------------------------------
 -- _ST_Values(rast raster, band int)
 -- Return all rast pixels values which center are in a geometry
 -- Values are returned as groups of identical adjacent values (value, count) 
index 9db8adcf3eeec1585e3a2bb11ba4a15ba350a8b6..48f29c6194333c4e0c224788ae5a6418bb0709e1 100644 (file)
@@ -6,6 +6,8 @@
 --
 ----------------------------------------------------------------------
 
+-- NOTE: This function is now implemented as a C function and is provided solely as a plpgsql example.
+
 -- Note: this script is dependent on 
 --   ST_DeleteBand(rast raster, band int) 
 --   ST_AddBand(newrast, rast, b, NULL)
 -- to be found in the script/plpgsql folder
 
 CREATE OR REPLACE FUNCTION ST_Reclass(rast raster,
-                                     band int,
+                      band int,
                                       reclassexpr text) 
     RETURNS raster AS 
     $$
     DECLARE
-       -- Create a new raster without the band we will reclassify
-       newrast raster := ST_DeleteBand(rast, band);
+    -- Create a new raster without the band we will reclassify
+        newrast raster := ST_DeleteBand(rast, band);
 
-       -- Determine the nodata value
-       nodataval float8 := ST_BandNodataValue(rast, band);
+    -- Determine the nodata value
+        nodataval float8 := ST_BandNodataValue(rast, band);
 
-       -- First parse of the reclass expression. Split the reclass classes into an array.
-       reclarray text[] := string_to_array(reclassexpr, '|');
+    -- First parse of the reclass expression. Split the reclass classes into an array.
+        reclarray text[] := string_to_array(reclassexpr, '|');
 
-       -- Determine the number of classes.
-       nbreclassstr int := array_length(reclarray, 1);
+        -- Determine the number of classes.
+        nbreclassstr int := array_length(reclarray, 1);
 
-       -- Initialise the MapAlgebra expression
-       maexpr text := 'CASE ';
+        -- Initialise the MapAlgebra expression
+        maexpr text := 'CASE ';
 
-       -- Temporary container for the two part of the class being parsed.
-       reclassstr text[];
+        -- Temporary container for the two part of the class being parsed.
+        reclassstr text[];
 
-       -- Temporary array containing the splited class.
-       fromstr text[];
+        -- Temporary array containing the splited class.
+        fromstr text[];
 
-       i int;
+        i int;
     BEGIN
-       -- For each classes
-       FOR i IN 1..nbreclassstr LOOP
-               -- Split the class into an array of classes.
-               reclassstr := string_to_array(reclarray[i], ':');
-               IF array_length(reclassstr, 1) < 2 THEN
-                       RAISE EXCEPTION 'ST_Reclass: Invalid reclassification class: "%". Aborting', reclarray[i];
-               END IF;
-               -- Split the range to reclassify into two
-               fromstr := string_to_array(reclassstr[1], '-');
-               -- Replace nodata with the nodata value
-               IF upper(reclassstr[2]) = 'NODATA' THEN
-                       reclassstr[2] = nodataval::text;
-               END IF;
-               -- Build the maexpr expression
-               IF fromstr[2] IS NULL OR fromstr[2] = ''  THEN
-                       maexpr := maexpr || ' WHEN ' || fromstr[1] || ' = rast THEN ' || reclassstr[2] || ' ';
-               ELSE
-                       maexpr := maexpr || ' WHEN ' || fromstr[1] || ' <= rast AND rast < ' || fromstr[2] || ' THEN ' || reclassstr[2] || ' ';
-               END IF;
-       END LOOP;
-       maexpr := maexpr || 'ELSE rast END';
-       newrast := ST_AddBand(rast, ST_MapAlgebra(rast, band, maexpr), 1, band);
-       RETURN newrast;
+    -- For each classes
+        FOR i IN 1..nbreclassstr LOOP
+        -- Split the class into an array of classes.
+            reclassstr := string_to_array(reclarray[i], ':');
+            IF array_length(reclassstr, 1) < 2 THEN
+            RAISE EXCEPTION 'ST_Reclass: Invalid reclassification class: "%". Aborting', reclarray[i];
+            END IF;
+            -- Split the range to reclassify into two
+            fromstr := string_to_array(reclassstr[1], '-');
+            -- Replace nodata with the nodata value
+            IF upper(reclassstr[2]) = 'NODATA' THEN
+                reclassstr[2] = nodataval::text;
+            END IF;
+            -- Build the maexpr expression
+            IF fromstr[2] IS NULL OR fromstr[2] = ''  THEN
+            maexpr := maexpr || ' WHEN ' || fromstr[1] || ' = rast THEN ' || reclassstr[2] || ' ';
+        ELSE
+            maexpr := maexpr || ' WHEN ' || fromstr[1] || ' <= rast AND rast < ' || fromstr[2] || ' THEN ' || reclassstr[2] || ' ';
+        END IF;
+        END LOOP;
+        maexpr := maexpr || 'ELSE rast END';
+        newrast := ST_AddBand(rast, ST_MapAlgebra(rast, band, maexpr), 1, band);
+    RETURN newrast;
     END;
     $$
     LANGUAGE 'plpgsql';