[postgis-users] ST_MapAlgebraExpr(rast,rast) Error

Andreas Forø Tollefsen andreasft at gmail.com
Wed Feb 8 02:38:43 PST 2012


Hi,

Revision 9096.

I am trying to get the mean raster pixel value inside my polygon.
Previously i have been using this query:
SELECT
a.gid ,
(ST_SummaryStats((ST_Union(ST_MapAlgebraExpr(ST_AsRaster(a.cell,
b.rast, '32BF'), b.rast, 'rast2', '32BF','INTERSECTION','rast2',
'rast1'))), false)).mean As avgmnt
FROM
priogrid a LEFT JOIN
access b
    ON ST_Intersects(a.cell, b.rast)
GROUP BY a.gid
ORDER BY a.gid;

This now return error:
NOTICE:  geometry_gist_joinsel called with incorrect join type
ERROR:  column "rast2" does not exist
LINE 1: SELECT (rast2)::double precision
                ^
QUERY:  SELECT (rast2)::double precision
********** Error **********
ERROR: column "rast2" does not exist
SQL state: 42703

The same is the case if running the example 2 (really exampe 1?) from:
http://www.postgis.org/documentation/manual-svn/RT_ST_MapAlgebraExpr2.html

--Create a cool set of rasters --
DROP TABLE IF EXISTS fun_shapes;
CREATE TABLE fun_shapes(rid serial PRIMARY KEY, fun_name text, rast raster);

-- Insert some cool shapes around Boston in Massachusetts state plane meters --
INSERT INTO fun_shapes(fun_name, rast)
VALUES ('ref', ST_AsRaster(ST_MakeEnvelope(235229, 899970, 237229,
901930,26986),200,200,'8BUI',0,0));

INSERT INTO fun_shapes(fun_name,rast)
WITH ref(rast) AS (SELECT rast FROM fun_shapes WHERE fun_name = 'ref' )
SELECT 'area' AS fun_name,
ST_AsRaster(ST_Buffer(ST_SetSRID(ST_Point(236229, 900930),26986),
1000),
			ref.rast,'8BUI', 10, 0) As rast
FROM ref
UNION ALL
SELECT 'rand bubbles',
		 	ST_AsRaster(
		 	(SELECT ST_Collect(geom)
	FROM (SELECT ST_Buffer(ST_SetSRID(ST_Point(236229 + i*random()*100,
900930 + j*random()*100),26986), random()*20) As geom
			FROM generate_series(1,10) As i, generate_series(1,10) As j
			) As foo ), ref.rast,'8BUI', 200, 0)
FROM ref;

--map them -
SELECT  ST_MapAlgebraExpr(
		area.rast, bub.rast, 'rast2', '8BUI', 'INTERSECTION', 'rast2',
'rast1') As interrast,
		ST_MapAlgebraExpr(
			area.rast, bub.rast, 'rast2', '8BUI', 'UNION', 'rast2', 'rast1') As unionrast
FROM
  (SELECT rast FROM fun_shapes WHERE
 fun_name = 'area') As area
CROSS JOIN  (SELECT rast
FROM fun_shapes WHERE
 fun_name = 'rand bubbles') As bub


Returns:

NOTICE:  CREATE TABLE will create implicit sequence
"fun_shapes_rid_seq" for serial column "fun_shapes.rid"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"fun_shapes_pkey" for table "fun_shapes"
ERROR:  column "rast2" does not exist
LINE 1: SELECT (rast2)::double precision
                ^
QUERY:  SELECT (rast2)::double precision

********** Error **********

ERROR: column "rast2" does not exist
SQL state: 42703

Any ideas?

Andreas



More information about the postgis-users mailing list