rt_pixtype newpixeltype;
int skipcomputation = 0;
char strnewval[50];
- int count = 0;
int len = 0;
int ret = -1;
TupleDesc tupdesc;
for (x = 0; x < width; x++) {
for(y = 0; y < height; y++) {
+ char *tmp;
ret = rt_band_get_pixel(band, x, y, &r);
/**
**/
if (ret != -1 && FLT_NEQ(r, newnodatavalue)) {
if (skipcomputation == 0) {
- sprintf(strnewval, "%f", r);
if (initexpr != NULL) {
- count = 0;
- newexpr = rtpg_strreplace(initexpr, "RAST", strnewval, &count);
+ sprintf(strnewval, "%d", x+1);
+ newexpr = rtpg_strreplace(initexpr, "RAST.X", strnewval, NULL);
+ sprintf(strnewval, "%d", y+1);
+ tmp = rtpg_strreplace(newexpr, "RAST.Y", strnewval, NULL);
+ pfree(newexpr); newexpr=tmp;
+ sprintf(strnewval, "%f", r);
+ tmp = rtpg_strreplace(newexpr, "RAST", strnewval, NULL);
+ pfree(newexpr); newexpr=tmp;
POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: (%dx%d), "
"r = %s, newexpr = %s",
SELECT ST_MapAlgebraExpr(NULL, 1, NULL, 'rast + 20', 2) IS NULL FROM ST_TestRaster(0, 0, -1) rast;
-- Test empty raster
-SELECT ST_IsEmpty(ST_MapAlgebraExpr(ST_MakeEmptyRaster(0, 10, 0, 0, 1, 1, 1, 1, -1), 1, NULL, 'rast + 20', 2));
+SELECT 'T1', ST_IsEmpty(ST_MapAlgebraExpr(ST_MakeEmptyRaster(0, 10, 0, 0, 1, 1, 1, 1, -1), 1, NULL, 'rast + 20', 2));
-- Test hasnoband raster
-SELECT ST_HasNoBand(ST_MapAlgebraExpr(ST_MakeEmptyRaster(10, 10, 0, 0, 1, 1, 1, 1, -1), 1, NULL, 'rast + 20', 2));
+SELECT 'T2', ST_HasNoBand(ST_MapAlgebraExpr(ST_MakeEmptyRaster(10, 10, 0, 0, 1, 1, 1, 1, -1), 1, NULL, 'rast + 20', 2));
-- Test hasnodata value
-SELECT ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(ST_SetBandNoDataValue(rast, NULL), 1, NULL, 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, -1) rast;
+SELECT 'T3', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(ST_SetBandNoDataValue(rast, NULL), 1, NULL, 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, -1) rast;
-- Test nodata value
-SELECT ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, NULL, 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, -1) rast;
+SELECT 'T4', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, NULL, 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, -1) rast;
-- Test 'rast' expression
-SELECT ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, NULL, 'rast', 2), 1, 1) FROM ST_TestRaster(0, 0, -1) rast;
-SELECT ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(ST_SetBandNoDataValue(rast, NULL), 1, NULL, 'rast'), 1, 1) FROM ST_TestRaster(0, 0, -1) rast;
+SELECT 'T5', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, NULL, 'rast', 2), 1, 1) FROM ST_TestRaster(0, 0, -1) rast;
+SELECT 'T6', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(ST_SetBandNoDataValue(rast, NULL), 1, NULL, 'rast'), 1, 1) FROM ST_TestRaster(0, 0, -1) rast;
-- Test pixeltype
-SELECT ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, '4BUI', 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, 100) rast;
-SELECT ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, '4BUId', 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, 100) rast;
-SELECT ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, '2BUI', 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, 101) rast;
+SELECT 'T7', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, '4BUI', 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, 100) rast;
+SELECT 'T8', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, '4BUId', 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, 100) rast;
+SELECT 'T9', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, '2BUI', 'rast + 20', 2), 1, 1) FROM ST_TestRaster(0, 0, 101) rast;
+
+-- Test 'rast.x' and 'rast.y' substitutions expression
+SELECT 'T10.'||x||'.'||y, ST_Value(rast, x, y),
+ ST_Value(ST_MapAlgebraExpr(rast, 1, NULL, 'round(rast*rast.x/rast.y+rast)'), x, y)
+FROM ST_TestRaster(0, 0, 10) rast,
+ generate_series(6, 8) as x,
+ generate_series(2, 4) as y
+ORDER BY x, y;