From d62d4df2e7f1c2c83777aa8b2d0ae56124f410b7 Mon Sep 17 00:00:00 2001 From: Pierre Racine Date: Tue, 29 Nov 2011 16:34:48 +0000 Subject: [PATCH] Changed the note at the beginning of the file when the function is now implemented in C. git-svn-id: http://svn.osgeo.org/postgis/trunk@8255 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/scripts/plpgsql/st_asraster.sql | 22 ++++++++++++---------- raster/scripts/plpgsql/st_histogram.sql | 4 +++- raster/scripts/plpgsql/st_mapalgebra.sql | 10 ++++------ raster/scripts/plpgsql/st_reclass.sql | 13 ++++--------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/raster/scripts/plpgsql/st_asraster.sql b/raster/scripts/plpgsql/st_asraster.sql index 1cb4419bd..25b74f8b2 100644 --- a/raster/scripts/plpgsql/st_asraster.sql +++ b/raster/scripts/plpgsql/st_asraster.sql @@ -6,13 +6,15 @@ -- ---------------------------------------------------------------------- --- NOTE: The ST_AsRaster function found in this file still many improvements before being implemented in C. +-- NOTE: The ST_AsRaster() function is already implemented in C. This plpgsql script is provided only as an example. +-- Defining the plpgsql function below might overwrite the current C implementation and brake other functions dependent on it. +-- Use with caution. CREATE OR REPLACE FUNCTION ST_AsRaster(geom geometry, rast raster, pixeltype text, nodatavalue float8, val float8) RETURNS raster AS $$ DECLARE - numband int := ST_NumBands(rast); + numband int := ST_NumBands(rast); x1w float8 := ST_XMin(geom); y1w float8 := ST_YMax(geom); x2w float8 := ST_XMax(geom); @@ -27,14 +29,14 @@ CREATE OR REPLACE FUNCTION ST_AsRaster(geom geometry, rast raster, pixeltype tex newheight int := abs(y2r - y1r) + 1; newrast raster := ST_AddBand(ST_MakeEmptyRaster(newwidth, newheight, newx1w, newy1w, ST_ScaleX(rast), ST_ScaleY(rast), ST_SkewX(rast), ST_SkewY(rast), ST_SRID(rast)), pixeltype, nodatavalue, nodatavalue); BEGIN - FOR x IN 1..newwidth LOOP - FOR y IN 1..newheight LOOP - IF ST_Intersects(geom, ST_Centroid(ST_PixelAsPolygon(newrast, x, y))) THEN - newrast := ST_SetValue(newrast, 1, x, y, val); - END IF; - END LOOP; - END LOOP; - RETURN newrast; + FOR x IN 1..newwidth LOOP + FOR y IN 1..newheight LOOP + IF ST_Intersects(geom, ST_Centroid(ST_PixelAsPolygon(newrast, x, y))) THEN + newrast := ST_SetValue(newrast, 1, x, y, val); + END IF; + END LOOP; + END LOOP; + RETURN newrast; END; $$ LANGUAGE 'plpgsql'; diff --git a/raster/scripts/plpgsql/st_histogram.sql b/raster/scripts/plpgsql/st_histogram.sql index 3ca76a809..0bf902858 100644 --- a/raster/scripts/plpgsql/st_histogram.sql +++ b/raster/scripts/plpgsql/st_histogram.sql @@ -5,7 +5,9 @@ -- Copyright (c) 2009-2010 Pierre Racine -- ---------------------------------------------------------------------- --- NOTE: This function is now implemented as a C function and is provided solely as a plpgsql example. +-- NOTE: The ST_Histogram() function is already implemented in C. This plpgsql script is provided only as an example. +-- Defining the plpgsql function below might overwrite the current C implementation and brake other functions dependent on it. +-- Use with caution. ---------------------------------------------------------------------- -- _ST_Values(rast raster, band int) -- Return all rast pixels values which center are in a geometry diff --git a/raster/scripts/plpgsql/st_mapalgebra.sql b/raster/scripts/plpgsql/st_mapalgebra.sql index 5c6086903..ecca6376d 100644 --- a/raster/scripts/plpgsql/st_mapalgebra.sql +++ b/raster/scripts/plpgsql/st_mapalgebra.sql @@ -4,12 +4,10 @@ -- Copyright (c) 2009-2010 Pierre Racine -- ---------------------------------------------------------------------- - --- NOTE: The one raster version of ST_MapAlgebra found in this file is --- already implemented in C and is provided solely as a plpgsql example. --- NOTE: The ST_SameAlignment function found in this files is is ready to be being implemented in C --- NOTE: The two raster version of ST_MapAlgebra found in this file is to be replaced by the optimized version found in st_mapalgebra_optimized.sql - +-- NOTE: The ST_MapAlgebra() function is already implemented in C. This plpgsql script is provided only as an example. +-- Defining the plpgsql function below might overwrite the current C implementation and brake other functions dependent on it. +-- Use with caution. +---------------------------------------------------------------------- CREATE OR REPLACE FUNCTION ST_MinPossibleVal(pixeltype text) RETURNS float8 AS $$ diff --git a/raster/scripts/plpgsql/st_reclass.sql b/raster/scripts/plpgsql/st_reclass.sql index 48f29c619..34b41d474 100644 --- a/raster/scripts/plpgsql/st_reclass.sql +++ b/raster/scripts/plpgsql/st_reclass.sql @@ -5,15 +5,10 @@ -- Copyright (c) 2009-2010 Pierre Racine -- ---------------------------------------------------------------------- - --- 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) --- ST_MapAlgebra(rast raster, band integer, expression text, nodatavalueexpr text, pixeltype text) --- to be found in the script/plpgsql folder - +-- NOTE: The ST_Reclass() function is already implemented in C. This plpgsql script is provided only as an example. +-- Defining the plpgsql function below might overwrite the current C implementation and brake other functions dependent on it. +-- Use with caution. +---------------------------------------------------------------------- CREATE OR REPLACE FUNCTION ST_Reclass(rast raster, band int, reclassexpr text) -- 2.50.0