[postgis-devel] [PostGIS] #1639: [raster] MapAlgebraExpr can't handle conditions

PostGIS trac at osgeo.org
Thu Mar 1 07:20:07 PST 2012


#1639: [raster] MapAlgebraExpr can't handle conditions
---------------------+------------------------------------------------------
 Reporter:  nicklas  |       Owner:  pracine      
     Type:  defect   |      Status:  new          
 Priority:  high     |   Milestone:  PostGIS 2.0.0
Component:  raster   |     Version:  trunk        
 Keywords:           |  
---------------------+------------------------------------------------------

Comment(by dustymugs):

 Strange that this isn't working.  Concise example:

 {{{
 DROP TYPE IF EXISTS cellset CASCADE;
 CREATE TYPE cellset AS (
         x integer,
         y integer,
         value double precision
 );

 CREATE OR REPLACE FUNCTION dump_cells(rast raster, band int DEFAULT 1)
         RETURNS SETOF cellset
         AS $$
         DECLARE
                 r cellset%rowtype;
                 rows int;
                 cols int;
         BEGIN
                 SELECT width, height INTO rows, cols FROM
 ST_Metadata(rast);

                 FOR r IN SELECT x, y, ST_Value(rast, band, x, y)
                         FROM generate_series(1, rows) AS x
                         CROSS JOIN generate_series(1, cols) AS y
                         LOOP

                         RETURN NEXT r;

                 END LOOP;
         END;
         $$
         LANGUAGE 'plpgsql';

 WITH foo AS (
         SELECT
                 ST_AddBand(
                         ST_MakeEmptyRaster(5, 5, 0, 0, 1, -1, 0, 0, 0)
                         , '8BUI'::text, 1, 0
                 )
         AS rast
 )
 SELECT dump_cells(rast)
 FROM (
         SELECT
                 ST_MapAlgebraExpr(rast, '8BUI', 'CASE WHEN [rast.x] % 2 =
 0 AND [rast.y] % 2 = 0 THEN NULL ELSE 128. END') AS rast
         FROM foo
 ) bar
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/1639#comment:3>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-devel mailing list