Hi,<div><br></div><div>I am trying to iterate over a raster, extract World2RasterCoordX/Y and Band Values using the following function:</div><div><br></div><div><div>Create or replace function extract_as_text(rast raster) returns text as</div>
<div>$$</div><div>Declare</div><div> i int;</div><div> j int;</div><div>rast raster;</div><div><br></div><div>Begin</div><div>for i in 1..2048 loop --dim x </div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for j in 1..1536 loop -- dim y</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>select ST_world2rastercoordx(rast, i, j) as xcoord,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>St_world2rastercoordy(rast, i, j) as ycoord,</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>ST_value(rast,1, i, j) as R,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ST_value(rast, 2, i, j) as G,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ST_value(rast, 3, i, j) as B</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>from rbike_all;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>End loop;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>End loop;</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>return xcoord,ycoord,R,G,B; <- this part is probably not right either - should perhaps just say text</div><div>end;</div><div>$$</div><div>Language 'plpgsql'</div>
</div><div><br></div><div>Query returned successfully with no result in 15 ms.</div><div><br></div><div><div>Select extract_as_text(rast)</div><div>from rbike_all;</div></div><div><br></div><div><div>ERROR: column reference "rast" is ambiguous</div>
<div>LINE 1: select ST_world2rastercoordx(rast, i, j) as xcoord,</div><div> ^</div><div>DETAIL: It could refer to either a PL/pgSQL variable or a table column.</div><div>QUERY: select ST_world2rastercoordx(rast, i, j) as xcoord,</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>St_world2rastercoordy(rast, i, j) as ycoord,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ST_value(rast,1, i, j) as R,</div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span>ST_value(rast, 2, i, j) as G,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ST_value(rast, 3, i, j) as B</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>from rbike_all</div>
<div>CONTEXT: PL/pgSQL function "extract_as_text" line 9 at SQL statement</div><div><br></div><div><br></div><div>********** Error **********</div><div><br></div><div>ERROR: column reference "rast" is ambiguous</div>
<div>SQL state: 42702</div><div>Detail: It could refer to either a PL/pgSQL variable or a table column.</div><div>Context: PL/pgSQL function "extract_as_text" line 9 at SQL statement</div></div><div><br></div><div>
Removing rast from Declare above results in the same error.</div><div><br></div><div>Any pointers greatly appreciated.</div><div><br></div><div>Chris<br clear="all"><br>-- <br>He doesn't fully understand what he thinks he knows about the problem.<br>
</div>