From 66c30d1e39528ea072751dad611b50a99de8e83a Mon Sep 17 00:00:00 2001 From: Pierre Racine Date: Mon, 28 May 2012 19:21:51 +0000 Subject: [PATCH] Replace the x, y iteration with a call to ST_MapAlgebraExpr() now that it supports [rast.x] and [rast.y]. Much faster! This is not (yet) part of rtpostgis.sql. Should be in 2.1. git-svn-id: http://svn.osgeo.org/postgis/trunk@9825 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/scripts/plpgsql/st_createindexraster.sql | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/raster/scripts/plpgsql/st_createindexraster.sql b/raster/scripts/plpgsql/st_createindexraster.sql index 43ab1c6b7..3e20193dd 100644 --- a/raster/scripts/plpgsql/st_createindexraster.sql +++ b/raster/scripts/plpgsql/st_createindexraster.sql @@ -46,20 +46,12 @@ BEGIN IF colincx <= (h - 1) * rowincy THEN RAISE EXCEPTION 'Column increment (now %) must be greater than the number of index on one column (now % pixel x % = %)...', colincx, h - 1, rowincy, (h - 1) * rowincy; END IF; - FOR x IN 1..w LOOP - FOR y IN 1..h LOOP - newraster := ST_SetValue(newraster, x, y, abs(x - xdir) * colincx + abs(y - (h ^ ((abs(x - xdir + 1) % 2) | rsflag # ydflag))::int) * rowincy + newstartvalue); - END LOOP; - END LOOP; + newraster = ST_SetBandNodataValue(ST_MapAlgebraExpr(newraster, pixeltype, 'abs([rast.x] - ' || xdir::text || ') * ' || colincx::text || ' + abs([rast.y] - (' || h::text || ' ^ ((abs([rast.x] - ' || xdir::text || ' + 1) % 2) | ' || rsflag::text || ' # ' || ydflag::text || '))::int) * ' || rowincy::text || ' + ' || newstartvalue::text), ST_BandNodataValue(newraster)); ELSE IF rowincx <= (w - 1) * colincy THEN RAISE EXCEPTION 'Row increment (now %) must be greater than the number of index on one row (now % pixel x % = %)...', rowincx, w - 1, colincy, (w - 1) * colincy; END IF; - FOR x IN 1..w LOOP - FOR y IN 1..h LOOP - newraster := ST_SetValue(newraster, x, y, abs(x - (w ^ ((abs(y - ydir + 1) % 2) | rsflag # xdflag))::int) * colincy + abs(y - ydir) * rowincx + newstartvalue); - END LOOP; - END LOOP; + newraster = ST_SetBandNodataValue(ST_MapAlgebraExpr(newraster, pixeltype, 'abs([rast.x] - (' || w::text || ' ^ ((abs([rast.y] - ' || ydir::text || ' + 1) % 2) | ' || rsflag::text || ' # ' || xdflag::text || '))::int) * ' || colincy::text || ' + abs([rast.y] - ' || ydir::text || ') * ' || rowincx::text || ' + ' || newstartvalue::text), ST_BandNodataValue(newraster)); END IF; RETURN newraster; END; -- 2.40.0